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::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name, ELFYAML::RawContentSection *RawSec = dyn_cast_or_null(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=]] + Offset: [[STRTABOFFSET=]] - Name: .shstrtab Type: SHT_STRTAB Flags: [[SHSTRTABFLAGS=]] + Offset: [[SHSTRTABOFFSET=]] - Name: .dynstr Type: SHT_STRTAB Flags: [[DYNSTRFLAGS=]] + Offset: [[DYNSTROFFSET=]] -## 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.