[llvm] 2600a58 - Linker: Disallow linking appending globals with different addrspaces
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 21 19:15:06 PST 2022
Author: Matt Arsenault
Date: 2022-12-21T22:15:01-05:00
New Revision: 2600a58931d8d49f21a32fd69a844b76fc5cb0b2
URL: https://github.com/llvm/llvm-project/commit/2600a58931d8d49f21a32fd69a844b76fc5cb0b2
DIFF: https://github.com/llvm/llvm-project/commit/2600a58931d8d49f21a32fd69a844b76fc5cb0b2.diff
LOG: Linker: Disallow linking appending globals with different addrspaces
The current appending linkage handling implicitly assumes this by
using a basic ConstantExpr::getBitCast to resolve type
mismatches. Avoid this edge case so we don't need to keep the type
mismatch replacement code around after opaque pointers.
Added:
llvm/test/Linker/appending-global-err6.ll
Modified:
llvm/lib/Linker/IRMover.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 9e19220bbf433..d11b83d371074 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -897,6 +897,10 @@ IRLinker::linkAppendingVarProto(GlobalVariable *DstGV,
if (DstGV->getSection() != SrcGV->getSection())
return stringErr(
"Appending variables with
diff erent section name need to be linked!");
+
+ if (DstGV->getAddressSpace() != SrcGV->getAddressSpace())
+ return stringErr("Appending variables with
diff erent address spaces need "
+ "to be linked!");
}
// Do not need to do anything if source is a declaration.
diff --git a/llvm/test/Linker/appending-global-err6.ll b/llvm/test/Linker/appending-global-err6.ll
new file mode 100644
index 0000000000000..92012dd49b982
--- /dev/null
+++ b/llvm/test/Linker/appending-global-err6.ll
@@ -0,0 +1,9 @@
+; RUN: not llvm-link %s %p/Inputs/appending-global.ll -S -o - 2>&1 | FileCheck %s
+; RUN: not llvm-link %p/Inputs/appending-global.ll %s -S -o - 2>&1 | FileCheck %s
+
+; Negative test to check that global variables with appending linkage
+; and
diff erent address spaces cannot be linked.
+
+; CHECK: error: Appending variables with
diff erent address spaces need to be linked!
+
+ at var = appending addrspace(1) global [ 1 x ptr ] undef
More information about the llvm-commits
mailing list