From edfb2f8b235ff72f00375ae2424f7eb98da08234 Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Tue, 27 Oct 2020 14:38:02 +0300 Subject: [PATCH] [yaml2obj] - Support the "Offset" key for the .dynsym section. Our "implicit" sections are handled separately from regular ones. It turns out that the "Offset" key is not handled properly for them. Perhaps we can generalize handling in one place, but before doing that I'd like to add support and test cases for each implicit section. (I need this particular single change to unblock another patch that is already on review, and I guess doing it independently for each section will be cleaner, see below). In this patch I've removed `explicit-dynsym-no-dynstr.yaml` to `dynsym-section.yaml` and added the new test into. In a follow-up we probably might want to merge 2 another existent `dynsymtab-*.yaml` tests into it too. Differential revision: https://reviews.llvm.org/D90224 --- llvm/lib/ObjectYAML/ELFEmitter.cpp | 3 +- llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml | 33 ++++++++++++++++++++++ .../yaml2obj/ELF/explicit-dynsym-no-dynstr.yaml | 21 -------------- 3 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml delete mode 100644 llvm/test/tools/yaml2obj/ELF/explicit-dynsym-no-dynstr.yaml diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index b811cce..cbd76c7 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -903,7 +903,8 @@ void ELFState::initSymtabSectionHeader(Elf_Shdr &SHeader, assignSectionAddress(SHeader, YAMLSec); - SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, /*Offset=*/None); + SHeader.sh_offset = + alignToOffset(CBA, SHeader.sh_addralign, RawSec ? RawSec->Offset : None); if (RawSec && (RawSec->Content || RawSec->Size)) { assert(Symbols.empty()); diff --git a/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml b/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml new file mode 100644 index 0000000..1c6f3ef --- /dev/null +++ b/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml @@ -0,0 +1,33 @@ +## Check how we produce SHT_DYNSYM sections. + +## Check we do not crash/assert when .dynsym is specified +## explicitly, but .dynstr is not present. +## Check we set the sh_link field to 0 for the .dynsym section in this case. + +# RUN: yaml2obj %s -o %t1 +# RUN: llvm-readelf --section-headers %t1 | FileCheck %s + +# CHECK: Section Headers: +# CHECK-NEXT: [Nr] Name Type Address Off Size ES Flg Lk +# CHECK-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 +# CHECK-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 0 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .dynsym + Type: SHT_DYNSYM + Offset: [[OFFSET=]] + +## Check we can use the "Offset" key to to set an arbitrary offset for the SHT_DYNSYM section. + +# RUN: yaml2obj %s -DOFFSET=0x100 -o %t2 +# RUN: llvm-readelf --section-headers %t2 | FileCheck %s --check-prefix=OFFSET + +# OFFSET: Section Headers: +# OFFSET-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al +# OFFSET-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 +# OFFSET-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000100 000018 18 A 0 1 0 diff --git a/llvm/test/tools/yaml2obj/ELF/explicit-dynsym-no-dynstr.yaml b/llvm/test/tools/yaml2obj/ELF/explicit-dynsym-no-dynstr.yaml deleted file mode 100644 index 3197764..0000000 --- a/llvm/test/tools/yaml2obj/ELF/explicit-dynsym-no-dynstr.yaml +++ /dev/null @@ -1,21 +0,0 @@ -## Check we do not crash/assert when .dynsym is specified -## explicitly, but .dynstr is not present. - -# RUN: yaml2obj %s -o %t -# RUN: llvm-readelf --section-headers %t | FileCheck %s - -## Check that .dynsym has Link field set to 0. - -# CHECK: Section Headers: -# CHECK-NEXT: [Nr] Name Type Address Off Size ES Flg Lk -# CHECK-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0 -# CHECK-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 0 - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .dynsym - Type: SHT_DYNSYM -- 2.7.4