From 01b2fd3f9780752e359b631dde4d6e95d8d7ef8a Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 20 Jan 2015 05:58:07 +0000 Subject: [PATCH] Bitcode: Don't create comdats when autoupgrading macho bitcode Don't infer COMDAT groups from older bitcode if the target is macho, it doesn't have COMDATs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226546 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++++++++-- test/Bitcode/weak-macho-3.5.ll | 11 +++++++++++ test/Bitcode/weak-macho-3.5.ll.bc | Bin 0 -> 352 bytes 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/Bitcode/weak-macho-3.5.ll create mode 100644 test/Bitcode/weak-macho-3.5.ll.bc diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index f8625e1034f..9e27225df79 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -11,6 +11,7 @@ #include "BitcodeReader.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Triple.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/Constants.h" @@ -1106,6 +1107,8 @@ std::error_code BitcodeReader::ParseValueSymbolTable() { SmallVector Record; + Triple TT(TheModule->getTargetTriple()); + // Read all the records for this value table. SmallString<128> ValueName; while (1) { @@ -1137,8 +1140,12 @@ std::error_code BitcodeReader::ParseValueSymbolTable() { V->setName(StringRef(ValueName.data(), ValueName.size())); if (auto *GO = dyn_cast(V)) { - if (GO->getComdat() == reinterpret_cast(1)) - GO->setComdat(TheModule->getOrInsertComdat(V->getName())); + if (GO->getComdat() == reinterpret_cast(1)) { + if (TT.isOSBinFormatMachO()) + GO->setComdat(nullptr); + else + GO->setComdat(TheModule->getOrInsertComdat(V->getName())); + } } ValueName.clear(); break; diff --git a/test/Bitcode/weak-macho-3.5.ll b/test/Bitcode/weak-macho-3.5.ll new file mode 100644 index 00000000000..0c09fe4cd9d --- /dev/null +++ b/test/Bitcode/weak-macho-3.5.ll @@ -0,0 +1,11 @@ +; RUN: llvm-dis < %s.bc| FileCheck %s + +; weak-macho-3.5.ll.bc was generated by passing this file to llvm-as-3.5 +; The test checks that LLVM does not place weak GlobalVariables into Comdats for +; macho object files, they don't support it. + +target triple = "x86_64-apple-macosx10.9.0" +; CHECK: target triple = "x86_64-apple-macosx10.9.0" + +@x = weak global i32 0 +; CHECK: @x = weak global i32 0{{$}} diff --git a/test/Bitcode/weak-macho-3.5.ll.bc b/test/Bitcode/weak-macho-3.5.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..ee6607235774cd17b122672c2f8e53d8a286f268 GIT binary patch literal 352 zcmcb2K%AQa2tVT$@#!NMIHu*0H7FmlL7-1kQM@B_D1E2jwe_=*#wL% zCo#70sIqcM%CU4OHE_5xIZfhrauF~RvEY#KOCiN`GqCx{67wDfSdxcCTg6tg5aFfa%k z)f`~9{=sU!pxKOry`q7=OrzZ_qrE_)y?h3HO$W0@L94prAK=~ e0ee*eb6G`ufdVk>7z!1D0SKho1Y&?B0|NlQJy=8l literal 0 HcmV?d00001