From 3acfb58b178d25b0671cbfb4fb20194e62b01a98 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 4 Sep 2013 14:05:09 +0000 Subject: Fix linking of unnamed_addr. This was regression from r134829. When linking we have to be conservative. If one of the symbols has a significant address, then the result should have it too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189935 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index f322112..ab37b8b 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -746,6 +746,7 @@ bool ModuleLinker::linkAppendingVarProto(GlobalVariable *DstGV, bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { GlobalValue *DGV = getLinkedToGlobal(SGV); llvm::Optional NewVisibility; + bool HasUnnamedAddr = SGV->hasUnnamedAddr(); if (DGV) { // Concatenation of appending linkage variables is magic and handled later. @@ -755,6 +756,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { // Determine whether linkage of these two globals follows the source // module's definition or the destination module's definition. GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage; + HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); GlobalValue::VisibilityTypes NV; bool LinkFromSrc = false; if (getLinkageResult(DGV, SGV, NewLinkage, NV, LinkFromSrc)) @@ -768,10 +770,11 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { if (GlobalVariable *DGVar = dyn_cast(DGV)) if (DGVar->isDeclaration() && SGV->isConstant() && !DGVar->isConstant()) DGVar->setConstant(true); - - // Set calculated linkage and visibility. + + // Set calculated linkage, visibility and unnamed_addr. DGV->setLinkage(NewLinkage); DGV->setVisibility(*NewVisibility); + DGV->setUnnamedAddr(HasUnnamedAddr); // Make sure to remember this mapping. ValueMap[SGV] = ConstantExpr::getBitCast(DGV,TypeMap.get(SGV->getType())); @@ -797,6 +800,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { copyGVAttributes(NewDGV, SGV); if (NewVisibility) NewDGV->setVisibility(*NewVisibility); + NewDGV->setUnnamedAddr(HasUnnamedAddr); if (DGV) { DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV, DGV->getType())); -- cgit v1.1 From 6947f10ec467eb89d606bc96450c35864e1b4f10 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 4 Sep 2013 14:59:03 +0000 Subject: Fix linking of unnamed_addr in functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189945 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index ab37b8b..16e2851 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -756,12 +756,12 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { // Determine whether linkage of these two globals follows the source // module's definition or the destination module's definition. GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage; - HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); GlobalValue::VisibilityTypes NV; bool LinkFromSrc = false; if (getLinkageResult(DGV, SGV, NewLinkage, NV, LinkFromSrc)) return true; NewVisibility = NV; + HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); // If we're not linking from the source, then keep the definition that we // have. @@ -817,6 +817,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { bool ModuleLinker::linkFunctionProto(Function *SF) { GlobalValue *DGV = getLinkedToGlobal(SF); llvm::Optional NewVisibility; + bool HasUnnamedAddr = SF->hasUnnamedAddr(); if (DGV) { GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage; @@ -825,11 +826,13 @@ bool ModuleLinker::linkFunctionProto(Function *SF) { if (getLinkageResult(DGV, SF, NewLinkage, NV, LinkFromSrc)) return true; NewVisibility = NV; + HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); if (!LinkFromSrc) { // Set calculated linkage DGV->setLinkage(NewLinkage); DGV->setVisibility(*NewVisibility); + DGV->setUnnamedAddr(HasUnnamedAddr); // Make sure to remember this mapping. ValueMap[SF] = ConstantExpr::getBitCast(DGV, TypeMap.get(SF->getType())); @@ -857,6 +860,7 @@ bool ModuleLinker::linkFunctionProto(Function *SF) { copyGVAttributes(NewDF, SF); if (NewVisibility) NewDF->setVisibility(*NewVisibility); + NewDF->setUnnamedAddr(HasUnnamedAddr); if (DGV) { // Any uses of DF need to change to NewDF, with cast. -- cgit v1.1 From 9127334dade7fa36cb5cb999fc116ceaa4f52ac9 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 4 Sep 2013 15:33:34 +0000 Subject: Error on linking appending globals with different unnamed_addr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189950 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 16e2851..4fffa55 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -704,7 +704,11 @@ bool ModuleLinker::linkAppendingVarProto(GlobalVariable *DstGV, if (DstGV->getVisibility() != SrcGV->getVisibility()) return emitError( "Appending variables with different visibility need to be linked!"); - + + if (DstGV->hasUnnamedAddr() != SrcGV->hasUnnamedAddr()) + return emitError( + "Appending variables with different unnamed_addr need to be linked!"); + if (DstGV->getSection() != SrcGV->getSection()) return emitError( "Appending variables with different section name need to be linked!"); -- cgit v1.1 From 1e3037f0be430ef2339838bbdede11f45658bd82 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 16 Sep 2013 01:08:15 +0000 Subject: Implement function prefix data as an IR feature. Previous discussion: http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-July/063909.html Differential Revision: http://llvm-reviews.chandlerc.com/D1191 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190773 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 4fffa55..c3bcbcf 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1260,6 +1260,13 @@ bool ModuleLinker::run() { // Skip if not linking from source. if (DoNotLinkFromSource.count(SF)) continue; + Function *DF = cast(ValueMap[SF]); + if (SF->hasPrefixData()) { + // Link in the prefix data. + DF->setPrefixData(MapValue( + SF->getPrefixData(), ValueMap, RF_None, &TypeMap, &ValMaterializer)); + } + // Skip if no body (function is external) or materialize. if (SF->isDeclaration()) { if (!SF->isMaterializable()) @@ -1268,7 +1275,7 @@ bool ModuleLinker::run() { return true; } - linkFunctionBody(cast(ValueMap[SF]), SF); + linkFunctionBody(DF, SF); SF->Dematerialize(); } @@ -1296,6 +1303,14 @@ bool ModuleLinker::run() { continue; Function *DF = cast(ValueMap[SF]); + if (SF->hasPrefixData()) { + // Link in the prefix data. + DF->setPrefixData(MapValue(SF->getPrefixData(), + ValueMap, + RF_None, + &TypeMap, + &ValMaterializer)); + } // Materialize if necessary. if (SF->isDeclaration()) { -- cgit v1.1 From e3ba15c794839abe076e3e2bdf6c626396a19d4d Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Sat, 12 Oct 2013 00:55:57 +0000 Subject: Add missing #include's to cctype when using isdigit/alpha/etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192519 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index c3bcbcf..b343b1c 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/Cloning.h" +#include using namespace llvm; //===----------------------------------------------------------------------===// -- cgit v1.1 From b4a0ba17183e1b4aa385e81e896c2a95671a40b2 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 16 Oct 2013 08:59:57 +0000 Subject: Add a 'deleteModule' method to the Linker class. This deletes the Module ivar instead of having the LTO code generater do it. It also sets the pointer to 'NULL', so that if it's used again it will abort quickly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192778 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index b343b1c..8f2200e 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1352,6 +1352,11 @@ Linker::Linker(Module *M) : Composite(M) { Linker::~Linker() { } +void Linker::deleteModule() { + delete Composite; + Composite = NULL; +} + bool Linker::linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg) { ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, Mode); if (TheLinker.run()) { -- cgit v1.1 From 5d5f2c37d57276c9320dd2677d355d47fa4bc5c4 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 7 Nov 2013 20:14:51 +0000 Subject: Move copying of global initializers below the cloning of functions. The BlockAddress doesn't have access to the correct basic blocks until the functions have been cloned. This causes the BlockAddress to point to the old values. Just wait until the functions have been cloned before copying the initializers. PR13163 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194218 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 8f2200e..00c2ed1 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1251,10 +1251,6 @@ bool ModuleLinker::run() { for (unsigned i = 0, e = AppendingVars.size(); i != e; ++i) linkAppendingVarInit(AppendingVars[i]); - // Update the initializers in the DstM module now that all globals that may - // be referenced are in DstM. - linkGlobalInits(); - // Link in the function bodies that are defined in the source module into // DstM. for (Module::iterator SF = SrcM->begin(), E = SrcM->end(); SF != E; ++SF) { @@ -1336,6 +1332,10 @@ bool ModuleLinker::run() { } } while (LinkedInAnyFunctions); + // Update the initializers in the DstM module now that all globals that may + // be referenced are in DstM. + linkGlobalInits(); + // Now that all of the types from the source are used, resolve any structs // copied over to the dest that didn't exist there. TypeMap.linkDefinedTypeBodies(); -- cgit v1.1 From 999ffb6085a6e24261680b41d4f43ad4ba8fd250 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Sat, 9 Nov 2013 00:43:18 +0000 Subject: Revert "Move copying of global initializers below the cloning of functions." This would cause internal symbols that are only referenced by global initializers to be removed. This reverts commit 194219. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194304 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/Linker') diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 00c2ed1..8f2200e 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1251,6 +1251,10 @@ bool ModuleLinker::run() { for (unsigned i = 0, e = AppendingVars.size(); i != e; ++i) linkAppendingVarInit(AppendingVars[i]); + // Update the initializers in the DstM module now that all globals that may + // be referenced are in DstM. + linkGlobalInits(); + // Link in the function bodies that are defined in the source module into // DstM. for (Module::iterator SF = SrcM->begin(), E = SrcM->end(); SF != E; ++SF) { @@ -1332,10 +1336,6 @@ bool ModuleLinker::run() { } } while (LinkedInAnyFunctions); - // Update the initializers in the DstM module now that all globals that may - // be referenced are in DstM. - linkGlobalInits(); - // Now that all of the types from the source are used, resolve any structs // copied over to the dest that didn't exist there. TypeMap.linkDefinedTypeBodies(); -- cgit v1.1