Add support for common symbols.

llvm-svn: 262848
This commit is contained in:
Rafael Espindola 2016-03-07 19:15:57 +00:00
parent e71d59fc4f
commit 37bcaac179
3 changed files with 42 additions and 3 deletions

View File

@ -439,7 +439,8 @@ void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
for (const BasicSymbolRef &Sym : Obj->symbols()) {
uint8_t Visibility = STV_DEFAULT;
if (const GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl())) {
const GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
if (GV) {
if (const Comdat *C = GV->getComdat())
if (!KeptComdats.count(C))
continue;
@ -454,10 +455,16 @@ void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
SymbolBody *Body;
uint32_t Flags = Sym.getFlags();
bool IsWeak = Flags & BasicSymbolRef::SF_Weak;
if (Flags & BasicSymbolRef::SF_Undefined)
if (Flags & BasicSymbolRef::SF_Undefined) {
Body = new (Alloc) Undefined(NameRef, IsWeak, Visibility, false);
else
} else if (Flags & BasicSymbolRef::SF_Common) {
const DataLayout &DL = M.getDataLayout();
uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
Body = new (Alloc)
DefinedCommon(NameRef, Size, GV->getAlignment(), IsWeak, Visibility);
} else {
Body = new (Alloc) DefinedBitcode(NameRef, IsWeak, Visibility);
}
SymbolBodies.push_back(Body);
}
}

View File

@ -0,0 +1 @@
.comm a,8,4

View File

@ -0,0 +1,31 @@
; REQUIRES: x86
; RUN: llvm-as %s -o %t1.o
; RUN: llvm-mc -triple=x86_64-pc-linux %p/Inputs/common.s -o %t2.o -filetype=obj
; RUN: ld.lld %t1.o %t2.o -o %t.so -shared
; RUN: llvm-readobj -s -t %t.so | FileCheck %s
; CHECK: Name: .bss
; CHECK-NEXT: Type: SHT_NOBITS
; CHECK-NEXT: Flags [
; CHECK-NEXT: SHF_ALLOC
; CHECK-NEXT: SHF_WRITE
; CHECK-NEXT: ]
; CHECK-NEXT: Address:
; CHECK-NEXT: Offset:
; CHECK-NEXT: Size: 8
; CHECK-NEXT: Link: 0
; CHECK-NEXT: Info: 0
; CHECK-NEXT: AddressAlignment: 8
; CHECK: Name: a
; CHECK-NEXT: Value:
; CHECK-NEXT: Size: 8
; CHECK-NEXT: Binding: Global
; CHECK-NEXT: Type: Object
; CHECK-NEXT: Other: 0
; CHECK-NEXT: Section: .bss
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@a = common global i32 0, align 8