forked from OSchip/llvm-project
Set the correct value for the common symbols.
In the relocatable object it is the alignment, but in the linked file it is a regular address. llvm-svn: 246505
This commit is contained in:
parent
fa715655ee
commit
ce8c9c0548
|
|
@ -138,12 +138,18 @@ template <class ELFT> class DefinedCommon : public Defined<ELFT> {
|
|||
typedef typename Base::Elf_Sym Elf_Sym;
|
||||
|
||||
public:
|
||||
typedef typename std::conditional<ELFT::Is64Bits, uint64_t, uint32_t>::type
|
||||
uintX_t;
|
||||
explicit DefinedCommon(StringRef N, const Elf_Sym &Sym)
|
||||
: Defined<ELFT>(Base::DefinedCommonKind, N, Sym) {}
|
||||
|
||||
static bool classof(const SymbolBody *S) {
|
||||
return S->kind() == Base::DefinedCommonKind;
|
||||
}
|
||||
|
||||
// The output offset of this common symbol in the output bss. Computed by the
|
||||
// writer.
|
||||
uintX_t OffsetInBSS;
|
||||
};
|
||||
|
||||
// Regular defined symbols read from object file symbol tables.
|
||||
|
|
|
|||
|
|
@ -344,7 +344,10 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
|
|||
uintX_t VA = Out->getVA();
|
||||
if (Section)
|
||||
VA += Section->getOutputSectionOff();
|
||||
VA += InputSym->st_value;
|
||||
if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
|
||||
VA += C->OffsetInBSS;
|
||||
else
|
||||
VA += InputSym->st_value;
|
||||
ESym->st_value = VA;
|
||||
}
|
||||
|
||||
|
|
@ -445,6 +448,7 @@ template <class ELFT> void Writer<ELFT>::createSections() {
|
|||
const Elf_Sym &Sym = C->Sym;
|
||||
uintX_t Align = Sym.st_value;
|
||||
Off = RoundUpToAlignment(Off, Align);
|
||||
C->OffsetInBSS = Off;
|
||||
Off += Sym.st_size;
|
||||
}
|
||||
BSSSec->setSize(Off);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/common.s -o %t2
|
||||
// RUN: lld -flavor gnu2 %t %t2 -o %t3
|
||||
// RUN: llvm-readobj -t %t3 | FileCheck %s
|
||||
// RUN: llvm-readobj -t -s %t3 | FileCheck %s
|
||||
// REQUIRES: x86
|
||||
|
||||
// CHECK: Name: .bss
|
||||
// CHECK-NEXT: Type: SHT_NOBITS
|
||||
// CHECK-NEXT: Flags [
|
||||
// CHECK-NEXT: SHF_ALLOC
|
||||
// CHECK-NEXT: SHF_WRITE
|
||||
// CHECK-NEXT: ]
|
||||
// CHECK-NEXT: Address: 0x1000
|
||||
|
||||
|
||||
// CHECK: Name: sym2
|
||||
// CHECK-NEXT: Value: 0x1004
|
||||
// CHECK-NEXT: Value: 0x1008
|
||||
// CHECK-NEXT: Size: 8
|
||||
// CHECK-NEXT: Binding: Global
|
||||
// CHECK-NEXT: Type: Object
|
||||
|
|
@ -13,7 +22,7 @@
|
|||
// CHECK-NEXT: Section: .bss
|
||||
|
||||
// CHECK: Name: sym1
|
||||
// CHECK-NEXT: Value: 0x1004
|
||||
// CHECK-NEXT: Value: 0x1000
|
||||
// CHECK-NEXT: Size: 8
|
||||
// CHECK-NEXT: Binding: Global
|
||||
// CHECK-NEXT: Type: Object
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ abs = 0x123
|
|||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: Symbol {
|
||||
// CHECK-NEXT: Name: common (34)
|
||||
// CHECK-NEXT: Value: 0x1008
|
||||
// CHECK-NEXT: Value: 0x1004
|
||||
// CHECK-NEXT: Size: 4
|
||||
// CHECK-NEXT: Binding: Global (0x1)
|
||||
// CHECK-NEXT: Type: Object (0x1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue