Page MenuHomeFreeBSD

Readelf: add -z decompression support

Authored by on Oct 22 2020, 7:04 PM.



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

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

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

6847 ↗(On Diff #78613)

The brace should be on a separate line.

6953 ↗(On Diff #78613)

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

7673 ↗(On Diff #78613)

-z needs to be documented in this usage string. retitled this revision from Add -z to readelf to Readelf: add -z decompression support.Oct 23 2020, 5:13 PM marked 3 inline comments as done. edited the test plan for this revision. (Show Details) added inline comments.
6953 ↗(On Diff #78613)

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.

6841 ↗(On Diff #78654)

we can use bool and return true / false

6843–6847 ↗(On Diff #78654)

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 ↗(On Diff #78654)

these should be indented by 1/2 tabs

6892–6894 ↗(On Diff #78654)

{} are not required for single-statement bodies. They are permitted but need to be consistent throughout and they're not used elsewhere marked 4 inline comments as done. edited the summary of this revision. (Show Details)
161 ↗(On Diff #78781)

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

164 ↗(On Diff #78781)

"specified by .Fl x or .Fl p"

7043 ↗(On Diff #78781)

new_buf is uninitialized if (re->options & RE_Z) == 0. marked 3 inline comments as done. added inline comments.
7043 ↗(On Diff #78781)

Fixed by setting new_buf to NULL every loop.

6886 ↗(On Diff #78816)

The indentation is wonky.

6906 ↗(On Diff #78816)

Please avoid indenting goto labels.

6981 ↗(On Diff #78816)

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

7046 ↗(On Diff #78816)


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.