Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1319,8 +1319,13 @@ // Append "$symbol" to the section name when targetting mingw. The ld.bfd // COFF linker will not properly handle comdats otherwise. - if (getTargetTriple().isWindowsGNUEnvironment()) - raw_svector_ostream(Name) << '$' << COMDATSymName; + if (getTargetTriple().isWindowsGNUEnvironment()) { + if (getTargetTriple().isArch32Bit()) { + raw_svector_ostream(Name) << '$' << GO->getComdat()->getName(); + } else { + raw_svector_ostream(Name) << '$' << COMDATSymName; + } + } return getContext().getCOFFSection(Name, Characteristics, Kind, COMDATSymName, Selection, UniqueID); Index: llvm/test/CodeGen/X86/mingw-comdats.ll =================================================================== --- llvm/test/CodeGen/X86/mingw-comdats.ll +++ llvm/test/CodeGen/X86/mingw-comdats.ll @@ -50,9 +50,9 @@ ; GNU: gv: ; GNU: .long 42 -; GNU32: .section .text$__Z3fooi,"xr",discard,__Z3fooi +; GNU32: .section .text$_Z3fooi,"xr",discard,__Z3fooi ; GNU32: __Z3fooi: -; GNU32: .section .data$_gv,"dw",discard,_gv +; GNU32: .section .data$gv,"dw",discard,_gv ; GNU32: _gv: ; GNU32: .long 42