forked from OSchip/llvm-project
Add DT_RELA and DT_RELASZ to the dynamic table.
llvm-svn: 247837
This commit is contained in:
parent
ea188fc318
commit
3887ebfc21
|
@ -326,17 +326,23 @@ class DynamicSection final : public OutputSectionBase<ELFT::Is64Bits> {
|
|||
typedef typename Base::Elf_Dyn Elf_Dyn;
|
||||
|
||||
public:
|
||||
DynamicSection(SymbolTable &SymTab, HashTableSection<ELFT> &HashSec)
|
||||
DynamicSection(SymbolTable &SymTab, HashTableSection<ELFT> &HashSec,
|
||||
RelocationSection<ELFT> &RelaDynSec)
|
||||
: OutputSectionBase<ELFT::Is64Bits>(".dynamic", SHT_DYNAMIC,
|
||||
SHF_ALLOC | SHF_WRITE),
|
||||
HashSec(HashSec), DynSymSec(HashSec.getDynSymSec()),
|
||||
DynStrSec(DynSymSec.getStrTabSec()), SymTab(SymTab) {
|
||||
DynStrSec(DynSymSec.getStrTabSec()), RelaDynSec(RelaDynSec),
|
||||
SymTab(SymTab) {
|
||||
typename Base::HeaderT &Header = this->Header;
|
||||
Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
|
||||
Header.sh_entsize = ELFT::Is64Bits ? 16 : 8;
|
||||
|
||||
unsigned NumEntries = 0;
|
||||
|
||||
if (RelaDynSec.hasReocs()) {
|
||||
++NumEntries; // DT_RELA
|
||||
++NumEntries; // DT_RELASZ
|
||||
}
|
||||
++NumEntries; // DT_SYMTAB
|
||||
++NumEntries; // DT_STRTAB
|
||||
++NumEntries; // DT_STRSZ
|
||||
|
@ -366,6 +372,16 @@ public:
|
|||
void writeTo(uint8_t *Buf) override {
|
||||
auto *P = reinterpret_cast<Elf_Dyn *>(Buf);
|
||||
|
||||
if (RelaDynSec.hasReocs()) {
|
||||
P->d_tag = DT_RELA;
|
||||
P->d_un.d_ptr = RelaDynSec.getVA();
|
||||
++P;
|
||||
|
||||
P->d_tag = DT_RELASZ;
|
||||
P->d_un.d_val = RelaDynSec.getSize();
|
||||
++P;
|
||||
}
|
||||
|
||||
P->d_tag = DT_SYMTAB;
|
||||
P->d_un.d_ptr = DynSymSec.getVA();
|
||||
++P;
|
||||
|
@ -406,6 +422,7 @@ private:
|
|||
HashTableSection<ELFT> &HashSec;
|
||||
SymbolTableSection<ELFT> &DynSymSec;
|
||||
StringTableSection<ELFT::Is64Bits> &DynStrSec;
|
||||
RelocationSection<ELFT> &RelaDynSec;
|
||||
SymbolTable &SymTab;
|
||||
};
|
||||
|
||||
|
@ -420,7 +437,8 @@ public:
|
|||
typedef typename ELFFile<ELFT>::Elf_Rela Elf_Rela;
|
||||
Writer(SymbolTable *T)
|
||||
: SymTabSec(*this, *T, StrTabSec), DynSymSec(*this, *T, DynStrSec),
|
||||
RelaDynSec(DynSymSec), HashSec(DynSymSec), DynamicSec(*T, HashSec) {}
|
||||
RelaDynSec(DynSymSec), HashSec(DynSymSec),
|
||||
DynamicSec(*T, HashSec, RelaDynSec) {}
|
||||
void run();
|
||||
|
||||
const OutputSection<ELFT> &getBSS() const {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o
|
||||
// RUN: lld -flavor gnu2 -shared %t2.o -o %t2.so
|
||||
// RUN: lld -flavor gnu2 %t.o %t2.so -o %t
|
||||
// RUN: llvm-readobj -r --expand-relocs -s %t | FileCheck %s
|
||||
// RUN: llvm-readobj -dynamic-table -r --expand-relocs -s %t | FileCheck %s
|
||||
// REQUIRES: x86
|
||||
|
||||
// CHECK: Name: .text
|
||||
|
@ -21,9 +21,9 @@
|
|||
// CHECK-NEXT: Flags [
|
||||
// CHECK-NEXT: SHF_ALLOC
|
||||
// CHECK-NEXT: ]
|
||||
// CHECK-NEXT: Address: 0x16000
|
||||
// CHECK-NEXT: Address: [[RELAADDR:.*]]
|
||||
// CHECK-NEXT: Offset: 0x6000
|
||||
// CHECK-NEXT: Size: 24
|
||||
// CHECK-NEXT: Size: [[RELASIZE:.*]]
|
||||
// CHECK-NEXT: Link: 4
|
||||
// CHECK-NEXT: Info: 0
|
||||
// CHECK-NEXT: AddressAlignment: 8
|
||||
|
@ -40,6 +40,11 @@
|
|||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: ]
|
||||
|
||||
// CHECK: DynamicSection [
|
||||
// CHECK-NEXT: Tag Type Name/Value
|
||||
// CHECK-NEXT: 0x0000000000000007 RELA [[RELAADDR]]
|
||||
// CHECK-NEXT: 0x0000000000000008 RELASZ [[RELASIZE]] (bytes)
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
.quad bar + 0x42
|
||||
|
|
Loading…
Reference in New Issue