summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-09-09 20:08:22 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-09-09 20:08:22 +0000
commit890db27b674cbb269d5d191e3e1af0cc29495f50 (patch)
tree1b15652687cd8e11ba827b8b65339bf3b02a02f7
parent1191adf4df172d76143e84388fdd2cfe1b790e10 (diff)
downloadbcm5719-llvm-890db27b674cbb269d5d191e3e1af0cc29495f50.tar.gz
bcm5719-llvm-890db27b674cbb269d5d191e3e1af0cc29495f50.zip
Handle common linkage correctly in the gold plugin.
This is the plugin version of pr20882. This handles the case of every common symbol being in the IR. We will need some support from gold to handle the case where some symbols are in ELF and some in the IR. llvm-svn: 217458
-rw-r--r--llvm/test/tools/gold/Inputs/common.ll1
-rw-r--r--llvm/test/tools/gold/common.ll11
-rw-r--r--llvm/tools/gold/gold-plugin.cpp8
3 files changed, 20 insertions, 0 deletions
diff --git a/llvm/test/tools/gold/Inputs/common.ll b/llvm/test/tools/gold/Inputs/common.ll
new file mode 100644
index 00000000000..46f199e167a
--- /dev/null
+++ b/llvm/test/tools/gold/Inputs/common.ll
@@ -0,0 +1 @@
+@a = common global i16 0, align 4
diff --git a/llvm/test/tools/gold/common.ll b/llvm/test/tools/gold/common.ll
new file mode 100644
index 00000000000..77976c84495
--- /dev/null
+++ b/llvm/test/tools/gold/common.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-as %s -o %t1.o
+; RUN: llvm-as %p/Inputs/common.ll -o %t2.o
+
+; RUN: ld -plugin %llvmshlibdir/LLVMgold.so \
+; RUN: --plugin-opt=emit-llvm \
+; RUN: -shared %t1.o %t2.o -o %t3.o
+; RUN: llvm-dis %t3.o -o - | FileCheck %s
+
+@a = common global i8 0, align 8
+
+; CHECK: @a = common global i16 0, align 8
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index f2eeb7e8c4f..110433aefe3 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -18,6 +18,7 @@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/CodeGen/Analysis.h"
#include "llvm/CodeGen/CommandFlags.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
@@ -576,6 +577,13 @@ getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile,
if (!GV)
continue; // Asm symbol.
+ if (GV->hasCommonLinkage()) {
+ // Common linkage is special. There is no single symbol that wins the
+ // resolution. Instead we have to collect the maximum alignment and size.
+ // The IR linker does that for us if we just pass it every common GV.
+ continue;
+ }
+
switch (Resolution) {
case LDPR_UNKNOWN:
llvm_unreachable("Unexpected resolution");
OpenPOWER on IntegriCloud