[llvm] 5ffafa8 - [yaml2obj] - Add support of Offset for .strtab/.shstrtab/.dynstr sections.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 01:03:49 PST 2020


Author: Georgii Rymar
Date: 2020-11-02T11:56:32+03:00
New Revision: 5ffafa870c50b3c94ad87039d5d879e200d2d68d

URL: https://github.com/llvm/llvm-project/commit/5ffafa870c50b3c94ad87039d5d879e200d2d68d
DIFF: https://github.com/llvm/llvm-project/commit/5ffafa870c50b3c94ad87039d5d879e200d2d68d.diff

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

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

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 124af979de8f..6b4343ef90b5 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -930,7 +930,8 @@ void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
   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);

diff  --git a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml b/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml
index b9fd494cefb5..f37529d05d37 100644
--- a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml
@@ -23,25 +23,29 @@ Sections:
   - 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.


        


More information about the llvm-commits mailing list