summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-06-10 11:38:06 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-06-10 11:38:06 +0000
commit379aa18a39584e6956e9ebd9d574310eb4c731ba (patch)
tree3b91a24a856d572d5b7f62219fb26251f5521212 /llvm
parentd847aa573b655fe71aad323c7f579c6302c702aa (diff)
downloadbcm5719-llvm-379aa18a39584e6956e9ebd9d574310eb4c731ba.tar.gz
bcm5719-llvm-379aa18a39584e6956e9ebd9d574310eb4c731ba.zip
[yaml2obj] - Do not assert when .dynsym is specified explicitly, but .dynstr is not present.
We have a code in buildSectionIndex() that adds implicit sections: // Add special sections after input sections, if necessary. for (StringRef Name : implicitSectionNames()) if (SN2I.addName(Name, SecNo)) { // Account for this section, since it wasn't in the Doc ++SecNo; DotShStrtab.add(Name); } The problem arises when .dynsym is specified explicitly and no DynamicSymbols is used. In that case, we do not add .dynstr implicitly and will assert later when will try to set Link for .dynsym. Seems, in this case, reasonable behavior is to allow Link field to be zero. This is what this patch does. Differential revision: https://reviews.llvm.org/D63001 llvm-svn: 362929
Diffstat (limited to 'llvm')
-rw-r--r--llvm/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml22
-rw-r--r--llvm/tools/yaml2obj/yaml2elf.cpp13
2 files changed, 34 insertions, 1 deletions
diff --git a/llvm/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml b/llvm/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml
new file mode 100644
index 00000000000..16c4a6a2d28
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml
@@ -0,0 +1,22 @@
+## Check we do not crash/assert when .dynsym is specified
+## explicitly, but .dynstr is not present.
+
+# RUN: yaml2obj %s -o %t
+# RUN: not llvm-readelf --section-headers %t 2>&1 | FileCheck %s
+
+## TODO: Check that .dynsym has Link field set to 0.
+## GNU readelf is able to dump sections headers,
+## but llvm-readelf reports an error below too early.
+## See https://bugs.llvm.org/show_bug.cgi?id=42215.
+
+# CHECK: error: invalid sh_type for string table, expected SHT_STRTAB
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_SYMTAB
diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp
index be484783534..8a53a1b2f48 100644
--- a/llvm/tools/yaml2obj/yaml2elf.cpp
+++ b/llvm/tools/yaml2obj/yaml2elf.cpp
@@ -367,7 +367,18 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
bool IsStatic = STType == SymtabType::Static;
SHeader.sh_name = DotShStrtab.getOffset(IsStatic ? ".symtab" : ".dynsym");
SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM;
- SHeader.sh_link = IsStatic ? SN2I.get(".strtab") : SN2I.get(".dynstr");
+
+ // When we describe the .dynsym section in the document explicitly, it is
+ // allowed to omit the "DynamicSymbols" tag. In this case .dynstr is not added
+ // implicitly and we should be able to leave the Link zeroed if .dynstr is not
+ // defined.
+ unsigned Link = 0;
+ if (IsStatic)
+ Link = SN2I.get(".strtab");
+ else
+ SN2I.lookup(".dynstr", Link);
+ SHeader.sh_link = Link;
+
if (!IsStatic)
SHeader.sh_flags |= ELF::SHF_ALLOC;
OpenPOWER on IntegriCloud