[llvm] r232235 - LowerBitSets: Do not export symbols for bit set referenced globals on Darwin.
Peter Collingbourne
peter at pcc.me.uk
Fri Mar 13 17:00:49 PDT 2015
Author: pcc
Date: Fri Mar 13 19:00:49 2015
New Revision: 232235
URL: http://llvm.org/viewvc/llvm-project?rev=232235&view=rev
Log:
LowerBitSets: Do not export symbols for bit set referenced globals on Darwin.
The linker on that platform may re-order symbols or strip dead symbols, which
will break bit set checks. Avoid this by hiding the symbols from the linker.
Modified:
llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp
llvm/trunk/test/Transforms/LowerBitSets/simple.ll
Modified: llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp?rev=232235&r1=232234&r2=232235&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/LowerBitSets.cpp Fri Mar 13 19:00:49 2015
@@ -16,6 +16,7 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/ADT/EquivalenceClasses.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/GlobalVariable.h"
@@ -186,6 +187,7 @@ struct LowerBitSets : public ModulePass
Module *M;
+ bool LinkerSubsectionsViaSymbols;
IntegerType *Int1Ty;
IntegerType *Int8Ty;
IntegerType *Int32Ty;
@@ -235,6 +237,9 @@ bool LowerBitSets::doInitialization(Modu
M = &Mod;
const DataLayout &DL = Mod.getDataLayout();
+ Triple TargetTriple(M->getTargetTriple());
+ LinkerSubsectionsViaSymbols = TargetTriple.isMacOSX();
+
Int1Ty = Type::getInt1Ty(M->getContext());
Int8Ty = Type::getInt8Ty(M->getContext());
Int32Ty = Type::getInt32Ty(M->getContext());
@@ -524,9 +529,12 @@ void LowerBitSets::buildBitSetsFromGloba
ConstantInt::get(Int32Ty, I * 2)};
Constant *CombinedGlobalElemPtr =
ConstantExpr::getGetElementPtr(CombinedGlobal, CombinedGlobalIdxs);
+ GlobalValue::LinkageTypes GAliasLinkage = LinkerSubsectionsViaSymbols
+ ? GlobalValue::PrivateLinkage
+ : Globals[I]->getLinkage();
GlobalAlias *GAlias = GlobalAlias::create(
Globals[I]->getType()->getElementType(),
- Globals[I]->getType()->getAddressSpace(), Globals[I]->getLinkage(),
+ Globals[I]->getType()->getAddressSpace(), GAliasLinkage,
"", CombinedGlobalElemPtr, M);
GAlias->takeName(Globals[I]);
Globals[I]->replaceAllUsesWith(GAlias);
Modified: llvm/trunk/test/Transforms/LowerBitSets/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LowerBitSets/simple.ll?rev=232235&r1=232234&r2=232235&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LowerBitSets/simple.ll (original)
+++ llvm/trunk/test/Transforms/LowerBitSets/simple.ll Fri Mar 13 19:00:49 2015
@@ -1,4 +1,5 @@
; RUN: opt -S -lowerbitsets < %s | FileCheck %s
+; RUN: opt -S -lowerbitsets -mtriple=x86_64-apple-macosx10.8.0 < %s | FileCheck -check-prefix=CHECK-DARWIN %s
; RUN: opt -S -O3 < %s | FileCheck -check-prefix=CHECK-NODISCARD %s
target datalayout = "e-p:32:32"
@@ -41,6 +42,10 @@ target datalayout = "e-p:32:32"
; CHECK: @b = alias getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 2)
; CHECK: @c = alias getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 4)
; CHECK: @d = alias getelementptr inbounds ({ i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }, { i32, [0 x i8], [63 x i32], [4 x i8], i32, [0 x i8], [2 x i32] }* [[G]], i32 0, i32 6)
+; CHECK-DARWIN: @a = private alias
+; CHECK-DARWIN: @b = private alias
+; CHECK-DARWIN: @c = private alias
+; CHECK-DARWIN: @d = private alias
; CHECK: @bits = private alias getelementptr inbounds ([68 x i8], [68 x i8]* [[BA]], i32 0, i32 0)
; CHECK: @bits1 = private alias getelementptr inbounds ([68 x i8], [68 x i8]* [[BA]], i32 0, i32 0)
More information about the llvm-commits
mailing list