Index: lib/CodeGen/GlobalMerge.cpp =================================================================== --- lib/CodeGen/GlobalMerge.cpp +++ lib/CodeGen/GlobalMerge.cpp @@ -497,6 +497,8 @@ 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::DLLStorageClassTypes DLLStorage = + Globals[k]->getDLLStorageClass(); // Copy metadata while adjusting any debug info metadata by the original // global's offset within the merged global. @@ -517,7 +519,9 @@ // It's not safe on Mach-O as the alias (and thus the portion of the // MergedGlobals variable) may be dead stripped at link time. if (Linkage != GlobalValue::InternalLinkage || !IsMachO) { - GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M); + GlobalAlias *GA = + GlobalAlias::create(Tys[idx], AddrSpace, Linkage, Name, GEP, &M); + GA->setDLLStorageClass(DLLStorage); } NumMerged++; @@ -577,8 +581,7 @@ for (auto &GV : M.globals()) { // Merge is safe for "normal" internal or external globals only if (GV.isDeclaration() || GV.isThreadLocal() || - GV.hasSection() || GV.hasImplicitSection() || - GV.hasDLLExportStorageClass()) + GV.hasSection() || GV.hasImplicitSection()) continue; // It's not safe to merge globals that may be preempted Index: test/CodeGen/ARM/global-merge-dllexport.ll =================================================================== --- test/CodeGen/ARM/global-merge-dllexport.ll +++ test/CodeGen/ARM/global-merge-dllexport.ll @@ -5,11 +5,17 @@ define void @f1(i32 %a1, i32 %a2) { ; CHECK: f1: -; CHECK: movw [[REG1:r[0-9]+]], :lower16:x -; CHECK: movt [[REG1]], :upper16:x +; CHECK: movw [[REG1:r[0-9]+]], :lower16:.L_MergedGlobals +; CHECK: movt [[REG1]], :upper16:.L_MergedGlobals store i32 %a1, i32* @x, align 4 store i32 %a2, i32* @y, align 4 ret void } -; CHECK-NOT: .L_MergedGlobals +; CHECK: .lcomm .L_MergedGlobals,8,4 +; CHECK: .globl x +; CHECK: x = .L_MergedGlobals +; CHECK: .globl y +; CHECK: y = .L_MergedGlobals+4 +; CHECK: .section .drectve,"yn" +; CHECK: .ascii " /EXPORT:y,DATA"