Page MenuHomeFreeBSD

Readelf: add -z decompression support
ClosedPublic

Authored by tig_freebsdfoundation.org on Oct 22 2020, 7:04 PM.
Tags
None
Referenced Files
F81594855: D26909.id78613.diff
Thu, Apr 18, 4:40 PM
Unknown Object (File)
Sat, Apr 6, 11:19 AM
Unknown Object (File)
Sat, Apr 6, 6:22 AM
Unknown Object (File)
Sat, Apr 6, 12:43 AM
Unknown Object (File)
Sat, Apr 6, 12:43 AM
Unknown Object (File)
Sat, Apr 6, 12:43 AM
Unknown Object (File)
Sat, Apr 6, 12:43 AM
Unknown Object (File)
Fri, Mar 29, 4: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.

6953

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
6953

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
7044

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
7044

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.

6981

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

7046

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.