Page MenuHomeFreeBSD

Readelf: add -z decompression support
ClosedPublic

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

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
Unit Tests Skipped

Event Timeline

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

contrib/elftoolchain/readelf/readelf.c
6914

The brace should be on a separate line.

7019

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

7746

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

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
160

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

163

"specified by .Fl x or .Fl p"

contrib/elftoolchain/readelf/readelf.c
7108

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
7108

Fixed by setting new_buf to NULL every loop.

contrib/elftoolchain/readelf/readelf.c
6952

The indentation is wonky.

6972

Please avoid indenting goto labels.

7047

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

7110

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.