diff options
author | Michael Spang <spang@google.com> | 2020-01-28 12:43:07 -0800 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-01-29 21:37:08 +0100 |
commit | 425198bf1f98e93be37b8675e29ac6d37529dc68 (patch) | |
tree | edffc5ee326a67ceb9e9cab5e7394ef96003aef6 /llvm/lib/CodeGen/GlobalMerge.cpp | |
parent | 81d73c6de33b2282f7174bd378699feac69bc5aa (diff) | |
download | bcm5719-llvm-425198bf1f98e93be37b8675e29ac6d37529dc68.tar.gz bcm5719-llvm-425198bf1f98e93be37b8675e29ac6d37529dc68.zip |
[GlobalMerge] Preserve symbol visibility when merging globals
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.
Differential Revision: https://reviews.llvm.org/D73235
(cherry picked from commit a2fb2c0ddca14c133f24d08af4a78b6a3d612ec6)
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalMerge.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index 5870e20d422..6e5593abb43 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -524,6 +524,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, 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 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, if (Linkage != GlobalValue::InternalLinkage || !IsMachO) { GlobalAlias *GA = GlobalAlias::create(Tys[StructIdxs[idx]], AddrSpace, Linkage, Name, GEP, &M); + GA->setVisibility(Visibility); GA->setDLLStorageClass(DLLStorage); } |