[PATCH] D73235: [GlobalMerge] Preserve symbol visibility when merging globals
Michael Spang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 14:40:45 PST 2020
mspang created this revision.
mspang added reviewers: john.brawn, ab, echristo.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
Symbols created for merged external global variables have default
visibility. This can break programs when compiling with -Oz -fvisibility=hidden
as symbols that should be hidden will be exported at link time.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73235
Files:
llvm/lib/CodeGen/GlobalMerge.cpp
llvm/test/CodeGen/AArch64/global-merge-hidden-minsize.ll
Index: llvm/test/CodeGen/AArch64/global-merge-hidden-minsize.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/global-merge-hidden-minsize.ll
@@ -0,0 +1,18 @@
+; RUN: llc %s -mtriple=arm-none-linux-gnu -o - | FileCheck %s
+; RUN: llc %s -mtriple=aarch64-none-linux-gnu -o - | FileCheck %s
+
+ at x = hidden global i32 0, align 4
+ at y = hidden global i32 0, align 4
+
+define hidden void @f() #0 {
+ store i32 0, i32* @x, align 4
+ store i32 0, i32* @y, align 4
+ ret void
+}
+
+attributes #0 = { minsize optsize }
+
+; CHECK: .globl x
+; CHECK: .hidden x
+; CHECK: .globl y
+; CHECK: .hidden y
Index: llvm/lib/CodeGen/GlobalMerge.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalMerge.cpp
+++ llvm/lib/CodeGen/GlobalMerge.cpp
@@ -524,6 +524,7 @@
for (ssize_t k = i, idx = 0; k != j; k = GlobalSet.find_next(k), ++idx) {
GlobalValue::LinkageTypes Linkage = Globals[k]->getLinkage();
std::string Name = Globals[k]->getName();
+ GlobalValue::VisibilityTypes Visibility = Globals[k]->getVisibility();
GlobalValue::DLLStorageClassTypes DLLStorage =
Globals[k]->getDLLStorageClass();
@@ -549,6 +550,7 @@
if (Linkage != GlobalValue::InternalLinkage || !IsMachO) {
GlobalAlias *GA = GlobalAlias::create(Tys[StructIdxs[idx]], AddrSpace,
Linkage, Name, GEP, &M);
+ GA->setVisibility(Visibility);
GA->setDLLStorageClass(DLLStorage);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73235.239703.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200122/2eb00a80/attachment.bin>
More information about the llvm-commits
mailing list