Index: lib/Target/ARM/ARMTargetMachine.cpp =================================================================== --- lib/Target/ARM/ARMTargetMachine.cpp +++ lib/Target/ARM/ARMTargetMachine.cpp @@ -412,7 +412,10 @@ // expect it to be generally either beneficial or harmless. On Mach-O it // is disabled as we emit the .subsections_via_symbols directive which // means that merging extern globals is not safe. - bool MergeExternalByDefault = !TM->getTargetTriple().isOSBinFormatMachO(); + // Disable merging of extern globals for windows, since it would drop + // related dllexport attributes. + bool MergeExternalByDefault = !TM->getTargetTriple().isOSBinFormatMachO() && + !TM->getTargetTriple().isOSWindows(); addPass(createGlobalMergePass(TM, 127, OnlyOptimizeForSize, MergeExternalByDefault)); } Index: test/CodeGen/ARM/global-merge-external.ll =================================================================== --- test/CodeGen/ARM/global-merge-external.ll +++ test/CodeGen/ARM/global-merge-external.ll @@ -3,6 +3,7 @@ ; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -global-merge-on-external=false | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE ; RUN: llc < %s -mtriple=arm-macho -arm-global-merge | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE ; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -relocation-model=pic | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE +; RUN llc < %s -mtriple=thumbv7-win32 -arm-global-merge | FileCheck %s --check-prefix=CHECK-WIN32-NO-MERGE @x = global i32 0, align 4 @y = global i32 0, align 4 @@ -14,6 +15,9 @@ ;CHECK: [[LABEL1]]: ;CHECK-MERGE: .long .L_MergedGlobals ;CHECK-NO-MERGE: .long {{_?x}} +;CHECK-WIN32-NO-MERGE: f1: +;CHECK-WIN32-NO-MERGE: movw: [[REG1:r[0-9]+]], :lower16:x +;CHECK-WIN32-NO-MERGE: movt: [[REG1]], :upper16:x store i32 %a1, i32* @x, align 4 store i32 %a2, i32* @y, align 4 ret void @@ -25,6 +29,9 @@ ;CHECK: [[LABEL2]]: ;CHECK-MERGE: .long .L_MergedGlobals ;CHECK-NO-MERGE: .long {{_?y}} +;CHECK-WIN32-NO-MERGE: g1: +;CHECK-WIN32-NO-MERGE: movw: [[REG2:r[0-9]+]], :lower16:y +;CHECK-WIN32-NO-MERGE: movt: [[REG2]], :upper16:y store i32 %a1, i32* @y, align 4 store i32 %a2, i32* @z, align 4 ret void