Page MenuHomeFreeBSD

Readelf: add -z decompression support
ClosedPublic

Authored by tig_freebsdfoundation.org on Oct 22 2020, 7:04 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 19, 1:43 PM
Unknown Object (File)
Mon, Nov 18, 10:23 PM
Unknown Object (File)
Mon, Nov 18, 6:34 AM
Unknown Object (File)
Mon, Nov 18, 4:20 AM
Unknown Object (File)
Oct 5 2024, 9:50 PM
Unknown Object (File)
Oct 3 2024, 1:10 AM
Unknown Object (File)
Oct 2 2024, 7:21 AM
Unknown Object (File)
Oct 1 2024, 1:52 AM
Subscribers

Details

Summary

Add decompress section function for readelf.
Update Makefile.
Update readelf.1
Depends on this libelf patch

Test Plan

Compared results with/without -z flags.
Confirmed -h prints -z usage info.
Compared results for:

readelf -x [section] -z file
readelf -p [section] -z file

with GNU's readelf.

diff elftoolchain_output gnu_output

shows no difference.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

The readelf man page needs to be updated to mention the new option.

contrib/elftoolchain/readelf/readelf.c
6848

The brace should be on a separate line.

6952

buf needs to be freed after we're done with it, but only if it's not equal to d->d_buf.

7683

-z needs to be documented in this usage string.

tig_freebsdfoundation.org retitled this revision from Add -z to readelf to Readelf: add -z decompression support.Oct 23 2020, 5:13 PM
tig_freebsdfoundation.org marked 3 inline comments as done.
tig_freebsdfoundation.org edited the test plan for this revision. (Show Details)
tig_freebsdfoundation.org added inline comments.
contrib/elftoolchain/readelf/readelf.c
6952

Since buf pointer keeps moving I added a pointer to newly allocated decompressed buffer.
If it's not null, we set buf = new_buf and free it after a section is processed.

contrib/elftoolchain/readelf/readelf.c
6841

we can use bool and return true / false

6843–6847

FreeBSD style(9) wants doesn't use this style; should be

/*
 * Decompress a data section if needed (using ZLIB).
 * Returns 0 if sucessful, 1 otherwise.
 */
static int decompress_section(struct section *s, 
    unsigned char *compressed_data_buffer, uint64_t compressed_size, 
    unsigned char **ret_buf, uint64_t *ret_sz)
{
6851–6853

these should be indented by 1/2 tabs

6892–6894

{} are not required for single-statement bodies. They are permitted but need to be consistent throughout and they're not used elsewhere

tig_freebsdfoundation.org marked 4 inline comments as done.
tig_freebsdfoundation.org edited the summary of this revision. (Show Details)
contrib/elftoolchain/readelf/readelf.1
161

Shouldn't it be Fl z | Fl -decompress?

164

"specified by .Fl x or .Fl p"

contrib/elftoolchain/readelf/readelf.c
7043

new_buf is uninitialized if (re->options & RE_Z) == 0.

tig_freebsdfoundation.org marked 3 inline comments as done.
tig_freebsdfoundation.org added inline comments.
contrib/elftoolchain/readelf/readelf.c
7043

Fixed by setting new_buf to NULL every loop.

contrib/elftoolchain/readelf/readelf.c
6886

The indentation is wonky.

6906

Please avoid indenting goto labels.

6980

free(NULL) is fine, there's no need to check for NULL.

7045

Ditto.

This revision is now accepted and ready to land.Oct 30 2020, 8:56 PM
This revision was automatically updated to reflect the committed changes.