[PATCH] D90446: [yaml2obj] - Add support of Offset for .strtab/.shstrtab/.dynstr sections.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 30 01:03:59 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
grimar requested review of this revision.

These sections are implicit and handled a bit differently.
Currently the "Offset" is ignored for them.
This patch fixes an issue.


https://reviews.llvm.org/D90446

Files:
  llvm/lib/ObjectYAML/ELFEmitter.cpp
  llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml


Index: llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml
===================================================================
--- llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml
+++ llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml
@@ -23,25 +23,29 @@
   - Name: .strtab
     Type: SHT_STRTAB
     Flags: [[STRTABFLAGS=<none>]]
+    Offset: [[STRTABOFFSET=<none>]]
   - Name: .shstrtab
     Type: SHT_STRTAB
     Flags: [[SHSTRTABFLAGS=<none>]]
+    Offset: [[SHSTRTABOFFSET=<none>]]
   - Name: .dynstr
     Type: SHT_STRTAB
     Flags: [[DYNSTRFLAGS=<none>]]
+    Offset: [[DYNSTROFFSET=<none>]]
 
-## Check we can set arbitrary flags for .strtab/.dynstr.
+## Check we can set arbitrary flags and offsets for
+## implicit string table sections.
 
 # RUN: yaml2obj --docnum=1 \
-# RUN:   -DSTRTABFLAGS="[ SHF_ALLOC, SHF_STRINGS ]" \
-# RUN:     -DSHSTRTABFLAGS="[ SHF_ALLOC, SHF_WRITE ]" \
-# RUN:       -DDYNSTRFLAGS="[ SHF_STRINGS ]" %s -o %t2
+# RUN:   -DSTRTABFLAGS="[ SHF_ALLOC, SHF_STRINGS ]" -DSTRTABOFFSET=0x100 \
+# RUN:     -DSHSTRTABFLAGS="[ SHF_ALLOC, SHF_WRITE ]" -DSHSTRTABOFFSET=0x200 \
+# RUN:       -DDYNSTRFLAGS="[ SHF_STRINGS ]" -DDYNSTROFFSET=0x300 %s -o %t2
 # RUN: llvm-readelf %t2 --sections | FileCheck %s --check-prefix=CASE2
 
-#      CASE2: [Nr] Name      Type   {{.*}} Flg Lk
-#      CASE2: [ 1] .strtab   STRTAB {{.*}}  AS 0 
-# CASE2-NEXT: [ 2] .shstrtab STRTAB {{.*}}  WA 0 
-# CASE2-NEXT: [ 3] .dynstr   STRTAB {{.*}}   S 0 
+#      CASE2: [Nr] Name      Type   Address          Off    {{.*}} Flg Lk
+#      CASE2: [ 1] .strtab   STRTAB 0000000000000000 000100 {{.*}}  AS 0 
+# CASE2-NEXT: [ 2] .shstrtab STRTAB 0000000000000001 000200 {{.*}}  WA 0 
+# CASE2-NEXT: [ 3] .dynstr   STRTAB 0000000000000000 000300 {{.*}}   S 0 
 
 ## Check no flags are set by default for implicit string table sections
 ## when they are not described in the YAML.
Index: llvm/lib/ObjectYAML/ELFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -930,7 +930,8 @@
   ELFYAML::RawContentSection *RawSec =
       dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
 
-  SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, /*Offset=*/None);
+  SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign,
+                                    YAMLSec ? YAMLSec->Offset : None);
 
   if (RawSec && (RawSec->Content || RawSec->Size)) {
     SHeader.sh_size = writeContent(CBA, RawSec->Content, RawSec->Size);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90446.301830.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201030/bff2444e/attachment.bin>


More information about the llvm-commits mailing list