[PATCH] D140485: Linker: Disallow linking appending globals with different addrspaces
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 21 09:49:19 PST 2022
arsenm created this revision.
arsenm added reviewers: nikic, MaskRay.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
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.
https://reviews.llvm.org/D140485
Files:
llvm/lib/Linker/IRMover.cpp
llvm/test/Linker/appending-global-err6.ll
Index: llvm/test/Linker/appending-global-err6.ll
===================================================================
--- /dev/null
+++ 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 different address spaces cannot be linked.
+
+; CHECK: error: Appending variables with different address spaces need to be linked!
+
+ at var = appending addrspace(1) global [ 1 x ptr ] undef
Index: llvm/lib/Linker/IRMover.cpp
===================================================================
--- llvm/lib/Linker/IRMover.cpp
+++ llvm/lib/Linker/IRMover.cpp
@@ -897,6 +897,10 @@
if (DstGV->getSection() != SrcGV->getSection())
return stringErr(
"Appending variables with different section name need to be linked!");
+
+ if (DstGV->getAddressSpace() != SrcGV->getAddressSpace())
+ return stringErr("Appending variables with different address spaces need "
+ "to be linked!");
}
// Do not need to do anything if source is a declaration.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140485.484605.patch
Type: text/x-patch
Size: 1233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221221/dc2d393c/attachment.bin>
More information about the llvm-commits
mailing list