[PATCH] D63280: [llvm-objdump] Use <first-symbol>-<offset> as the section start symbol
Jim Wilson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 17:42:29 PDT 2019
jimw added a comment.
This one had me confused for a while, but after a bit of experimenting I figured out that the problem is strip.
hifiveu017:1075$ cat tmp.c
extern int sub2 (void);
int sub (void) { return sub2 (); }
hifiveu017:1076$ gcc --shared -fpic -O -o tmp.so tmp.c
hifiveu017:1077$ objdump -d tmp.so | head
tmp.so: file format elf64-littleriscv
Disassembly of section .plt:
00000000000003d0 <.plt>:
3d0: 00002397 auipc t2,0x2
3d4: 41c30333 sub t1,t1,t3
3d8: c303be03 ld t3,-976(t2) # 2000 <__TMC_END__>
hifiveu017:1078$ strip tmp.so
hifiveu017:1079$ objdump -d tmp.so | head
tmp.so: file format elf64-littleriscv
Disassembly of section .plt:
00000000000003d0 <sub2 at plt-0x20>:
3d0: 00002397 auipc t2,0x2
3d4: 41c30333 sub t1,t1,t3
3d8: c303be03 ld t3,-976(t2) # 2000 <sub@@Base+0x1b6e>
hifiveu017:1080$
MaskRay is looking at system libraries which have all been stripped. I've been looking at libraries built as part of the toolchain build, which are not stripped. The difference between the stripped and unstripped file is that the unstripped file has a section symbol for each section. Readelf --syms shows it as
9: 00000000000003d0 0 SECTION LOCAL DEFAULT 9
and nm shows it as
00000000000003d0 l d .plt 0000000000000000 .plt
The stripped file doesn't have the section symbols.
Objdump always uses the nearest symbol, so if you have the section symbols, then the output starts with that symbol name. This was mentioned near the top, when discussing
Disassembly of section .text:
0000000000001000 .text:
The first .text is the section, the second one is the section symbol. And that section symbol disappears when you strip the file, if it isn't needed by something else like a dynamic reloc.
So the issue here is that the objdump output is a little confusing when run on stripped files. I don't think that is a bug. If you want good objdump output, don't strip the files.
There is a secondary issue that the first plt in the plt section does not have a symbol of its own, and certainly not one that will survive strip, but I don't think that is a bug either.
Perhaps objdump could be extended to create synthetic section symbols if they don't exist, to get better output for stripped files, but that would be an enhancement not a bug fix.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63280/new/
https://reviews.llvm.org/D63280
More information about the llvm-commits
mailing list