From 2600a58931d8d49f21a32fd69a844b76fc5cb0b2 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 21 Dec 2022 12:35:42 -0500 Subject: [PATCH] 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. --- llvm/lib/Linker/IRMover.cpp | 4 ++++ llvm/test/Linker/appending-global-err6.ll | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 llvm/test/Linker/appending-global-err6.ll diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 9e19220..d11b83d 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 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. diff --git a/llvm/test/Linker/appending-global-err6.ll b/llvm/test/Linker/appending-global-err6.ll new file mode 100644 index 0000000..92012dd --- /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 different address spaces cannot be linked. + +; CHECK: error: Appending variables with different address spaces need to be linked! + +@var = appending addrspace(1) global [ 1 x ptr ] undef -- 2.7.4