From 6fff9b53f24478610f4bc2e6a6e5b4d75f686f8a Mon Sep 17 00:00:00 2001 From: Andreas Ziegler Date: Sat, 7 Mar 2020 15:32:40 +0100 Subject: [PATCH] readelf: print addend for RELA relocations without symbol (#292) * readelf: print addend for RELA relocations without symbol When processing relocations from a SHT_RELA type section, GNU readelf displays the value of the 'r_addend' field if no symbol index is given (that is, 'r_info_sym' is 0). By also implementing this we can better test the output for 64-bit binaries which commonly use SHT_RELA relocations. The included test file is the same as tls.elf but compiled for x86_64. Its code is the following: __thread int i; int main(){} and it is compiled using the following command line: $ gcc -m64 -o tls64.elf tls.c * test: add source file for tls{,64}.elf The comments at the top describe how to compile the source file into tls.elf and tls64.elf. --- scripts/readelf.py | 4 ++++ test/testfiles_for_readelf/tls.c | 8 ++++++++ test/testfiles_for_readelf/tls64.elf | Bin 0 -> 8280 bytes 3 files changed, 12 insertions(+) create mode 100644 test/testfiles_for_readelf/tls.c create mode 100755 test/testfiles_for_readelf/tls64.elf diff --git a/scripts/readelf.py b/scripts/readelf.py index 6db36df..5c5111c 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -506,6 +506,10 @@ class ReadElf(object): rel['r_info_type'], self.elffile))) if rel['r_info_sym'] == 0: + if section.is_RELA(): + fieldsize = 8 if self.elffile.elfclass == 32 else 16 + addend = self._format_hex(rel['r_addend'], lead0x=False) + self._emit(' %s %s' % (' ' * fieldsize, addend)) self._emitline() continue diff --git a/test/testfiles_for_readelf/tls.c b/test/testfiles_for_readelf/tls.c new file mode 100644 index 0000000..781bf99 --- /dev/null +++ b/test/testfiles_for_readelf/tls.c @@ -0,0 +1,8 @@ +// Compile into tls.elf using: +// $ gcc -m32 -o tls.elf tls.c +// For tls64.elf, use: +// $ gcc -m64 -o tls64.elf tls.c + +__thread int i; + +int main(){} diff --git a/test/testfiles_for_readelf/tls64.elf b/test/testfiles_for_readelf/tls64.elf new file mode 100755 index 0000000000000000000000000000000000000000..ef775387fce1e4f7556069a715e195a9a35c16ad GI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