[patch] Don't use appending linkage for embeded bitcode

Rafael EspĂ­ndola via cfe-commits cfe-commits at lists.llvm.org
Fri May 13 09:46:16 PDT 2016


Hi Steven,

I think there was a mistake when picking this linkage. The appending
linkage is really just for things that llvm itself special cases. By
an historical artifact it was codegened just like external.

The attached patch changes it to external linkage. I tested that the
produced .o file is bit by bit identical with this change.

But I have to ask, what is the intended use? I was under the
impression that the idea was to allow multiple .o files to have their
IR embedded and have the liker concatenate them.

Currently, with or without this patch, I expect you to get a
duplicated symbol error. To implement the above the symbol should be
internal end the GV added to llvm.used.

Cheers,
Rafael
-------------- next part --------------
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp
index bffa621..4f0a3ca 100644
--- a/lib/CodeGen/BackendUtil.cpp
+++ b/lib/CodeGen/BackendUtil.cpp
@@ -820,9 +820,8 @@ void clang::EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
   }
   llvm::Constant *ModuleConstant =
       llvm::ConstantDataArray::get(M->getContext(), ModuleData);
-  // Use Appending linkage so it doesn't get optimized out.
   llvm::GlobalVariable *GV = new llvm::GlobalVariable(
-      *M, ModuleConstant->getType(), true, llvm::GlobalValue::AppendingLinkage,
+      *M, ModuleConstant->getType(), true, llvm::GlobalValue::ExternalLinkage,
       ModuleConstant);
   GV->setSection(getSectionNameForBitcode(T));
   if (llvm::GlobalVariable *Old =


More information about the cfe-commits mailing list