[llvm] cdd7f24 - [llvm-readelf] - Do not omit a zero symbol value when printing relocations.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 16 05:43:39 PDT 2020
Author: Georgii Rymar
Date: 2020-06-16T15:43:16+03:00
New Revision: cdd7f24c3aea315674fb59b3ff96fb012e739b76
URL: https://github.com/llvm/llvm-project/commit/cdd7f24c3aea315674fb59b3ff96fb012e739b76
DIFF: https://github.com/llvm/llvm-project/commit/cdd7f24c3aea315674fb59b3ff96fb012e739b76.diff
LOG: [llvm-readelf] - Do not omit a zero symbol value when printing relocations.
Previously we only printed a symbol value when it has a non-empty name
or non-zero value.
This patch changes the behavior. Now we only omit a symbols value when
a relocation does not reference a symbol (i.e. symbol index == 0).
Seems it is what GNU readelf does, looking on its output.
Differential revision: https://reviews.llvm.org/D81842
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test b/llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
index 704c2e0c4afe..062f67b80046 100644
--- a/llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
+++ b/llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
@@ -1,30 +1,33 @@
-# Show that the value field is omitted if a symbol has no name or value, but is
-# printed if one is present. Test for both static and dynamic relocation
-# printing.
+## Show that the value field is omitted when a relocation does not reference a symbol.
+## In other cases, particularly when a symbol has a zero value or when it has an empty
+## name, we print it. Test for both static and dynamic relocation printing.
# RUN: yaml2obj %s -o %t
# RUN: llvm-readelf --relocations --dyn-relocations %t | FileCheck %s
-# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 4 entries:
+# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 5 entries:
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456
-# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 678
+# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 678
+# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 2
-# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 4 entries:
+# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 5 entries:
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456
-# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 678
+# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 678
+# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 2
-# CHECK: 'RELA' relocation section at offset {{.*}} contains 96 bytes:
+# CHECK: 'RELA' relocation section at offset {{.*}} contains 120 bytes:
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 456
-# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 678
+# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 678
+# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 2
--- !ELF
FileHeader:
@@ -56,6 +59,11 @@ Sections:
Addend: 0x678
Type: R_X86_64_NONE
Symbol: 3
+## References a symbol with a zero value and an empty name.
+ - Offset: 0
+ Type: R_X86_64_NONE
+ Addend: 2
+ Symbol: 4
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [SHF_ALLOC]
@@ -65,7 +73,7 @@ Sections:
- Tag: DT_RELA
Value: 0x1100
- Tag: DT_RELASZ
- Value: 96
+ Value: 120
- Tag: DT_RELAENT
Value: 24
- Tag: DT_NULL
@@ -92,6 +100,11 @@ Sections:
Addend: 0x678
Type: R_X86_64_NONE
Symbol: 3
+## References a symbol with a zero value and an empty name.
+ - Offset: 0
+ Type: R_X86_64_NONE
+ Addend: 2
+ Symbol: 4
Symbols:
- Name: sym
Value: 0
@@ -102,6 +115,9 @@ Symbols:
Binding: STB_GLOBAL
- Type: STT_SECTION
Index: 0
+ - Value: 0x0
+ Section: .text
+ Binding: STB_GLOBAL
DynamicSymbols:
- Name: sym
Value: 0
@@ -112,6 +128,9 @@ DynamicSymbols:
Binding: STB_GLOBAL
- Type: STT_SECTION
Index: 0
+ - Value: 0x0
+ Section: .text
+ Binding: STB_GLOBAL
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 8f65b1a71029..fa4aaa02c526 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -3519,7 +3519,7 @@ void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Sym *Sym,
Obj->getRelocationTypeName(R.getType(Obj->isMips64EL()), RelocName);
Fields[2].Str = RelocName.c_str();
- if (Sym && (!SymbolName.empty() || Sym->getValue() != 0))
+ if (Sym)
Fields[3].Str = to_string(format_hex_no_prefix(Sym->getValue(), Width));
Fields[4].Str = std::string(SymbolName);
@@ -4312,7 +4312,7 @@ RelSymbol<ELFT> getSymbolForReloc(const ELFFile<ELFT> *Obj, StringRef FileName,
if (!ErrOrName)
return WarnAndReturn(Sym, toString(ErrOrName.takeError()));
- return {Sym, maybeDemangle(*ErrOrName)};
+ return {Sym == FirstSym ? nullptr : Sym, maybeDemangle(*ErrOrName)};
}
} // namespace
More information about the llvm-commits
mailing list