[PATCH] D58168: [yaml2obj] - Do not ignore explicit addresses for .dynsym and .dynstr

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 19 04:14:44 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL354318: [yaml2obj] - Do not ignore explicit addresses for .dynsym and .dynstr (authored by grimar, committed by ).
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D58168?vs=187251&id=187345#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58168/new/

https://reviews.llvm.org/D58168

Files:
  llvm/trunk/test/tools/yaml2obj/dynsym-dynstr-addr.yaml
  llvm/trunk/tools/yaml2obj/yaml2elf.cpp


Index: llvm/trunk/test/tools/yaml2obj/dynsym-dynstr-addr.yaml
===================================================================
--- llvm/trunk/test/tools/yaml2obj/dynsym-dynstr-addr.yaml
+++ llvm/trunk/test/tools/yaml2obj/dynsym-dynstr-addr.yaml
@@ -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: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
===================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp
@@ -321,6 +321,15 @@
   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 @@
   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>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58168.187345.patch
Type: text/x-patch
Size: 2510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190219/bffbb6cb/attachment.bin>


More information about the llvm-commits mailing list