Skip to content

Commit 54ec9bb

Browse files
author
Georgii Rymar
committed
[llvm-readelf/obj] - Report a warning when the value of the DT_PLTREL dynamic tag is invalid.
We report an error for unknown `DT_PLTREL` values. This switches the error to warning. Differential revision: https://reviews.llvm.org/D92087
1 parent 3d4c046 commit 54ec9bb

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ ProgramHeaders:
163163
# RUN: llvm-readelf --dyn-relocations %t10a 2>&1 | \
164164
# RUN: FileCheck %s -DFILE=%t10a --check-prefix=INVALID-DT-PLTRELSZ1 --implicit-check-not=warning:
165165

166-
# INVALID-DT-PLTRELSZ1: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0xff){{$}}
166+
# INVALID-DT-PLTRELSZ1: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0xff) or PLTREL entry size (0x18){{$}}
167167

168168
--- !ELF
169169
FileHeader:

‎llvm/test/tools/llvm-readobj/ELF/dynamic-reloc.test‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,38 @@ ProgramHeaders:
128128
- Type: PT_LOAD
129129
FirstSec: .rela.dyn
130130
LastSec: .dynamic
131+
132+
## Check we report a warning when the value of the DT_PLTREL dynamic tag is invalid.
133+
## We currently accept DT_RELA(7) and DT_REL(17) values. This test case uses 0xff.
134+
135+
# RUN: yaml2obj --docnum=2 %s -DDTPLTREL=0xFF -o %t3
136+
# RUN: llvm-readobj --dyn-relocations %t3 2>&1 | \
137+
# RUN: FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-LLVM
138+
# RUN: llvm-readelf --dyn-relocations %t3 2>&1 | \
139+
# RUN: FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-GNU
140+
141+
# PLTRELUNKNOWN-LLVM: warning: '[[FILE]]': unknown DT_PLTREL value of 255
142+
# PLTRELUNKNOWN-LLVM: Dynamic Relocations {
143+
# PLTRELUNKNOWN-LLVM-NEXT: 0x1 R_X86_64_NONE foo 0x0
144+
# PLTRELUNKNOWN-LLVM-NEXT: 0x2 R_X86_64_NONE foo 0x0
145+
# PLTRELUNKNOWN-LLVM-NEXT: 0x4 R_X86_64_RELATIVE - 0x0
146+
# PLTRELUNKNOWN-LLVM-NEXT: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0)
147+
# PLTRELUNKNOWN-LLVM-NEXT: }
148+
149+
# PLTRELUNKNOWN-GNU: warning: '[[FILE]]': unknown DT_PLTREL value of 255
150+
# PLTRELUNKNOWN-GNU-EMPTY:
151+
# PLTRELUNKNOWN-GNU-NEXT: 'RELA' relocation section at offset 0x78 contains 24 bytes:
152+
# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
153+
# PLTRELUNKNOWN-GNU-NEXT: 0000000000000001 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 0
154+
# PLTRELUNKNOWN-GNU-EMPTY:
155+
# PLTRELUNKNOWN-GNU-NEXT: 'REL' relocation section at offset 0x90 contains 16 bytes:
156+
# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
157+
# PLTRELUNKNOWN-GNU-NEXT: 0000000000000002 0000000100000000 R_X86_64_NONE 0000000000000000 foo
158+
# PLTRELUNKNOWN-GNU-EMPTY:
159+
# PLTRELUNKNOWN-GNU-NEXT: 'RELR' relocation section at offset 0xa0 contains 8 bytes:
160+
# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
161+
# PLTRELUNKNOWN-GNU-NEXT: 0000000000000004 0000000000000008 R_X86_64_RELATIVE
162+
# PLTRELUNKNOWN-GNU-EMPTY:
163+
# PLTRELUNKNOWN-GNU-NEXT: 'PLT' relocation section at offset 0xa8 contains 16 bytes:
164+
# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
165+
# PLTRELUNKNOWN-GNU-NEXT: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0)

‎llvm/tools/llvm-readobj/ELFDumper.cpp‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,10 +2204,9 @@ void ELFDumper<ELFT>::parseDynamicTable() {
22042204
else if (Dyn.getVal() == DT_RELA)
22052205
DynPLTRelRegion.EntSize = sizeof(Elf_Rela);
22062206
else
2207-
reportError(createError(Twine("unknown DT_PLTREL value of ") +
2208-
Twine((uint64_t)Dyn.getVal())),
2209-
ObjF.getFileName());
2210-
DynPLTRelRegion.EntSizePrintName = "";
2207+
reportUniqueWarning(createError(Twine("unknown DT_PLTREL value of ") +
2208+
Twine((uint64_t)Dyn.getVal())));
2209+
DynPLTRelRegion.EntSizePrintName = "PLTREL entry size";
22112210
break;
22122211
case ELF::DT_JMPREL:
22132212
DynPLTRelRegion.Addr = toMappedAddr(Dyn.getTag(), Dyn.getPtr());

0 commit comments

Comments
 (0)