[lld] r262848 - Add support for common symbols.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 7 11:15:57 PST 2016
Author: rafael
Date: Mon Mar 7 13:15:57 2016
New Revision: 262848
URL: http://llvm.org/viewvc/llvm-project?rev=262848&view=rev
Log:
Add support for common symbols.
Added:
lld/trunk/test/ELF/lto/Inputs/common.s
lld/trunk/test/ELF/lto/common.ll
Modified:
lld/trunk/ELF/InputFiles.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=262848&r1=262847&r2=262848&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Mar 7 13:15:57 2016
@@ -439,7 +439,8 @@ void BitcodeFile::parse(DenseSet<StringR
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<StringR
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);
}
}
Added: lld/trunk/test/ELF/lto/Inputs/common.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/Inputs/common.s?rev=262848&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/Inputs/common.s (added)
+++ lld/trunk/test/ELF/lto/Inputs/common.s Mon Mar 7 13:15:57 2016
@@ -0,0 +1 @@
+ .comm a,8,4
Added: lld/trunk/test/ELF/lto/common.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/common.ll?rev=262848&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/common.ll (added)
+++ lld/trunk/test/ELF/lto/common.ll Mon Mar 7 13:15:57 2016
@@ -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"
+
+ at a = common global i32 0, align 8
More information about the llvm-commits
mailing list