mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-25 14:50:26 +00:00
Start creating the .dynamic section.
For now it is always empty. llvm-svn: 247056
This commit is contained in:
parent
0516b1864d
commit
740fafe54d
@ -50,6 +50,10 @@ public:
|
||||
return ObjectFiles;
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<SharedFileBase>> &getSharedFiles() const {
|
||||
return SharedFiles;
|
||||
}
|
||||
|
||||
private:
|
||||
Symbol *insert(SymbolBody *New);
|
||||
template <class ELFT> void addELFFile(ELFFileBase *File);
|
||||
|
@ -156,13 +156,36 @@ private:
|
||||
const StringTableSection<ELFT::Is64Bits> &StrTabSec;
|
||||
};
|
||||
|
||||
template <bool Is64Bits>
|
||||
class DynamicSection final : public OutputSectionBase<Is64Bits> {
|
||||
public:
|
||||
DynamicSection(const StringTableSection<Is64Bits> &StrTabSec)
|
||||
: OutputSectionBase<Is64Bits>(".dynamic", SHT_DYNAMIC,
|
||||
SHF_ALLOC | SHF_WRITE),
|
||||
StrTabSec(StrTabSec) {
|
||||
typedef OutputSectionBase<Is64Bits> Base;
|
||||
typename Base::HeaderT &Header = this->Header;
|
||||
Header.sh_addralign = Is64Bits ? 8 : 4;
|
||||
Header.sh_entsize = Is64Bits ? 16 : 8;
|
||||
}
|
||||
|
||||
void finalize() override {
|
||||
this->Header.sh_link = StrTabSec.getSectionIndex();
|
||||
}
|
||||
|
||||
void writeTo(uint8_t *Buf) override {}
|
||||
|
||||
private:
|
||||
const StringTableSection<Is64Bits> &StrTabSec;
|
||||
};
|
||||
|
||||
// The writer writes a SymbolTable result to a file.
|
||||
template <class ELFT> class Writer {
|
||||
public:
|
||||
typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
|
||||
typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
|
||||
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
|
||||
Writer(SymbolTable *T) : SymTable(*T, StringTable) {}
|
||||
Writer(SymbolTable *T) : SymTable(*T, StringTable), DynamicSec(StringTable) {}
|
||||
void run();
|
||||
|
||||
private:
|
||||
@ -184,6 +207,8 @@ private:
|
||||
StringTableSection<ELFT::Is64Bits> StringTable;
|
||||
|
||||
SymbolTableSection<ELFT> SymTable;
|
||||
|
||||
DynamicSection<ELFT::Is64Bits> DynamicSec;
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
@ -491,6 +516,11 @@ template <class ELFT> void Writer<ELFT>::createSections() {
|
||||
OutputSections.push_back(&SymTable);
|
||||
OutputSections.push_back(&StringTable);
|
||||
|
||||
const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
|
||||
Symtab.getSharedFiles();
|
||||
if (!SharedFiles.empty())
|
||||
OutputSections.push_back(&DynamicSec);
|
||||
|
||||
std::stable_sort(OutputSections.begin(), OutputSections.end(),
|
||||
compSec<ELFT::Is64Bits>);
|
||||
for (unsigned I = 0, N = OutputSections.size(); I < N; ++I)
|
||||
|
@ -1,8 +1,38 @@
|
||||
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
|
||||
// RUN: lld -flavor gnu2 %t.o %p/Inputs/i686-simple-library.so -o %t
|
||||
// RUN: llvm-readobj -t %t | FileCheck %s
|
||||
// RUN: llvm-readobj -t -s %t | FileCheck %s
|
||||
// REQUIRES: x86
|
||||
|
||||
// CHECK: Name: .dynamic
|
||||
// CHECK-NEXT: Type: SHT_DYNAMIC
|
||||
// CHECK-NEXT: Flags [
|
||||
// CHECK-NEXT: SHF_ALLOC
|
||||
// CHECK-NEXT: SHF_WRITE
|
||||
// CHECK-NEXT: ]
|
||||
// CHECK-NEXT: Address:
|
||||
// CHECK-NEXT: Offset:
|
||||
// CHECK-NEXT: Size:
|
||||
// CHECK-NEXT: Link: 6
|
||||
// CHECK-NEXT: Info: 0
|
||||
// CHECK-NEXT: AddressAlignment: 4
|
||||
// CHECK-NEXT: EntrySize: 8
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: Index: 6
|
||||
// CHECK-NEXT: Name: .strtab
|
||||
// CHECK-NEXT: Type: SHT_STRTAB
|
||||
// CHECK-NEXT: Flags [
|
||||
// CHECK-NEXT: ]
|
||||
// CHECK-NEXT: Address:
|
||||
// CHECK-NEXT: Offset:
|
||||
// CHECK-NEXT: Size:
|
||||
// CHECK-NEXT: Link: 0
|
||||
// CHECK-NEXT: Info: 0
|
||||
// CHECK-NEXT: AddressAlignment: 1
|
||||
// CHECK-NEXT: EntrySize: 0
|
||||
// CHECK-NEXT: }
|
||||
|
||||
|
||||
// CHECK: Symbols [
|
||||
// CHECK-NEXT: Symbol {
|
||||
// CHECK-NEXT: Name:
|
||||
|
Loading…
Reference in New Issue
Block a user