From 7fa759a69d0ac90fc8937e755963b35160ecf377 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Tue, 1 Oct 2019 09:54:40 +0000 Subject: [PATCH] [yaml2obj] - Allow specifying custom Link values for SHT_HASH section. This allows setting any sh_link values for SHT_HASH sections. Differential revision: https://reviews.llvm.org/D68214 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373316 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ObjectYAML/ELFEmitter.cpp | 2 +- test/tools/yaml2obj/elf-hash-section.yaml | 32 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/ObjectYAML/ELFEmitter.cpp b/lib/ObjectYAML/ELFEmitter.cpp index 5acb02a5a57..1651d605650 100644 --- a/lib/ObjectYAML/ELFEmitter.cpp +++ b/lib/ObjectYAML/ELFEmitter.cpp @@ -821,7 +821,7 @@ void ELFState::writeSectionContent(Elf_Shdr &SHeader, CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign); unsigned Link = 0; - if (SN2I.lookup(".dynsym", Link)) + if (Section.Link.empty() && SN2I.lookup(".dynsym", Link)) SHeader.sh_link = Link; if (Section.Content) { diff --git a/test/tools/yaml2obj/elf-hash-section.yaml b/test/tools/yaml2obj/elf-hash-section.yaml index 9995574df0e..995c871439a 100644 --- a/test/tools/yaml2obj/elf-hash-section.yaml +++ b/test/tools/yaml2obj/elf-hash-section.yaml @@ -145,3 +145,35 @@ FileHeader: Sections: - Name: .hash Type: SHT_HASH + +## Check we can set any sh_link value with use of the "Link" tag. + +# RUN: yaml2obj --docnum=8 %s -o %t8 +# RUN: llvm-readobj --sections %t8 | FileCheck %s --check-prefix=LINK + +# LINK: Name: .hash1 +# LINK: Link: +# LINK-SAME: 123 + +# LINK: Name: .hash2 +# LINK: Link: +# LINK-SAME: 1 + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_386 +Sections: + - Name: .hash1 + Type: SHT_HASH + Content: "" + Link: 123 + - Name: .hash2 + Type: SHT_HASH + Content: "" + Link: .hash1 +## SHT_HASH is linked to dynamic symbol table by default if it exists. + - Name: .dynsym + Type: SHT_DYNSYM -- 2.11.4.GIT