[llvm] r217458 - Handle common linkage correctly in the gold plugin.
Rafael Espindola
rafael.espindola at gmail.com
Tue Sep 9 13:08:22 PDT 2014
Author: rafael
Date: Tue Sep 9 15:08:22 2014
New Revision: 217458
URL: http://llvm.org/viewvc/llvm-project?rev=217458&view=rev
Log:
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.
Added:
llvm/trunk/test/tools/gold/Inputs/common.ll
llvm/trunk/test/tools/gold/common.ll
Modified:
llvm/trunk/tools/gold/gold-plugin.cpp
Added: llvm/trunk/test/tools/gold/Inputs/common.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/Inputs/common.ll?rev=217458&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/Inputs/common.ll (added)
+++ llvm/trunk/test/tools/gold/Inputs/common.ll Tue Sep 9 15:08:22 2014
@@ -0,0 +1 @@
+ at a = common global i16 0, align 4
Added: llvm/trunk/test/tools/gold/common.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/common.ll?rev=217458&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/common.ll (added)
+++ llvm/trunk/test/tools/gold/common.ll Tue Sep 9 15:08:22 2014
@@ -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
+
+ at a = common global i8 0, align 8
+
+; CHECK: @a = common global i16 0, align 8
Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=217458&r1=217457&r2=217458&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Tue Sep 9 15:08:22 2014
@@ -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, c
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");
More information about the llvm-commits
mailing list