]> granicus.if.org Git - llvm/commitdiff
[yaml2obj] - Do not ignore explicit addresses for .dynsym and .dynstr
authorGeorge Rimar <grimar@accesssoftek.com>
Tue, 19 Feb 2019 12:15:04 +0000 (12:15 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Tue, 19 Feb 2019 12:15:04 +0000 (12:15 +0000)
This fixes https://bugs.llvm.org/show_bug.cgi?id=40339

Previously if the addresses were set in YAML they were ignored for
.dynsym and .dynstr sections. The patch fixes that.

Differential revision: https://reviews.llvm.org/D58168

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354318 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/yaml2obj/dynsym-dynstr-addr.yaml [new file with mode: 0644]
tools/yaml2obj/yaml2elf.cpp

diff --git a/test/tools/yaml2obj/dynsym-dynstr-addr.yaml b/test/tools/yaml2obj/dynsym-dynstr-addr.yaml
new file mode 100644 (file)
index 0000000..c54787c
--- /dev/null
@@ -0,0 +1,40 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj -sections %t | FileCheck %s
+
+## Check yaml2obj does not ignore the address of the
+## explicitly listed .dynstr and .dynsym sections.
+
+# CHECK:      Name: .dynstr
+# CHECK-NEXT:   Type: SHT_STRTAB
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x1000
+
+# CHECK:      Name: .dynsym
+# CHECK-NEXT:   Type: SHT_DYNSYM
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:     SHF_ALLOC
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x2000
+
+!ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_DYN
+  Machine:         EM_X86_64
+Sections:
+  - Name:         .dynstr
+    Type:         SHT_STRTAB
+    Flags:        [ SHF_ALLOC ]
+    Address:      0x1000
+    EntSize:      0x1
+  - Name:         .dynsym
+    Type:         SHT_DYNSYM
+    Flags:        [ SHF_ALLOC ]
+    Address:      0x2000
+    EntSize:      0x18
+DynamicSymbols:
+  Global:
+    - Name: foo
index 5198a751cfbd4df54642661c17814606d14c924c..ac1626aa1a3e42c8f90103eb6b154f1ea74fed4d 100644 (file)
@@ -321,6 +321,15 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
   SHeader.sh_entsize = sizeof(Elf_Sym);
   SHeader.sh_addralign = 8;
 
+  // If .dynsym section is explicitly described in the YAML
+  // then we want to use its section address.
+  if (!IsStatic) {
+    // Take section index and ignore the SHT_NULL section.
+    unsigned SecNdx = getDotDynSymSecNo() - 1;
+    if (SecNdx < Doc.Sections.size())
+      SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
+  }
+
   std::vector<Elf_Sym> Syms;
   {
     // Ensure STN_UNDEF is present
@@ -358,6 +367,15 @@ void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
   STB.write(CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign));
   SHeader.sh_size = STB.getSize();
   SHeader.sh_addralign = 1;
+
+  // If .dynstr section is explicitly described in the YAML
+  // then we want to use its section address.
+  if (Name == ".dynstr") {
+    // Take section index and ignore the SHT_NULL section.
+    unsigned SecNdx = getDotDynStrSecNo() - 1;
+    if (SecNdx < Doc.Sections.size())
+      SHeader.sh_addr = Doc.Sections[SecNdx]->Address;
+  }
 }
 
 template <class ELFT>