This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] - Dump the archive headers when -all-headers is specified
ClosedPublic

Authored by grimar on Jan 16 2019, 5:49 AM.

Details

Summary

When -all-headers is given it is supposed to dump all headers,
but now it skips the archive headers for no reason.

The patch fixes that.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Jan 16 2019, 5:49 AM

The code change looks good to me, but I'd like a bit more testing, if it's okay. I assume that the output is something like the following for each archive member in turn:

member1.o:
<archive header>
<file header>
<section headers>
...
member2.o:
<archive header>
...

but I don't see anything showing that we're printing things that way (instead of printing all archive headers, then all file headers etc): we should have a test for that.

The code change looks good to me, but I'd like a bit more testing, if it's okay. I assume that the output is something like the following for each archive member in turn:

member1.o:
<archive header>
<file header>
<section headers>
...
member2.o:
<archive header>
...

but I don't see anything showing that we're printing things that way (instead of printing all archive headers, then all file headers etc): we should have a test for that.

Sounds reasonable. I'll re-check the behavior tomorrow and add a test.

grimar updated this revision to Diff 182258.Jan 17 2019, 5:48 AM

I added a requested test showing how -all-headers now dumps the archive headers.
(and removed the old test since the new one covers the added functionality).

There is a little difference in the order between llvm-objump and GNU objdump.

The latter prints them before the architecture:

In archive all-headers.test.tmp.a:

all-headers.test.tmp: file format elf64-x86-64
rw-r--r-- 0/0 372 Jan 1 03:00 1970 all-headers.test.tmp
architecture: i386:x86-64, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x0000000000000000

I am not sure how much it is important to change
(given that we are not 1:1 equal in output),
but it is not what this patch tries to fix anyways and we can do that separately.

jhenderson accepted this revision.Jan 17 2019, 6:04 AM

LGTM with one nit. I think it would make more sense for the archive header to appear before the file header (the archive header is conceptually before the file header in the archive, and isn't really part of the ELF file itself), but like you said, that is a different change.

test/tools/llvm-objdump/all-headers.test
15 ↗(On Diff #182258)

in archive -> in the archive

17 ↗(On Diff #182258)

Not that it really matters, but I wonder if it would be better to simply copy %t?

This revision is now accepted and ready to land.Jan 17 2019, 6:04 AM
grimar marked an inline comment as done.Jan 17 2019, 6:11 AM
grimar added inline comments.
test/tools/llvm-objdump/all-headers.test
17 ↗(On Diff #182258)

I have no preference. Actually, we can even use the existent file twice, what do you think?
(it works, I just tested).

grimar marked an inline comment as done.Jan 17 2019, 6:20 AM
grimar added inline comments.
test/tools/llvm-objdump/all-headers.test
17 ↗(On Diff #182258)

i.e. with
llvm-ar rcs t.a t1.o t1.o
llvm-objdump t.a --all-headers

It then dumps them both as expected:

t.a(t1.o):	file format ELF64-x86-64

...

t.a(t1.o):	file format ELF64-x86-64

....

The name is the same, but since we want to test the headers order, that should be fine I think.

jhenderson added inline comments.Jan 17 2019, 6:40 AM
test/tools/llvm-objdump/all-headers.test
17 ↗(On Diff #182258)

I'm surprised that that actually works! I'd expect the second "t1.o" to replace the first one. However, I think it would be good to have two differently named members anyway - I've seen bugs in tools where they only use one member's names for everything!

Copying would probably be a bit faster ;-)

grimar marked an inline comment as done.Jan 17 2019, 6:43 AM
grimar added inline comments.
test/tools/llvm-objdump/all-headers.test
17 ↗(On Diff #182258)

Ok :)

This revision was automatically updated to reflect the committed changes.
grimar marked 3 inline comments as done.