mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-16 16:02:19 +00:00
Bug fix: Assign output section indexes *after* sorting them.
llvm-svn: 247037
This commit is contained in:
parent
f44bd93bec
commit
b01b57486d
@ -184,11 +184,6 @@ private:
|
||||
StringTableSection<ELFT::Is64Bits> StringTable;
|
||||
|
||||
SymbolTableSection<ELFT> SymTable;
|
||||
|
||||
void addOutputSection(OutputSectionBase<ELFT::Is64Bits> *Sec) {
|
||||
OutputSections.push_back(Sec);
|
||||
Sec->setSectionIndex(OutputSections.size());
|
||||
}
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
@ -428,6 +423,13 @@ static bool cmpAlign(const DefinedCommon<ELFT> *A,
|
||||
return A->MaxAlignment > B->MaxAlignment;
|
||||
}
|
||||
|
||||
template <bool Is64Bits>
|
||||
static bool compSec(OutputSectionBase<Is64Bits> *A,
|
||||
OutputSectionBase<Is64Bits> *B) {
|
||||
// Place SHF_ALLOC sections first.
|
||||
return (A->getFlags() & SHF_ALLOC) && !(B->getFlags() & SHF_ALLOC);
|
||||
}
|
||||
|
||||
// Create output section objects and add them to OutputSections.
|
||||
template <class ELFT> void Writer<ELFT>::createSections() {
|
||||
SmallDenseMap<SectionKey<ELFT::Is64Bits>, OutputSection<ELFT> *> Map;
|
||||
@ -438,7 +440,7 @@ template <class ELFT> void Writer<ELFT>::createSections() {
|
||||
if (!Sec) {
|
||||
Sec = new (CAlloc.Allocate())
|
||||
OutputSection<ELFT>(Key.Name, Key.sh_type, Key.sh_flags);
|
||||
addOutputSection(Sec);
|
||||
OutputSections.push_back(Sec);
|
||||
}
|
||||
return Sec;
|
||||
};
|
||||
@ -485,13 +487,14 @@ template <class ELFT> void Writer<ELFT>::createSections() {
|
||||
}
|
||||
|
||||
BSSSec->setSize(Off);
|
||||
}
|
||||
|
||||
template <bool Is64Bits>
|
||||
static bool compSec(OutputSectionBase<Is64Bits> *A,
|
||||
OutputSectionBase<Is64Bits> *B) {
|
||||
// Place SHF_ALLOC sections first.
|
||||
return (A->getFlags() & SHF_ALLOC) && !(B->getFlags() & SHF_ALLOC);
|
||||
OutputSections.push_back(&SymTable);
|
||||
OutputSections.push_back(&StringTable);
|
||||
|
||||
std::stable_sort(OutputSections.begin(), OutputSections.end(),
|
||||
compSec<ELFT::Is64Bits>);
|
||||
for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
|
||||
OutputSections[I]->setSectionIndex(I + 1);
|
||||
}
|
||||
|
||||
// Visits all sections to assign incremental, non-overlapping RVAs and
|
||||
@ -501,11 +504,6 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
|
||||
uintX_t VA = 0x1000; // The first page is kept unmapped.
|
||||
uintX_t FileOff = SizeOfHeaders;
|
||||
|
||||
std::stable_sort(OutputSections.begin(), OutputSections.end(),
|
||||
compSec<ELFT::Is64Bits>);
|
||||
|
||||
addOutputSection(&SymTable);
|
||||
addOutputSection(&StringTable);
|
||||
StringTableIndex = OutputSections.size();
|
||||
SymTable.setStringTableIndex(StringTableIndex);
|
||||
|
||||
|
34
lld/test/elf2/output-section.s
Normal file
34
lld/test/elf2/output-section.s
Normal file
@ -0,0 +1,34 @@
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
|
||||
// RUN: lld -flavor gnu2 %t -o %t2
|
||||
// RUN: llvm-readobj -t %t2 | FileCheck %s
|
||||
// REQUIRES: x86
|
||||
|
||||
// CHECK: Symbol {
|
||||
// CHECK: Name: bar_sym
|
||||
// CHECK-NEXT: Value:
|
||||
// CHECK-NEXT: Size:
|
||||
// CHECK-NEXT: Binding:
|
||||
// CHECK-NEXT: Type:
|
||||
// CHECK-NEXT: Other:
|
||||
// CHECK-NEXT: Section: bar
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: Symbol {
|
||||
// CHECK-NEXT: Name: foo_sym
|
||||
// CHECK-NEXT: Value:
|
||||
// CHECK-NEXT: Size:
|
||||
// CHECK-NEXT: Binding:
|
||||
// CHECK-NEXT: Type:
|
||||
// CHECK-NEXT: Other:
|
||||
// CHECK-NEXT: Section: foo
|
||||
// CHECK-NEXT: }
|
||||
|
||||
.section foo
|
||||
.global foo_sym
|
||||
foo_sym:
|
||||
|
||||
.section bar, "a"
|
||||
.global bar_sym
|
||||
bar_sym:
|
||||
|
||||
.global _start
|
||||
_start:
|
Loading…
x
Reference in New Issue
Block a user