[llvm] 7ab1481 - [llvm-readelf/llvm-readobj] - Check version of SHT_GNU_verdef section entries when dumping.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 29 00:10:30 PST 2019
Author: Georgii Rymar
Date: 2019-11-29T11:09:56+03:00
New Revision: 7ab14813619189d13382da047409a81c94ebc58d
URL: https://github.com/llvm/llvm-project/commit/7ab14813619189d13382da047409a81c94ebc58d
DIFF: https://github.com/llvm/llvm-project/commit/7ab14813619189d13382da047409a81c94ebc58d.diff
LOG: [llvm-readelf/llvm-readobj] - Check version of SHT_GNU_verdef section entries when dumping.
Elfxx_Verdef contains the following field:
vd_version
Version revision. This field shall be set to 1.
(https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/symversion.html)
Our code should check the struct version for correctness. This patch does that.
(This will help to simplify or eliminate ELFDumper<ELFT>::LoadVersionDefs() which
has it's own logic to parse version definitions for no reason. It checks the
struct version currently).
Differential revision: https://reviews.llvm.org/D70810
Added:
Modified:
llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test b/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
index 3a4de3698385..44be4f2fdac4 100644
--- a/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
+++ b/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
@@ -91,7 +91,7 @@ Sections:
Link: .dynstr
Info: 0x1
Entries:
- - Version: 0
+ - Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
@@ -122,7 +122,7 @@ Sections:
Link: .dynstr
Info: 0x1
Entries:
- - Version: 0
+ - Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
@@ -141,7 +141,7 @@ DynamicSymbols:
# PAST-STRTAB-END-LLVM: VersionDefinitions [
# PAST-STRTAB-END-LLVM-NEXT: Definition {
-# PAST-STRTAB-END-LLVM-NEXT: Version: 0
+# PAST-STRTAB-END-LLVM-NEXT: Version: 1
# PAST-STRTAB-END-LLVM-NEXT: Flags [ (0x0)
# PAST-STRTAB-END-LLVM-NEXT: ]
# PAST-STRTAB-END-LLVM-NEXT: Index: 0
@@ -153,7 +153,7 @@ DynamicSymbols:
# PAST-STRTAB-END-GNU: Version definition section '.gnu.version_d' contains 1 entries:
# PAST-STRTAB-END-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.strtab)
-# PAST-STRTAB-END-GNU-NEXT: 0x0000: Rev: 0 Flags: none Index: 0 Cnt: 1 Name: <invalid vda_name: 5>
+# PAST-STRTAB-END-GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 0 Cnt: 1 Name: <invalid vda_name: 5>
--- !ELF
FileHeader:
@@ -167,7 +167,7 @@ Sections:
Link: .strtab
Info: 0x1
Entries:
- - Version: 0
+ - Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
@@ -200,7 +200,7 @@ Sections:
Link: .dynstr
Info: 0x1
Entries:
- - Version: 0
+ - Version: 1
Flags: 0
VersionNdx: 0
Hash: 0
@@ -230,7 +230,35 @@ Sections:
Link: .dynstr
Info: 0x1
## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory.
- Content: "0000000000000100000000001300000000000000"
+ Content: "0100000000000100000000001300000000000000"
DynamicSymbols:
- Name: foo
Binding: STB_GLOBAL
+
+## Check how we handle the case when a version definition entry has an unsupported version.
+
+# RUN: yaml2obj %s --docnum=9 -o %t9
+# RUN: llvm-readobj -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9
+# RUN: llvm-readelf -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9
+
+# UNSUPPORTED-VERSION: warning: '[[FILE]]': unable to dump SHT_GNU_verdef section with index 1: version 65278 is not yet supported
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: .dynstr
+ Info: 0x1
+ Entries:
+ - Version: 0xfefe
+ Flags: 0
+ VersionNdx: 0
+ Hash: 0
+ Names: []
+DynamicSymbols:
+ - Name: foo
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 79d08d379a1a..51ea599f4be7 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -409,6 +409,12 @@ ELFDumper<ELFT>::getVersionDefinitions(const Elf_Shdr *Sec) const {
": found a misaligned version definition entry at offset 0x" +
Twine::utohexstr(VerdefBuf - Start));
+ unsigned Version = *reinterpret_cast<const Elf_Half *>(VerdefBuf);
+ if (Version != 1)
+ return createError("unable to dump SHT_GNU_verdef section with index " +
+ Twine(SecNdx) + ": version " + Twine(Version) +
+ " is not yet supported");
+
const Elf_Verdef *D = reinterpret_cast<const Elf_Verdef *>(VerdefBuf);
VerDef &VD = *Ret.emplace(Ret.end());
VD.Offset = VerdefBuf - Start;
More information about the llvm-commits
mailing list