[llvm] r263971 - [llvm-objdump] Printing relocations in executable and shared object files. This partially reverts r215844 by removing test objdump-reloc-shared.test which stated GNU objdump doesn't print relocations, it does.
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 21 14:04:17 PDT 2016
> +uint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const {
> + const Elf_Shdr *sec = getRelSection(Rel);
> + uint64_t Offset = sec->sh_type == ELF::SHT_REL ?
> + getRel(Rel)->r_offset :
> + getRela(Rel)->r_offset;
> + if (EF.getHeader()->e_type == ELF::ET_EXEC ||
> + EF.getHeader()->e_type == ELF::ET_DYN) {
> + // For an executable file or a shared object, the value is the virtual
> + // address of the storage unit affected by the relocation.
> + auto SectionIter = getRelocatedSection(toDRI(sec));
> + if (SectionIter != section_end())
> + Offset -= SectionIter->getAddress();
This is completely wrong. You simply return the wrong value if the
section has no associated relocated section.
For example:
-----------------------------------------------------
$ cat test.c
__attribute__((visibility("hidden"))) int a = 42;
int *b = &a;
$ clang -c test.c
$ ld test.o -o test.so -shared
$ objdump -r test.so
test.so: file format elf64-x86-64
$ ./build/bin/llvm-objdump -r test.so
test.so: file format ELF64-x86-64
RELOCATION RECORDS FOR [.rela.dyn]:
./build/bin/llvm-objdump: error reading file: Invalid data was
encountered while parsing the file.
-------------------------------------------------------
Reverting and adding the above test.
Cheers,
Rafael
More information about the llvm-commits
mailing list