[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.

Colin LeMahieu via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 22 08:36:56 PDT 2016


Thanks for the prompt reply and test case, I'll make sure this is considered.

Admittedly I know less about the ELF spec than you do; I appreciate the patience while I try to contribute a fix for the incorrect logic in llvm-objdump and the ELFObjectFile.h that assumes relocations don't exist in executable or shared object files.

If you have suggestions that could prevent future issues I appreciate the feedback.

-----Original Message-----
From: Rafael EspĂ­ndola [mailto:rafael.espindola at gmail.com] 
Sent: Monday, March 21, 2016 4:04 PM
To: Colin LeMahieu <colinl at codeaurora.org>
Cc: llvm-commits <llvm-commits at lists.llvm.org>
Subject: Re: [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.

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