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)
Mon, Nov 25, 1:28 PM
Unknown Object (File)
Sun, Nov 24, 6:25 PM
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
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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

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

contrib/elftoolchain/readelf/readelf.c
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.

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
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.

contrib/elftoolchain/readelf/readelf.c
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

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

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

164 ↗(On Diff #78781)

"specified by .Fl x or .Fl p"

contrib/elftoolchain/readelf/readelf.c
7043 ↗(On Diff #78781)

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

Fixed by setting new_buf to NULL every loop.

contrib/elftoolchain/readelf/readelf.c
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)

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.