summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-05 13:54:35 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-05 13:54:35 +0000
commit149aa2f7fc6214e7f340da9011a857d75fe5a652 (patch)
tree7e3dcaaa6d7966116270717db5de95a699a67c07
parent2a4817637350661b9002c10ff830241697e0f639 (diff)
downloadbcm5719-llvm-149aa2f7fc6214e7f340da9011a857d75fe5a652.tar.gz
bcm5719-llvm-149aa2f7fc6214e7f340da9011a857d75fe5a652.zip
[yaml2obj] - Allow overriding sh_entsize for SHT_GNU_versym sections.
This allows to write a test case for one of untested errors in llvm/Object/ELF.h. I did it in this patch to demonstrate. Differential revision: https://reviews.llvm.org/D65394 llvm-svn: 367860
-rw-r--r--llvm/include/llvm/Object/ELF.h5
-rw-r--r--llvm/test/Object/invalid.test25
-rw-r--r--llvm/test/tools/yaml2obj/versym-section.yaml28
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp2
4 files changed, 54 insertions, 6 deletions
diff --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index aa0864edb78..6febbc7c8de 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -547,8 +547,9 @@ template <typename T>
Expected<const T *> ELFFile<ELFT>::getEntry(const Elf_Shdr *Section,
uint32_t Entry) const {
if (sizeof(T) != Section->sh_entsize)
- // TODO: this error is untested.
- return createError("invalid sh_entsize");
+ return createError("section " + getSecIndexForError(this, Section) +
+ " has invalid sh_entsize: expected " + Twine(sizeof(T)) +
+ ", but got " + Twine(Section->sh_entsize));
size_t Pos = Section->sh_offset + Entry * sizeof(T);
if (Pos + sizeof(T) > Buf.size())
return createError("unable to access section " +
diff --git a/llvm/test/Object/invalid.test b/llvm/test/Object/invalid.test
index 7071dee98eb..04a332d5fa4 100644
--- a/llvm/test/Object/invalid.test
+++ b/llvm/test/Object/invalid.test
@@ -627,3 +627,28 @@ Sections:
Content: ""
Symbols:
- Name: foo
+
+## Check that we report an error if SHT_GNU_versym has invalid
+## sh_entsize value (3 instead of 2) when trying to access the entries.
+
+# RUN: yaml2obj %s --docnum=30 -o %t30
+# RUN: not llvm-readobj -V %t30 2>&1 | FileCheck --check-prefix=INVALID-VER-SHENTSIZE %s
+
+# INVALID-VER-SHENTSIZE: error: section [index 1] has invalid sh_entsize: expected 2, but got 3
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_FREEBSD
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ EntSize: 0x0000000000000003
+ Entries: [ ]
+## Needed to trigger creation of .dynsym.
+DynamicSymbols:
+ - Name: foo
+ Binding: STB_GLOBAL
diff --git a/llvm/test/tools/yaml2obj/versym-section.yaml b/llvm/test/tools/yaml2obj/versym-section.yaml
index fa28ae569b6..6e0cecba19e 100644
--- a/llvm/test/tools/yaml2obj/versym-section.yaml
+++ b/llvm/test/tools/yaml2obj/versym-section.yaml
@@ -1,9 +1,9 @@
-# RUN: yaml2obj %s -o %t
-# RUN: llvm-readobj -V %t | FileCheck %s
-
## Check we are able to produce a valid SHT_GNU_versym
## section from its description.
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj -V %t1 | FileCheck %s
+
# CHECK: Version symbols {
# CHECK-NEXT: Section Name: .gnu.version
# CHECK-NEXT: Address: 0x200210
@@ -89,3 +89,25 @@ DynamicSymbols:
- Name: f2
Binding: STB_GLOBAL
...
+
+## Check we are able to set custom sh_entsize field for SHT_GNU_versym section.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readelf -S %t2 | FileCheck %s --check-prefix=ENTSIZE
+
+# ENTSIZE: Section Headers:
+# ENTSIZE: [Nr] Name Type Address Off Size ES
+# ENTSIZE: [ 1] .gnu.version VERSYM 0000000000000000 000180 000000 03
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_FREEBSD
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ EntSize: 0x0000000000000003
+ Entries: [ ]
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index e11d8fe3ff0..bcb390bb5e1 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -796,7 +796,7 @@ bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
for (uint16_t Version : Section.Entries)
support::endian::write<uint16_t>(OS, Version, ELFT::TargetEndianness);
- SHeader.sh_entsize = 2;
+ SHeader.sh_entsize = Section.EntSize ? (uint64_t)*Section.EntSize : 2;
SHeader.sh_size = Section.Entries.size() * SHeader.sh_entsize;
return true;
}
OpenPOWER on IntegriCloud