[PATCH] D74749: ThinLTOBitcodeWriter: drop dso_local when a GlobalVariable is converted to a declaration
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 17 18:40:38 PST 2020
MaskRay created this revision.
MaskRay added reviewers: evgeny777, pcc, tejohnson.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, hiraditya, inglorion.
Herald added a project: LLVM.
If we infer the dso_local flag for -fpic, dso_local should be dropped
when we convert a GlobalVariable a declaration. dso_local causes the
generation of direct access (e.g. R_X86_64_PC32). Such relocations referencing
STB_GLOBAL STV_DEFAULT objects are not allowed in a -shared link.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74749
Files:
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll
Index: llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll
@@ -0,0 +1,18 @@
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
+; RUN: llvm-modextract -b -n 0 -o %t0.bc %t
+; RUN: llvm-modextract -b -n 1 -o %t1.bc %t
+; RUN: not llvm-modextract -b -n 2 -o - %t 2>&1 | FileCheck --check-prefix=ERROR %s
+; RUN: llvm-dis -o - %t0.bc | FileCheck --check-prefix=M0 %s
+; RUN: llvm-dis -o - %t1.bc | FileCheck --check-prefix=M1 %s
+
+; ERROR: llvm-modextract: error: module index out of range; bitcode file contains 2 module(s)
+
+; M0: @g = external constant [1 x i8]
+; M1: @g = dso_local constant [1 x i8] c"0", !type !0
+ at g = dso_local constant [1 x i8] c"0", !type !0
+
+define [1 x i8]* @f() {
+ ret [1 x i8]* @g
+}
+
+!0 = !{i32 0, !"typeid"}
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===================================================================
--- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -183,6 +183,8 @@
for (GlobalValue *GV : V)
if (!convertToDeclaration(*GV))
GV->eraseFromParent();
+ else if (!GV->isImplicitDSOLocal())
+ GV->setDSOLocal(false);
}
void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74749.245064.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200218/5f097ab7/attachment.bin>
More information about the llvm-commits
mailing list