[PATCH] D81840: [llvm-readelf] - Do not crash when relocation references a STT_SECTION symbol for the null section.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 15 05:24:35 PDT 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Currently, llvm-readelf crashes when there is a STT_SECTION symbol for the null section
and this symbol is used in a relocation.
This patch fixes the issue.
https://reviews.llvm.org/D81840
Files:
llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1082,6 +1082,9 @@
Obj->getSection(Sym, SymTab, ShndxTable);
if (!SecOrErr)
return SecOrErr.takeError();
+ // A section symbol describes the section at index 0.
+ if (*SecOrErr == nullptr)
+ return std::make_pair(Sym, "");
Expected<StringRef> NameOrErr = Obj->getSectionName(*SecOrErr);
if (!NameOrErr)
Index: llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
+++ llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
@@ -5,23 +5,26 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readelf --relocations --dyn-relocations %t | FileCheck %s
-# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 3 entries:
+# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 4 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: Relocation section '.rela.dyn' at offset {{.*}} contains 3 entries:
+# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 4 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: 'RELA' relocation section at offset {{.*}} contains 72 bytes:
+# CHECK: 'RELA' relocation section at offset {{.*}} contains 96 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
--- !ELF
FileHeader:
@@ -49,6 +52,10 @@
Type: R_X86_64_NONE
Addend: 0x456
Symbol: 2
+ - Offset: 0
+ Addend: 0x678
+ Type: R_X86_64_NONE
+ Symbol: 3
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [SHF_ALLOC]
@@ -58,7 +65,7 @@
- Tag: DT_RELA
Value: 0x1100
- Tag: DT_RELASZ
- Value: 72
+ Value: 96
- Tag: DT_RELAENT
Value: 24
- Tag: DT_NULL
@@ -81,6 +88,10 @@
Type: R_X86_64_NONE
Addend: 0x456
Symbol: 2
+ - Offset: 0
+ Addend: 0x678
+ Type: R_X86_64_NONE
+ Symbol: 3
Symbols:
- Name: sym
Value: 0
@@ -89,6 +100,8 @@
- Value: 0x123
Section: .text
Binding: STB_GLOBAL
+ - Type: STT_SECTION
+ Index: 0
DynamicSymbols:
- Name: sym
Value: 0
@@ -97,6 +110,8 @@
- Value: 0x123
Section: .text
Binding: STB_GLOBAL
+ - Type: STT_SECTION
+ Index: 0
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81840.270724.patch
Type: text/x-patch
Size: 3942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200615/6edd3968/attachment.bin>
More information about the llvm-commits
mailing list