[lld] r296577 - Set output section's st_entsize based on input section's st_entsize.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 28 20:04:23 PST 2017
Author: ruiu
Date: Tue Feb 28 22:04:23 2017
New Revision: 296577
URL: http://llvm.org/viewvc/llvm-project?rev=296577&view=rev
Log:
Set output section's st_entsize based on input section's st_entsize.
Each input section knows its sh_entsize value, so we can set output
section's sh_entsize based on input sections values.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/test/ELF/merge-string.s
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=296577&r1=296576&r2=296577&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Feb 28 22:04:23 2017
@@ -66,42 +66,8 @@ void OutputSection::writeHeaderTo(typena
Shdr->sh_name = ShName;
}
-template <class ELFT> static uint64_t getEntsize(uint32_t Type) {
- switch (Type) {
- case SHT_RELA:
- return sizeof(typename ELFT::Rela);
- case SHT_REL:
- return sizeof(typename ELFT::Rel);
- case SHT_MIPS_REGINFO:
- return sizeof(Elf_Mips_RegInfo<ELFT>);
- case SHT_MIPS_OPTIONS:
- return sizeof(Elf_Mips_Options<ELFT>) + sizeof(Elf_Mips_RegInfo<ELFT>);
- case SHT_MIPS_ABIFLAGS:
- return sizeof(Elf_Mips_ABIFlags<ELFT>);
- default:
- return 0;
- }
-}
-
OutputSection::OutputSection(StringRef Name, uint32_t Type, uint64_t Flags)
- : Name(Name), Addralign(1), Flags(Flags), Type(Type) {
- switch (Config->EKind) {
- case ELFNoneKind:
- llvm_unreachable("unknown kind");
- case ELF32LEKind:
- this->Entsize = getEntsize<ELF32LE>(Type);
- break;
- case ELF32BEKind:
- this->Entsize = getEntsize<ELF32BE>(Type);
- break;
- case ELF64LEKind:
- this->Entsize = getEntsize<ELF64LE>(Type);
- break;
- case ELF64BEKind:
- this->Entsize = getEntsize<ELF64BE>(Type);
- break;
- }
-}
+ : Name(Name), Addralign(1), Flags(Flags), Type(Type) {}
template <typename ELFT>
static bool compareByFilePosition(InputSection *A, InputSection *B) {
@@ -153,10 +119,15 @@ void OutputSection::addSection(InputSect
Sections.push_back(S);
S->OutSec = this;
this->updateAlignment(S->Alignment);
- // Keep sh_entsize value of the input section to be able to perform merging
- // later during a final linking using the generated relocatable object.
- if (Config->Relocatable && (S->Flags & SHF_MERGE))
- this->Entsize = S->Entsize;
+
+ // If this section contains a table of fixed-size entries, sh_entsize
+ // holds the element size. Consequently, if this contains two or more
+ // input sections, all of them must have the same sh_entsize. However,
+ // you can put different types of input sections into one output
+ // sectin by using linker scripts. I don't know what to do here.
+ // Probably we sholuld handle that as an error. But for now we just
+ // pick the largest sh_entsize.
+ this->Entsize = std::max(this->Entsize, S->Entsize);
}
// This function is called after we sort input sections
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=296577&r1=296576&r2=296577&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Feb 28 22:04:23 2017
@@ -125,7 +125,9 @@ template <class ELFT> MergeInputSection<
template <class ELFT>
MipsAbiFlagsSection<ELFT>::MipsAbiFlagsSection(Elf_Mips_ABIFlags Flags)
: SyntheticSection(SHF_ALLOC, SHT_MIPS_ABIFLAGS, 8, ".MIPS.abiflags"),
- Flags(Flags) {}
+ Flags(Flags) {
+ this->Entsize = sizeof(Elf_Mips_ABIFlags);
+}
template <class ELFT> void MipsAbiFlagsSection<ELFT>::writeTo(uint8_t *Buf) {
memcpy(Buf, &Flags, sizeof(Flags));
@@ -182,7 +184,9 @@ MipsAbiFlagsSection<ELFT> *MipsAbiFlagsS
template <class ELFT>
MipsOptionsSection<ELFT>::MipsOptionsSection(Elf_Mips_RegInfo Reginfo)
: SyntheticSection(SHF_ALLOC, SHT_MIPS_OPTIONS, 8, ".MIPS.options"),
- Reginfo(Reginfo) {}
+ Reginfo(Reginfo) {
+ this->Entsize = sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
+}
template <class ELFT> void MipsOptionsSection<ELFT>::writeTo(uint8_t *Buf) {
auto *Options = reinterpret_cast<Elf_Mips_Options *>(Buf);
@@ -242,7 +246,9 @@ MipsOptionsSection<ELFT> *MipsOptionsSec
template <class ELFT>
MipsReginfoSection<ELFT>::MipsReginfoSection(Elf_Mips_RegInfo Reginfo)
: SyntheticSection(SHF_ALLOC, SHT_MIPS_REGINFO, 4, ".reginfo"),
- Reginfo(Reginfo) {}
+ Reginfo(Reginfo) {
+ this->Entsize = sizeof(Elf_Mips_RegInfo);
+}
template <class ELFT> void MipsReginfoSection<ELFT>::writeTo(uint8_t *Buf) {
if (!Config->Relocatable)
@@ -1013,6 +1019,7 @@ DynamicSection<ELFT>::DynamicSection()
: SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_DYNAMIC, sizeof(uintX_t),
".dynamic") {
this->Entsize = ELFT::Is64Bits ? 16 : 8;
+
// .dynamic section is not writable on MIPS.
// See "Special Section" in Chapter 4 in the following document:
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
@@ -1147,7 +1154,6 @@ template <class ELFT> void DynamicSectio
add({DT_MIPS_RLD_MAP, In<ELFT>::MipsRldMap});
}
- this->OutSec->Entsize = this->Entsize;
this->OutSec->Link = this->Link;
// +1 for DT_NULL
@@ -1260,7 +1266,6 @@ template <class ELFT> void RelocationSec
// Set required output section properties.
this->OutSec->Link = this->Link;
- this->OutSec->Entsize = this->Entsize;
}
template <class ELFT>
@@ -1295,7 +1300,6 @@ static bool sortMipsSymbols(const Symbol
// dynamic linking are inherently all globals.)
template <class ELFT> void SymbolTableSection<ELFT>::finalizeContents() {
this->OutSec->Link = StrTabSec.OutSec->SectionIndex;
- this->OutSec->Entsize = this->Entsize;
// If it is a .dynsym, there should be no local symbols, but we need
// to do a few things for the dynamic linker.
@@ -1451,7 +1455,6 @@ GnuHashTableSection<ELFT>::GnuHashTableS
}
template <class ELFT> void GnuHashTableSection<ELFT>::finalizeContents() {
- this->OutSec->Entsize = this->Entsize;
this->OutSec->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex;
// Computes bloom filter size in word size. We want to allocate 8
@@ -1587,7 +1590,6 @@ HashTableSection<ELFT>::HashTableSection
template <class ELFT> void HashTableSection<ELFT>::finalizeContents() {
this->OutSec->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex;
- this->OutSec->Entsize = this->Entsize;
unsigned NumEntries = 2; // nbucket and nchain.
NumEntries += In<ELFT>::DynSymTab->getNumSymbols(); // The chain entries.
@@ -1933,10 +1935,11 @@ template <class ELFT> size_t VersionDefi
template <class ELFT>
VersionTableSection<ELFT>::VersionTableSection()
: SyntheticSection(SHF_ALLOC, SHT_GNU_versym, sizeof(uint16_t),
- ".gnu.version") {}
+ ".gnu.version") {
+ this->Entsize = sizeof(Elf_Versym);
+}
template <class ELFT> void VersionTableSection<ELFT>::finalizeContents() {
- this->OutSec->Entsize = this->Entsize = sizeof(Elf_Versym);
// At the moment of june 2016 GNU docs does not mention that sh_link field
// should be set, but Sun docs do. Also readelf relies on this field.
this->OutSec->Link = In<ELFT>::DynSymTab->OutSec->SectionIndex;
Modified: lld/trunk/test/ELF/merge-string.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/merge-string.s?rev=296577&r1=296576&r2=296577&view=diff
==============================================================================
--- lld/trunk/test/ELF/merge-string.s (original)
+++ lld/trunk/test/ELF/merge-string.s Tue Feb 28 22:04:23 2017
@@ -70,7 +70,7 @@ zed:
// NOMERGE-NEXT: Link: 0
// NOMERGE-NEXT: Info: 0
// NOMERGE-NEXT: AddressAlignment: 1
-// NOMERGE-NEXT: EntrySize: 0
+// NOMERGE-NEXT: EntrySize: 1
// NOMERGE-NEXT: SectionData (
// NOMERGE-NEXT: 0000: 61626300 61626300 626300 |abc.abc.bc.|
// NOMERGE-NEXT: )
More information about the llvm-commits
mailing list