1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Add the private linkage.

llvm-svn: 62279
This commit is contained in:
Rafael Espindola 2009-01-15 20:18:42 +00:00
parent 97d45c48c5
commit 0aba6c9435
72 changed files with 401 additions and 145 deletions

View File

@ -480,13 +480,20 @@ All Global Variables and Functions have one of the following types of linkage:
<dl>
<dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
<dd>Global values with private linkage are only directly accessible by
objects in the current module. In particular, linking code into a module with
an private global value may cause the private to be renamed as necessary to
avoid collisions. Because the symbol is private to the module, all
references can be updated. This doesn't show up in any symbol table in the
object file.
</dd>
<dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
<dd>Global values with internal linkage are only directly accessible by
objects in the current module. In particular, linking code into a module with
an internal global value may cause the internal to be renamed as necessary to
avoid collisions. Because the symbol is internal to the module, all
references can be updated. This corresponds to the notion of the
<dd> Similar to private, but the value show as a local symbol (STB_LOCAL in
the case of ELF) in the object file. This corresponds to the notion of the
'<tt>static</tt>' keyword in C.
</dd>

View File

@ -35,6 +35,7 @@ public:
WeakLinkage, ///< Keep one copy of named function when linking (weak)
AppendingLinkage, ///< Special purpose, only applies to global arrays
InternalLinkage, ///< Rename collisions when linking (static functions)
PrivateLinkage, ///< Like Internal, but omit from symbol table
DLLImportLinkage, ///< Function to be imported from DLL
DLLExportLinkage, ///< Function to be accessible from DLL
ExternalWeakLinkage,///< ExternalWeak linkage description
@ -104,6 +105,10 @@ public:
bool hasCommonLinkage() const { return Linkage == CommonLinkage; }
bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
bool hasPrivateLinkage() const { return Linkage == PrivateLinkage; }
bool hasLocalLinkage() const {
return Linkage == InternalLinkage || Linkage == PrivateLinkage;
}
bool hasDLLImportLinkage() const { return Linkage == DLLImportLinkage; }
bool hasDLLExportLinkage() const { return Linkage == DLLExportLinkage; }
bool hasExternalWeakLinkage() const { return Linkage == ExternalWeakLinkage; }

View File

@ -188,7 +188,7 @@ public:
/// getOrInsertFunction - Look up the specified function in the module symbol
/// table. Four possibilities:
/// 1. If it does not exist, add a prototype for the function and return it.
/// 2. If it exists, and has internal linkage, the existing function is
/// 2. If it exists, and has a local linkage, the existing function is
/// renamed and a new one is inserted.
/// 3. Otherwise, if the existing function has the correct prototype, return
/// the existing function.

View File

@ -29,6 +29,7 @@ class Mangler {
/// symbol is marked as not needing this prefix.
const char *Prefix;
const char *PrivatePrefix;
/// UseQuotes - If this is set, the target accepts global names in quotes,
/// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
/// the space character. By default, this is false.
@ -58,7 +59,7 @@ public:
// Mangler ctor - if a prefix is specified, it will be prepended onto all
// symbols.
Mangler(Module &M, const char *Prefix = "");
Mangler(Module &M, const char *Prefix = "", const char *privatePrefix = "");
/// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
/// strings for assembler labels.

View File

@ -1084,7 +1084,7 @@ void Andersens::CollectConstraints(Module &M) {
// At some point we should just add constraints for the escaping functions
// at solve time, but this slows down solving. For now, we simply mark
// address taken functions as escaping and treat them as external.
if (!F->hasInternalLinkage() || AnalyzeUsesOfFunction(F))
if (!F->hasLocalLinkage() || AnalyzeUsesOfFunction(F))
AddConstraintsForNonInternalLinkage(F);
if (!F->isDeclaration()) {

View File

@ -112,7 +112,7 @@ private:
CallGraphNode *Node = getOrInsertFunction(F);
// If this function has external linkage, anything could call it.
if (!F->hasInternalLinkage()) {
if (!F->hasLocalLinkage()) {
ExternalCallingNode->addCalledFunction(CallSite(), Node);
// Found the entry point?

View File

@ -164,7 +164,7 @@ Pass *llvm::createGlobalsModRefPass() { return new GlobalsModRef(); }
void GlobalsModRef::AnalyzeGlobals(Module &M) {
std::vector<Function*> Readers, Writers;
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (I->hasInternalLinkage()) {
if (I->hasLocalLinkage()) {
if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
// Remember that we are tracking this global.
NonAddressTakenGlobals.insert(I);
@ -175,7 +175,7 @@ void GlobalsModRef::AnalyzeGlobals(Module &M) {
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
if (I->hasInternalLinkage()) {
if (I->hasLocalLinkage()) {
if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
// Remember that we are tracking this global, and the mod/ref fns
NonAddressTakenGlobals.insert(I);
@ -504,7 +504,7 @@ GlobalsModRef::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
// If we are asking for mod/ref info of a direct call with a pointer to a
// global we are tracking, return information if we have it.
if (GlobalValue *GV = dyn_cast<GlobalValue>(P->getUnderlyingObject()))
if (GV->hasInternalLinkage())
if (GV->hasLocalLinkage())
if (Function *F = CS.getCalledFunction())
if (NonAddressTakenGlobals.count(GV))
if (FunctionRecord *FR = getFunctionInfo(F))

View File

@ -188,13 +188,13 @@ Archive::~Archive() {
static void getSymbols(Module*M, std::vector<std::string>& symbols) {
// Loop over global variables
for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
if (!GI->isDeclaration() && !GI->hasInternalLinkage())
if (!GI->isDeclaration() && !GI->hasLocalLinkage())
if (!GI->getName().empty())
symbols.push_back(GI->getName());
// Loop over functions
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
if (!FI->isDeclaration() && !FI->hasInternalLinkage())
if (!FI->isDeclaration() && !FI->hasLocalLinkage())
if (!FI->getName().empty())
symbols.push_back(FI->getName());

View File

@ -453,6 +453,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(declare); KEYWORD(define);
KEYWORD(global); KEYWORD(constant);
KEYWORD(private);
KEYWORD(internal);
KEYWORD(linkonce);
KEYWORD(weak);

View File

@ -113,6 +113,7 @@ bool LLParser::ParseTopLevelEntities() {
// optional leading prefixes, the production is:
// GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
// OptionalAddrSpace ('constant'|'global') ...
case lltok::kw_private: // OptionalLinkage
case lltok::kw_internal: // OptionalLinkage
case lltok::kw_weak: // OptionalLinkage
case lltok::kw_linkonce: // OptionalLinkage
@ -375,7 +376,8 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
if (Linkage != GlobalValue::ExternalLinkage &&
Linkage != GlobalValue::WeakLinkage &&
Linkage != GlobalValue::InternalLinkage)
Linkage != GlobalValue::InternalLinkage &&
Linkage != GlobalValue::PrivateLinkage)
return Error(LinkageLoc, "invalid linkage type for alias");
Constant *Aliasee;
@ -738,6 +740,7 @@ bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) {
/// ParseOptionalLinkage
/// ::= /*empty*/
/// ::= 'private'
/// ::= 'internal'
/// ::= 'weak'
/// ::= 'linkonce'
@ -751,6 +754,7 @@ bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
HasLinkage = false;
switch (Lex.getKind()) {
default: Res = GlobalValue::ExternalLinkage; return false;
case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
case lltok::kw_weak: Res = GlobalValue::WeakLinkage; break;
case lltok::kw_linkonce: Res = GlobalValue::LinkOnceLinkage; break;
@ -2065,6 +2069,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
if (isDefine)
return Error(LinkageLoc, "invalid linkage for function definition");
break;
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
case GlobalValue::LinkOnceLinkage:
case GlobalValue::WeakLinkage:

View File

@ -36,7 +36,7 @@ namespace lltok {
kw_declare, kw_define,
kw_global, kw_constant,
kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
kw_private, kw_internal, kw_linkonce, kw_weak, kw_appending, kw_dllimport,
kw_dllexport, kw_common, kw_default, kw_hidden, kw_protected,
kw_extern_weak,
kw_external, kw_thread_local,

View File

@ -67,6 +67,7 @@ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) {
case 6: return GlobalValue::DLLExportLinkage;
case 7: return GlobalValue::ExternalWeakLinkage;
case 8: return GlobalValue::CommonLinkage;
case 9: return GlobalValue::PrivateLinkage;
}
}

View File

@ -284,6 +284,7 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
case GlobalValue::DLLExportLinkage: return 6;
case GlobalValue::ExternalWeakLinkage: return 7;
case GlobalValue::CommonLinkage: return 8;
case GlobalValue::PrivateLinkage: return 9;
}
}

View File

@ -139,7 +139,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
}
bool AsmPrinter::doInitialization(Module &M) {
Mang = new Mangler(M, TAI->getGlobalPrefix());
Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix());
GCModuleInfo *MI = getAnalysisToUpdate<GCModuleInfo>();
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
@ -199,7 +199,7 @@ bool AsmPrinter::doFinalization(Module &M) {
O << "\t.globl\t" << Name << '\n';
else if (I->hasWeakLinkage())
O << TAI->getWeakRefDirective() << Name << '\n';
else if (!I->hasInternalLinkage())
else if (!I->hasLocalLinkage())
assert(0 && "Invalid alias linkage");
printVisibility(Name, I->getVisibility());

View File

@ -3272,7 +3272,8 @@ private:
// Externally visible entry into the functions eh frame info.
// If the corresponding function is static, this should not be
// externally visible.
if (linkage != Function::InternalLinkage) {
if (linkage != Function::InternalLinkage &&
linkage != Function::PrivateLinkage) {
if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
}

View File

@ -174,6 +174,8 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) {
case GlobalValue::WeakLinkage:
FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK);
break;
case GlobalValue::PrivateLinkage:
assert (0 && "PrivateLinkage should not be in the symbol table.");
case GlobalValue::InternalLinkage:
FnSym.SetBind(ELFWriter::ELFSym::STB_LOCAL);
break;
@ -329,6 +331,7 @@ void ELFWriter::EmitGlobal(GlobalVariable *GV) {
// Set the idx of the .bss section
BSSSym.SectionIdx = BSSSection.SectionIdx;
if (!GV->hasPrivateLinkage())
SymbolTable.push_back(BSSSym);
// Reserve space in the .bss section for this symbol.

View File

@ -371,7 +371,7 @@ void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) {
SecDataOut.outbyte(0);
}
// Globals without external linkage apparently do not go in the symbol table.
if (GV->getLinkage() != GlobalValue::InternalLinkage) {
if (!GV->hasLocalLinkage()) {
MachOSym Sym(GV, Mang->getValueName(GV), Sec->Index, TM);
Sym.n_value = Sec->size;
SymbolTable.push_back(Sym);
@ -959,6 +959,9 @@ MachOSym::MachOSym(const GlobalValue *gv, std::string name, uint8_t sect,
GVName = TAI->getGlobalPrefix() + name;
n_type |= GV->hasHiddenVisibility() ? N_PEXT : N_EXT;
break;
case GlobalValue::PrivateLinkage:
GVName = TAI->getPrivateGlobalPrefix() + name;
break;
case GlobalValue::InternalLinkage:
GVName = TAI->getGlobalPrefix() + name;
break;

View File

@ -4276,7 +4276,7 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
// Check for well-known libc/libm calls. If the function is internal, it
// can't be a library call.
unsigned NameLen = F->getNameLen();
if (!F->hasInternalLinkage() && NameLen) {
if (!F->hasLocalLinkage() && NameLen) {
const char *NameStr = F->getNameStart();
if (NameStr[0] == 'c' &&
((NameLen == 8 && !strcmp(NameStr, "copysign")) ||

View File

@ -249,7 +249,7 @@ void ExecutionEngine::runStaticConstructorsDestructors(Module *module, bool isDt
// an old-style (llvmgcc3) static ctor with __main linked in and in use. If
// this is the case, don't execute any of the global ctors, __main will do
// it.
if (!GV || GV->isDeclaration() || GV->hasInternalLinkage()) return;
if (!GV || GV->isDeclaration() || GV->hasLocalLinkage()) return;
// Should be an array of '{ int, void ()* }' structs. The first value is
// the init priority, which we ignore.
@ -893,7 +893,7 @@ void ExecutionEngine::emitGlobals() {
for (Module::const_global_iterator I = M.global_begin(),
E = M.global_end(); I != E; ++I) {
const GlobalValue *GV = I;
if (GV->hasInternalLinkage() || GV->isDeclaration() ||
if (GV->hasLocalLinkage() || GV->isDeclaration() ||
GV->hasAppendingLinkage() || !GV->hasName())
continue;// Ignore external globals and globals with internal linkage.

View File

@ -554,7 +554,7 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
addGlobalMapping(GV, Ptr);
}
} else {
if (isGVCompilationDisabled() && !GV->hasInternalLinkage()) {
if (isGVCompilationDisabled() && !GV->hasLocalLinkage()) {
cerr << "Compilation of non-internal GlobalValue is disabled!\n";
abort();
}

View File

@ -50,7 +50,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
if (I->hasName()) {
if (I->isDeclaration())
UndefinedSymbols.insert(I->getName());
else if (!I->hasInternalLinkage()) {
else if (!I->hasLocalLinkage()) {
assert(!I->hasDLLImportLinkage()
&& "Found dllimported non-external symbol!");
DefinedSymbols.insert(I->getName());
@ -62,7 +62,7 @@ GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
if (I->hasName()) {
if (I->isDeclaration())
UndefinedSymbols.insert(I->getName());
else if (!I->hasInternalLinkage()) {
else if (!I->hasLocalLinkage()) {
assert(!I->hasDLLImportLinkage()
&& "Found dllimported non-external symbol!");
DefinedSymbols.insert(I->getName());

View File

@ -415,7 +415,7 @@ static void ForceRenaming(GlobalValue *GV, const std::string &Name) {
// If there is a conflict, rename the conflict.
if (GlobalValue *ConflictGV = cast_or_null<GlobalValue>(ST.lookup(Name))) {
assert(ConflictGV->hasInternalLinkage() &&
assert(ConflictGV->hasLocalLinkage() &&
"Not conflicting with a static global, should link instead!");
GV->takeName(ConflictGV);
ConflictGV->setName(Name); // This will cause ConflictGV to get renamed
@ -444,7 +444,7 @@ static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
static bool GetLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
GlobalValue::LinkageTypes &LT, bool &LinkFromSrc,
std::string *Err) {
assert((!Dest || !Src->hasInternalLinkage()) &&
assert((!Dest || !Src->hasLocalLinkage()) &&
"If Src has internal linkage, Dest shouldn't be set!");
if (!Dest) {
// Linking something to nothing.
@ -536,13 +536,13 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// Check to see if may have to link the global with the global, alias or
// function.
if (SGV->hasName() && !SGV->hasInternalLinkage())
if (SGV->hasName() && !SGV->hasLocalLinkage())
DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getNameStart(),
SGV->getNameEnd()));
// If we found a global with the same name in the dest module, but it has
// internal linkage, we are really not doing any linkage here.
if (DGV && DGV->hasInternalLinkage())
if (DGV && DGV->hasLocalLinkage())
DGV = 0;
// If types don't agree due to opaque types, try to resolve them.
@ -573,7 +573,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// If the LLVM runtime renamed the global, but it is an externally visible
// symbol, DGV must be an existing global with internal linkage. Rename
// it.
if (!NewDGV->hasInternalLinkage() && NewDGV->getName() != SGV->getName())
if (!NewDGV->hasLocalLinkage() && NewDGV->getName() != SGV->getName())
ForceRenaming(NewDGV, SGV->getName());
// Make sure to remember this mapping.
@ -643,7 +643,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
// If the symbol table renamed the global, but it is an externally visible
// symbol, DGV must be an existing global with internal linkage. Rename.
if (NewDGV->getName() != SGV->getName() && !NewDGV->hasInternalLinkage())
if (NewDGV->getName() != SGV->getName() && !NewDGV->hasLocalLinkage())
ForceRenaming(NewDGV, SGV->getName());
// Inherit const as appropriate.
@ -687,10 +687,12 @@ CalculateAliasLinkage(const GlobalValue *SGV, const GlobalValue *DGV) {
return GlobalValue::ExternalLinkage;
else if (SGV->hasWeakLinkage() || DGV->hasWeakLinkage())
return GlobalValue::WeakLinkage;
else {
assert(SGV->hasInternalLinkage() && DGV->hasInternalLinkage() &&
"Unexpected linkage type");
else if (SGV->hasInternalLinkage() && DGV->hasInternalLinkage())
return GlobalValue::InternalLinkage;
else {
assert (SGV->hasPrivateLinkage() && DGV->hasPrivateLinkage() &&
"Unexpected linkage type");
return GlobalValue::PrivateLinkage;
}
}
@ -715,7 +717,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
GlobalValue* DGV = NULL;
// Try to find something 'similar' to SGA in destination module.
if (!DGV && !SGA->hasInternalLinkage()) {
if (!DGV && !SGA->hasLocalLinkage()) {
DGV = Dest->getNamedAlias(SGA->getName());
// If types don't agree due to opaque types, try to resolve them.
@ -723,7 +725,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
RecursiveResolveTypes(SGA->getType(), DGV->getType());
}
if (!DGV && !SGA->hasInternalLinkage()) {
if (!DGV && !SGA->hasLocalLinkage()) {
DGV = Dest->getGlobalVariable(SGA->getName());
// If types don't agree due to opaque types, try to resolve them.
@ -731,7 +733,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
RecursiveResolveTypes(SGA->getType(), DGV->getType());
}
if (!DGV && !SGA->hasInternalLinkage()) {
if (!DGV && !SGA->hasLocalLinkage()) {
DGV = Dest->getFunction(SGA->getName());
// If types don't agree due to opaque types, try to resolve them.
@ -740,7 +742,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
}
// No linking to be performed on internal stuff.
if (DGV && DGV->hasInternalLinkage())
if (DGV && DGV->hasLocalLinkage())
DGV = NULL;
if (GlobalAlias *DGA = dyn_cast_or_null<GlobalAlias>(DGV)) {
@ -831,7 +833,7 @@ static bool LinkAlias(Module *Dest, const Module *Src,
// If the symbol table renamed the alias, but it is an externally visible
// symbol, DGA must be an global value with internal linkage. Rename it.
if (NewGA->getName() != SGA->getName() &&
!NewGA->hasInternalLinkage())
!NewGA->hasLocalLinkage())
ForceRenaming(NewGA, SGA->getName());
// Remember this mapping so uses in the source module get remapped
@ -912,13 +914,13 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to see if may have to link the function with the global, alias or
// function.
if (SF->hasName() && !SF->hasInternalLinkage())
if (SF->hasName() && !SF->hasLocalLinkage())
DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getNameStart(),
SF->getNameEnd()));
// If we found a global with the same name in the dest module, but it has
// internal linkage, we are really not doing any linkage here.
if (DGV && DGV->hasInternalLinkage())
if (DGV && DGV->hasLocalLinkage())
DGV = 0;
// If types don't agree due to opaque types, try to resolve them.
@ -943,7 +945,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// If the LLVM runtime renamed the function, but it is an externally
// visible symbol, DF must be an existing function with internal linkage.
// Rename it.
if (!NewDF->hasInternalLinkage() && NewDF->getName() != SF->getName())
if (!NewDF->hasLocalLinkage() && NewDF->getName() != SF->getName())
ForceRenaming(NewDF, SF->getName());
// ... and remember this mapping...
@ -982,7 +984,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// If the symbol table renamed the function, but it is an externally
// visible symbol, DF must be an existing function with internal
// linkage. Rename it.
if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage())
if (NewDF->getName() != SF->getName() && !NewDF->hasLocalLinkage())
ForceRenaming(NewDF, SF->getName());
// Remember this mapping so uses in the source module get remapped

View File

@ -808,7 +808,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
Reloc::Model RelocM = getTargetMachine().getRelocationModel();
if (RelocM == Reloc::PIC_) {
bool UseGOTOFF = GV->hasInternalLinkage() || GV->hasHiddenVisibility();
bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
ARMConstantPoolValue *CPV =
new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT");
SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2);

View File

@ -197,6 +197,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
const Function *F = MF.getFunction();
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::PrivateLinkage:
case Function::InternalLinkage:
SwitchToTextSection("\t.text", F);
break;
@ -847,11 +848,11 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
}
if (GVar->hasInternalLinkage() || GVar->mayBeOverridden()) {
if (GVar->hasLocalLinkage() || GVar->mayBeOverridden()) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (isDarwin) {
if (GVar->hasInternalLinkage()) {
if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << "," << Size
<< ',' << Align;
} else if (GVar->hasCommonLinkage()) {
@ -869,7 +870,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
return;
}
} else if (TAI->getLCOMMDirective() != NULL) {
if (GVar->hasInternalLinkage()) {
if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << "," << Size;
} else {
O << TAI->getCOMMDirective() << name << "," << Size;
@ -878,7 +879,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
} else {
SwitchToSection(TAI->SectionForGlobal(GVar));
if (GVar->hasInternalLinkage())
if (GVar->hasLocalLinkage())
O << "\t.local\t" << name << "\n";
O << TAI->getCOMMDirective() << name << "," << Size;
if (TAI->getCOMMDirectiveTakesAlignment())
@ -909,6 +910,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
case GlobalValue::ExternalLinkage:
O << "\t.globl " << name << "\n";
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
break;
default:

View File

@ -513,7 +513,7 @@ SDValue AlphaTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
// if (!GV->hasWeakLinkage() && !GV->isDeclaration() && !GV->hasLinkOnceLinkage()) {
if (GV->hasInternalLinkage()) {
if (GV->hasLocalLinkage()) {
SDValue Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, GA,
DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, MVT::i64));
SDValue Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);

View File

@ -169,6 +169,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
O << "\t.ent " << CurrentFnName << "\n";
assert (!F->hasPrivateLinkage() && "add private prefix.");
O << CurrentFnName << ":\n";
// Print out code for the function.

View File

@ -1910,7 +1910,7 @@ bool CWriter::doInitialization(Module &M) {
if (getGlobalVariableClass(I))
continue;
if (I->hasInternalLinkage())
if (I->hasLocalLinkage())
Out << "static ";
else
Out << "extern ";
@ -1946,7 +1946,7 @@ bool CWriter::doInitialization(Module &M) {
if (getGlobalVariableClass(I))
continue;
if (I->hasInternalLinkage())
if (I->hasLocalLinkage())
Out << "static ";
else if (I->hasDLLImportLinkage())
Out << "__declspec(dllimport) ";
@ -2190,7 +2190,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
/// isStructReturn - Should this function actually return a struct by-value?
bool isStructReturn = F->hasStructRetAttr();
if (F->hasInternalLinkage()) Out << "static ";
if (F->hasLocalLinkage()) Out << "static ";
if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";
switch (F->getCallingConv()) {

View File

@ -442,6 +442,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::PrivateLinkage:
case Function::InternalLinkage: // Symbols default to internal.
break;
case Function::ExternalLinkage:
@ -536,7 +537,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
(GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
(GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
@ -545,7 +546,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
O << "\t.type " << name << ", @object\n";
O << name << ":\n";
O << "\t.zero " << Size << '\n';
} else if (GVar->hasInternalLinkage()) {
} else if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << ',' << Size;
} else {
O << ".comm " << name << ',' << Size;
@ -573,6 +574,7 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
O << "\t.global " << name << '\n'
<< "\t.type " << name << ", @object\n";
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
break;
default:
@ -617,4 +619,3 @@ FunctionPass *llvm::createSPUAsmPrinterPass(raw_ostream &o,
SPUTargetMachine &tm) {
return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
}

View File

@ -292,6 +292,8 @@ namespace {
switch (LT) {
case GlobalValue::InternalLinkage:
Out << "GlobalValue::InternalLinkage"; break;
case GlobalValue::PrivateLinkage:
Out << "GlobalValue::PrivateLinkage"; break;
case GlobalValue::LinkOnceLinkage:
Out << "GlobalValue::LinkOnceLinkage "; break;
case GlobalValue::WeakLinkage:

View File

@ -61,7 +61,7 @@ DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
Mangler *Mang) const {
if (GV==0)
return false;
if (GV->hasInternalLinkage() && !isa<Function>(GV) &&
if (GV->hasLocalLinkage() && !isa<Function>(GV) &&
((strlen(getPrivateGlobalPrefix()) != 0 &&
Mang->getValueName(GV).substr(0,strlen(getPrivateGlobalPrefix())) ==
getPrivateGlobalPrefix()) ||

View File

@ -44,6 +44,7 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
if (const Function *F = dyn_cast<Function>(GV)) {
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::PrivateLinkage:
case Function::InternalLinkage:
case Function::DLLExportLinkage:
case Function::ExternalLinkage:
@ -184,4 +185,3 @@ std::string ELFTargetAsmInfo::printSectionFlags(unsigned flags) const {
return Flags;
}

View File

@ -275,10 +275,10 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && !GVar->hasSection()) {
if (!GVar->isThreadLocal() &&
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
(GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasInternalLinkage()) {
if (GVar->hasLocalLinkage()) {
O << "\t.lcomm " << name << "#," << Size
<< ',' << (1 << Align);
O << '\n';
@ -307,6 +307,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
O << TAI->getGlobalDirective() << name << '\n';
// FALL THROUGH
case GlobalValue::InternalLinkage:
case GlobalValue::PrivateLinkage:
break;
case GlobalValue::GhostLinkage:
cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";

View File

@ -349,10 +349,10 @@ MSILWriter::ValueType MSILWriter::getValueLocation(const Value* V) {
return ArgumentVT;
// Function
else if (const Function* F = dyn_cast<Function>(V))
return F->hasInternalLinkage() ? InternalVT : GlobalVT;
return F->hasLocalLinkage() ? InternalVT : GlobalVT;
// Variable
else if (const GlobalVariable* G = dyn_cast<GlobalVariable>(V))
return G->hasInternalLinkage() ? InternalVT : GlobalVT;
return G->hasLocalLinkage() ? InternalVT : GlobalVT;
// Constant
else if (isa<Constant>(V))
return isa<ConstantExpr>(V) ? ConstExprVT : ConstVT;
@ -1401,7 +1401,7 @@ void MSILWriter::printStaticInitializerList() {
void MSILWriter::printFunction(const Function& F) {
bool isSigned = F.paramHasAttr(0, Attribute::SExt);
Out << "\n.method static ";
Out << (F.hasInternalLinkage() ? "private " : "public ");
Out << (F.hasLocalLinkage() ? "private " : "public ");
if (F.isVarArg()) Out << "vararg ";
Out << getTypeName(F.getReturnType(),isSigned) <<
getConvModopt(F.getCallingConv()) << getValueName(&F) << '\n';

View File

@ -275,9 +275,6 @@ runOnMachineFunction(MachineFunction &MF)
O << "\n\n";
// What's my mangled name?
CurrentFnName = Mang->getValueName(MF.getFunction());
// Emit the function start directives
emitFunctionStart(MF);
@ -384,7 +381,10 @@ printOperand(const MachineInstr *MI, int opNum)
return;
case MachineOperand::MO_GlobalAddress:
O << Mang->getValueName(MO.getGlobal());
{
const GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
}
break;
case MachineOperand::MO_ExternalSymbol:
@ -449,7 +449,7 @@ printFCCOperand(const MachineInstr *MI, int opNum, const char *Modifier)
bool MipsAsmPrinter::
doInitialization(Module &M)
{
Mang = new Mangler(M);
Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
// Tell the assembler which ABI we are using
O << "\t.section .mdebug." << emitCurrentABIString() << '\n';
@ -502,10 +502,10 @@ printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && !GVar->hasSection()) {
if (!GVar->isThreadLocal() &&
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
(GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasInternalLinkage())
if (GVar->hasLocalLinkage())
O << "\t.local\t" << name << '\n';
O << TAI->getCOMMDirective() << name << ',' << Size;
@ -531,6 +531,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
// If external or appending, declare as a global symbol
O << TAI->getGlobalDirective() << name << '\n';
// Fall Through
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
if (CVA && CVA->isCString())
printSizeAndType = false;

View File

@ -216,7 +216,7 @@ bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV)
// if this is a internal constant string, there is a special
// section for it, but not in small data/bss.
if (GVA->hasInitializer() && GV->hasInternalLinkage()) {
if (GVA->hasInitializer() && GV->hasLocalLinkage()) {
Constant *C = GVA->getInitializer();
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
if (CVA && CVA->isCString())
@ -489,7 +489,7 @@ LowerGlobalAddress(SDValue Op, SelectionDAG &DAG)
SDValue ResNode = DAG.getLoad(MVT::i32, DAG.getEntryNode(), GA, NULL, 0);
// On functions and global targets not internal linked only
// a load from got/GP is necessary for PIC to work.
if (!GV->hasInternalLinkage() || isa<Function>(GV))
if (!GV->hasLocalLinkage() || isa<Function>(GV))
return ResNode;
SDValue Lo = DAG.getNode(MipsISD::Lo, MVT::i32, GA);
return DAG.getNode(ISD::ADD, MVT::i32, ResNode, Lo);

View File

@ -584,6 +584,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::PrivateLinkage:
case Function::InternalLinkage: // Symbols default to internal.
break;
case Function::ExternalLinkage:
@ -686,7 +687,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
(GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
(GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
@ -695,7 +696,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
O << "\t.type " << name << ", @object\n";
O << name << ":\n";
O << "\t.zero " << Size << '\n';
} else if (GVar->hasInternalLinkage()) {
} else if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << ',' << Size;
} else {
O << ".comm " << name << ',' << Size;
@ -723,6 +724,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
<< "\t.type " << name << ", @object\n";
// FALL THROUGH
case GlobalValue::InternalLinkage:
case GlobalValue::PrivateLinkage:
break;
default:
cerr << "Unknown linkage type!";
@ -911,7 +913,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
(GVar->hasInternalLinkage() || GVar->hasExternalLinkage() ||
(GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
@ -919,7 +921,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
O << "\t.globl " << name << '\n';
O << "\t.zerofill __DATA, __common, " << name << ", "
<< Size << ", " << Align;
} else if (GVar->hasInternalLinkage()) {
} else if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
} else if (!GVar->hasCommonLinkage()) {
O << "\t.globl " << name << '\n'

View File

@ -98,8 +98,6 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
static unsigned BBNumber = 0;
O << "\n\n";
// What's my mangled name?
CurrentFnName = Mang->getValueName(MF.getFunction());
// Print out the label for the function.
const Function *F = MF.getFunction();
@ -168,7 +166,10 @@ void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
printBasicBlockLabel(MO.getMBB());
return;
case MachineOperand::MO_GlobalAddress:
O << Mang->getValueName(MO.getGlobal());
{
const GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
}
break;
case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName();
@ -218,7 +219,7 @@ void SparcAsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
}
bool SparcAsmPrinter::doInitialization(Module &M) {
Mang = new Mangler(M);
Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
return false; // success
}
@ -255,10 +256,10 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (C->isNullValue() && !GVar->hasSection()) {
if (!GVar->isThreadLocal() &&
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
(GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (GVar->hasInternalLinkage())
if (GVar->hasLocalLinkage())
O << "\t.local " << name << '\n';
O << TAI->getCOMMDirective() << name << ',' << Size;
@ -284,6 +285,7 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
// If external or appending, declare as a global symbol
O << TAI->getGlobalDirective() << name << '\n';
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
break;
case GlobalValue::GhostLinkage:

View File

@ -159,6 +159,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.
case Function::PrivateLinkage:
EmitAlignment(FnAlign, F);
break;
case Function::DLLExportLinkage:
@ -188,7 +189,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
else if (Subtarget->isTargetCygMing()) {
O << "\t.def\t " << CurrentFnName
<< ";\t.scl\t" <<
(F->getLinkage() == Function::InternalLinkage ? COFF::C_STAT : COFF::C_EXT)
(F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
<< ";\t.endef\n";
}
@ -421,7 +422,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
if (shouldPrintPLT(TM, Subtarget)) {
// Assemble call via PLT for externally visible symbols
if (!GV->hasHiddenVisibility() && !GV->hasProtectedVisibility() &&
!GV->hasInternalLinkage())
!GV->hasLocalLinkage())
O << "@PLT";
}
if (Subtarget->isTargetCygMing() && GV->isDeclaration())
@ -789,11 +790,11 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
if (!GVar->isThreadLocal() &&
(GVar->hasInternalLinkage() || GVar->mayBeOverridden())) {
(GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (TAI->getLCOMMDirective() != NULL) {
if (GVar->hasInternalLinkage()) {
if (GVar->hasLocalLinkage()) {
O << TAI->getLCOMMDirective() << name << ',' << Size;
if (Subtarget->isTargetDarwin())
O << ',' << Align;
@ -813,7 +814,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
} else {
if (!Subtarget->isTargetCygMing()) {
if (GVar->hasInternalLinkage())
if (GVar->hasLocalLinkage())
O << "\t.local\t" << name << '\n';
}
O << TAI->getCOMMDirective() << name << ',' << Size;
@ -849,6 +850,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
// If external or appending, declare as a global symbol
O << "\t.globl " << name << '\n';
// FALL THROUGH
case GlobalValue::PrivateLinkage:
case GlobalValue::InternalLinkage:
break;
default:

View File

@ -145,6 +145,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
FnAlign = 1;
switch (F->getLinkage()) {
default: assert(0 && "Unsupported linkage type!");
case Function::PrivateLinkage:
case Function::InternalLinkage:
EmitAlignment(FnAlign);
break;

View File

@ -56,7 +56,7 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
// Extra load is needed for all externally visible.
if (isDirectCall)
return false;
if (GV->hasInternalLinkage() || GV->hasHiddenVisibility())
if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
return false;
return true;
} else if (isTargetCygMing() || isTargetWindows()) {
@ -79,7 +79,7 @@ bool X86Subtarget::GVRequiresRegister(const GlobalValue *GV,
// returns false.
if (TM.getRelocationModel() == Reloc::PIC_)
return !isDirectCall &&
(GV->hasInternalLinkage() || GV->hasExternalLinkage());
(GV->hasLocalLinkage() || GV->hasExternalLinkage());
return false;
}

View File

@ -198,6 +198,7 @@ emitGlobal(const GlobalVariable *GV)
}
// FALL THROUGH
case GlobalValue::InternalLinkage:
case GlobalValue::PrivateLinkage:
break;
case GlobalValue::GhostLinkage:
cerr << "Should not have any unmaterialized functions!\n";
@ -259,6 +260,7 @@ emitFunctionStart(MachineFunction &MF)
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.
case Function::PrivateLinkage:
break;
case Function::ExternalLinkage:
emitGlobalDirective(CurrentFnName);
@ -299,9 +301,6 @@ bool XCoreAsmPrinter::runOnMachineFunction(MachineFunction &MF)
// Print out jump tables referenced by the function
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
// What's my mangled name?
CurrentFnName = Mang->getValueName(MF.getFunction());
// Emit the function start directives
emitFunctionStart(MF);
@ -367,9 +366,12 @@ void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
printBasicBlockLabel(MO.getMBB());
break;
case MachineOperand::MO_GlobalAddress:
O << Mang->getValueName(MO.getGlobal());
if (MO.getGlobal()->hasExternalWeakLinkage())
ExtWeakSymbols.insert(MO.getGlobal());
{
const GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
}
break;
case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName();

View File

@ -114,7 +114,7 @@ bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
Function *F = CGN->getFunction();
// Make sure that it is local to this module.
if (!F || !F->hasInternalLinkage()) return false;
if (!F || !F->hasLocalLinkage()) return false;
// First check: see if there are any pointer arguments! If not, quick exit.
SmallVector<std::pair<Argument*, unsigned>, 16> PointerArgs;

View File

@ -72,7 +72,7 @@ bool ConstantMerge::runOnModule(Module &M) {
// If this GV is dead, remove it.
GV->removeDeadConstantUsers();
if (GV->use_empty() && GV->hasInternalLinkage()) {
if (GV->use_empty() && GV->hasLocalLinkage()) {
GV->eraseFromParent();
continue;
}
@ -86,7 +86,7 @@ bool ConstantMerge::runOnModule(Module &M) {
if (Slot == 0) { // Nope, add it to the map.
Slot = GV;
} else if (GV->hasInternalLinkage()) { // Yup, this is a duplicate!
} else if (GV->hasLocalLinkage()) { // Yup, this is a duplicate!
// Make all uses of the duplicate constant use the canonical version.
Replacements.push_back(std::make_pair(GV, Slot));
}

View File

@ -172,7 +172,7 @@ ModulePass *llvm::createDeadArgHackingPass() { return new DAH(); }
/// llvm.vastart is never called, the varargs list is dead for the function.
bool DAE::DeleteDeadVarargs(Function &Fn) {
assert(Fn.getFunctionType()->isVarArg() && "Function isn't varargs!");
if (Fn.isDeclaration() || !Fn.hasInternalLinkage()) return false;
if (Fn.isDeclaration() || !Fn.hasLocalLinkage()) return false;
// Ensure that the function is only directly called.
for (Value::use_iterator I = Fn.use_begin(), E = Fn.use_end(); I != E; ++I) {
@ -424,7 +424,7 @@ void DAE::SurveyFunction(Function &F) {
return;
}
if (!F.hasInternalLinkage() && (!ShouldHackArguments() || F.isIntrinsic())) {
if (!F.hasLocalLinkage() && (!ShouldHackArguments() || F.isIntrinsic())) {
MarkLive(F);
return;
}

View File

@ -63,7 +63,7 @@ namespace {
I != E; ++I) {
if (CallInst* callInst = dyn_cast<CallInst>(&*I)) {
Function* Callee = callInst->getCalledFunction();
if (Callee && Callee->hasInternalLinkage())
if (Callee && Callee->hasLocalLinkage())
Callee->setLinkage(GlobalValue::ExternalLinkage);
}
}
@ -85,6 +85,7 @@ namespace {
bool isolateGV(Module &M) {
// Mark all globals internal
// FIXME: what should we do with private linkage?
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
if (!I->isDeclaration()) {
I->setLinkage(GlobalValue::InternalLinkage);

View File

@ -63,7 +63,7 @@ bool GlobalDCE::runOnModule(Module &M) {
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Changed |= RemoveUnusedGlobalValue(*I);
// Functions with external linkage are needed if they have a body
if ((!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) &&
if ((!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) &&
!I->isDeclaration())
GlobalIsNeeded(I);
}
@ -73,7 +73,7 @@ bool GlobalDCE::runOnModule(Module &M) {
Changed |= RemoveUnusedGlobalValue(*I);
// Externally visible & appending globals are needed, if they have an
// initializer.
if ((!I->hasInternalLinkage() && !I->hasLinkOnceLinkage()) &&
if ((!I->hasLocalLinkage() && !I->hasLinkOnceLinkage()) &&
!I->isDeclaration())
GlobalIsNeeded(I);
}

View File

@ -464,7 +464,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD) {
if (!GlobalUsersSafeToSRA(GV))
return 0;
assert(GV->hasInternalLinkage() && !GV->isConstant());
assert(GV->hasLocalLinkage() && !GV->isConstant());
Constant *Init = GV->getInitializer();
const Type *Ty = Init->getType();
@ -1808,12 +1808,12 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {
Function *F = FI++;
F->removeDeadConstantUsers();
if (F->use_empty() && (F->hasInternalLinkage() ||
if (F->use_empty() && (F->hasLocalLinkage() ||
F->hasLinkOnceLinkage())) {
M.getFunctionList().erase(F);
Changed = true;
++NumFnDeleted;
} else if (F->hasInternalLinkage()) {
} else if (F->hasLocalLinkage()) {
if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
OnlyCalledDirectly(F)) {
// If this function has C calling conventions, is not a varargs
@ -1843,7 +1843,7 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
GVI != E; ) {
GlobalVariable *GV = GVI++;
if (!GV->isConstant() && GV->hasInternalLinkage() &&
if (!GV->isConstant() && GV->hasLocalLinkage() &&
GV->hasInitializer())
Changed |= ProcessInternalGlobal(GV, GVI);
}
@ -1982,7 +1982,7 @@ static Constant *getVal(DenseMap<Value*, Constant*> &ComputedValues,
/// globals. This should be kept up to date with CommitValueTo.
static bool isSimpleEnoughPointerToCommit(Constant *C) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
return false; // do not allow weak/linkonce/dllimport/dllexport linkage.
return !GV->isDeclaration(); // reject external globals.
}
@ -1991,7 +1991,7 @@ static bool isSimpleEnoughPointerToCommit(Constant *C) {
if (CE->getOpcode() == Instruction::GetElementPtr &&
isa<GlobalVariable>(CE->getOperand(0))) {
GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
return false; // do not allow weak/linkonce/dllimport/dllexport linkage.
return GV->hasInitializer() &&
ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE);

View File

@ -63,7 +63,7 @@ bool IPCP::runOnModule(Module &M) {
if (!I->isDeclaration()) {
// Delete any klingons.
I->removeDeadConstantUsers();
if (I->hasInternalLinkage())
if (I->hasLocalLinkage())
LocalChange |= PropagateConstantsIntoArguments(*I);
Changed |= PropagateConstantReturn(*I);
}

View File

@ -68,7 +68,7 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
// If we inlined the last possible call site to the function, delete the
// function body now.
if (Callee->use_empty() && Callee->hasInternalLinkage() &&
if (Callee->use_empty() && Callee->hasLocalLinkage() &&
!SCCFunctions.count(Callee)) {
DOUT << " -> Deleting dead function: " << Callee->getName() << "\n";
CallGraphNode *CalleeNode = CG[Callee];
@ -240,7 +240,7 @@ bool Inliner::removeDeadFunctions(CallGraph &CG,
if (DNR && DNR->count(F))
continue;
if ((F->hasLinkOnceLinkage() || F->hasInternalLinkage()) &&
if ((F->hasLinkOnceLinkage() || F->hasLocalLinkage()) &&
F->use_empty()) {
// Remove any call graph edges from the function to its callees.

View File

@ -121,9 +121,10 @@ bool InternalizePass::runOnModule(Module &M) {
bool Changed = false;
// Mark all functions not in the api as internal.
// FIXME: maybe use private linkage?
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isDeclaration() && // Function must be defined here
!I->hasInternalLinkage() && // Can't already have internal linkage
!I->hasLocalLinkage() && // Can't already have internal linkage
!ExternalNames.count(I->getName())) {// Not marked to keep external?
I->setLinkage(GlobalValue::InternalLinkage);
// Remove a callgraph edge from the external node to this function.
@ -149,9 +150,10 @@ bool InternalizePass::runOnModule(Module &M) {
// Mark all global variables with initializers that are not in the api as
// internal as well.
// FIXME: maybe use private linkage?
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
if (!I->isDeclaration() && !I->hasInternalLinkage() &&
if (!I->isDeclaration() && !I->hasLocalLinkage() &&
!ExternalNames.count(I->getName())) {
I->setLinkage(GlobalValue::InternalLinkage);
Changed = true;

View File

@ -245,7 +245,7 @@ static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
Function *G = FnVec[j];
if (!F->mayBeOverridden()) {
if (G->hasInternalLinkage()) {
if (G->hasLocalLinkage()) {
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
G->replaceAllUsesWith(F);
G->eraseFromParent();
@ -329,7 +329,7 @@ bool MergeFunctions::runOnModule(Module &M) {
if (F->isDeclaration() || F->isIntrinsic())
continue;
if (!F->hasInternalLinkage() && !F->hasExternalLinkage() &&
if (!F->hasLocalLinkage() && !F->hasExternalLinkage() &&
!F->hasWeakLinkage())
continue;

View File

@ -95,7 +95,7 @@ static void RemoveDeadConstant(Constant *C) {
OnlyUsedBy(C->getOperand(i), C))
Operands.insert(C->getOperand(i));
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (!GV->hasInternalLinkage()) return; // Don't delete non static globals.
if (!GV->hasLocalLinkage()) return; // Don't delete non static globals.
GV->eraseFromParent();
}
else if (!isa<Function>(C))
@ -114,7 +114,7 @@ static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) {
for (ValueSymbolTable::iterator VI = ST.begin(), VE = ST.end(); VI != VE; ) {
Value *V = VI->getValue();
++VI;
if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasInternalLinkage()) {
if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
if (!PreserveDbgInfo || strncmp(V->getNameStart(), "llvm.dbg", 8))
// Set name to "", removing from symbol table!
V->setName("");
@ -162,13 +162,13 @@ bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
I->setName(""); // Internal symbols can't participate in linkage
}
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
I->setName(""); // Internal symbols can't participate in linkage
StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
@ -268,6 +268,7 @@ bool StripDebugInfo(Module &M) {
// llvm.dbg.compile_units and llvm.dbg.subprograms are marked as linkonce
// but since we are removing all debug information, make them internal now.
// FIXME: Use private linkage maybe?
if (Constant *C = M.getNamedGlobal("llvm.dbg.compile_units"))
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C))
GV->setLinkage(GlobalValue::InternalLinkage);
@ -299,7 +300,7 @@ bool StripDebugInfo(Module &M) {
Constant *C = DeadConstants.back();
DeadConstants.pop_back();
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (GV->hasInternalLinkage())
if (GV->hasLocalLinkage())
RemoveDeadConstant(GV);
}
else
@ -329,4 +330,3 @@ bool StripSymbols::runOnModule(Module &M) {
bool StripNonDebugSymbols::runOnModule(Module &M) {
return StripSymbolNames(M, true);
}

View File

@ -82,7 +82,7 @@ bool SRETPromotion::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
Function *F = CGN->getFunction();
if (!F || F->isDeclaration() || !F->hasInternalLinkage())
if (!F || F->isDeclaration() || !F->hasLocalLinkage())
return false;
// Make sure that function returns struct.

View File

@ -203,7 +203,7 @@ public:
/// and out of the specified function (which cannot have its address taken),
/// this method must be called.
void AddTrackedFunction(Function *F) {
assert(F->hasInternalLinkage() && "Can only track internal functions!");
assert(F->hasLocalLinkage() && "Can only track internal functions!");
// Add an entry, F -> undef.
if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
@ -609,7 +609,7 @@ void SCCPSolver::visitReturnInst(ReturnInst &I) {
Function *F = I.getParent()->getParent();
// If we are tracking the return value of this function, merge it in.
if (!F->hasInternalLinkage())
if (!F->hasLocalLinkage())
return;
if (!TrackedRetVals.empty() && I.getNumOperands() == 1) {
@ -1170,7 +1170,7 @@ void SCCPSolver::visitCallSite(CallSite CS) {
// The common case is that we aren't tracking the callee, either because we
// are not doing interprocedural analysis or the callee is indirect, or is
// external. Handle these cases first.
if (F == 0 || !F->hasInternalLinkage()) {
if (F == 0 || !F->hasLocalLinkage()) {
CallOverdefined:
// Void return and not tracking callee, just bail.
if (I->getType() == Type::VoidTy) return;
@ -1656,7 +1656,7 @@ bool IPSCCP::runOnModule(Module &M) {
// taken or that are external as overdefined.
//
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
if (!F->hasInternalLinkage() || AddressIsTaken(F)) {
if (!F->hasLocalLinkage() || AddressIsTaken(F)) {
if (!F->isDeclaration())
Solver.MarkBlockExecutable(F->begin());
for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end();
@ -1671,7 +1671,7 @@ bool IPSCCP::runOnModule(Module &M) {
// their addresses taken, we can propagate constants through them.
for (Module::global_iterator G = M.global_begin(), E = M.global_end();
G != E; ++G)
if (!G->isConstant() && G->hasInternalLinkage() && !AddressIsTaken(G))
if (!G->isConstant() && G->hasLocalLinkage() && !AddressIsTaken(G))
Solver.TrackValueOfGlobalVariable(G);
// Solve for constants.

View File

@ -130,7 +130,7 @@ void BasicInlinerImpl::inlineFunctions() {
// Inline
if (InlineFunction(CS, NULL, TD)) {
if (Callee->use_empty() && Callee->hasInternalLinkage())
if (Callee->use_empty() && Callee->hasLocalLinkage())
DeadFunctions.insert(Callee);
Changed = true;
CallSites.erase(CallSites.begin() + index);

View File

@ -199,7 +199,7 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
// If there is only one call of the function, and it has internal linkage,
// make it almost guaranteed to be inlined.
//
if (Callee->hasInternalLinkage() && Callee->hasOneUse())
if (Callee->hasLocalLinkage() && Callee->hasOneUse())
InlineCost -= 15000;
// If this function uses the coldcc calling convention, prefer not to inline

View File

@ -1149,6 +1149,7 @@ void AssemblyWriter::printModule(const Module *M) {
static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) {
switch (LT) {
case GlobalValue::PrivateLinkage: Out << "private "; break;
case GlobalValue::InternalLinkage: Out << "internal "; break;
case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break;
case GlobalValue::WeakLinkage: Out << "weak "; break;

View File

@ -147,14 +147,20 @@ std::string Mangler::getValueName(const GlobalValue *GV, const char * Suffix) {
Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(GlobalID++);
} else {
Name = makeNameProper(GV->getName() + Suffix, Prefix);
std::string prefix;
if (GV->hasPrivateLinkage())
prefix = PrivatePrefix;
else
prefix = "";
Name = prefix + Name;
}
return Name;
}
Mangler::Mangler(Module &M, const char *prefix)
: Prefix(prefix), UseQuotes(false), PreserveAsmNames(false),
Count(0), TypeCounter(0) {
Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
: Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false),
PreserveAsmNames(false), Count(0), TypeCounter(0) {
std::fill(AcceptableChars, array_endof(AcceptableChars), 0);
// Letters and numbers are acceptable.

View File

@ -153,7 +153,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
}
// Okay, the function exists. Does it have externally visible linkage?
if (F->hasInternalLinkage()) {
if (F->hasLocalLinkage()) {
// Clear the function's name.
F->setName("");
// Retry, now there won't be a conflict.
@ -238,14 +238,14 @@ Function *Module::getFunction(const char *Name) const {
/// symbol table. If it does not exist, return null. The type argument
/// should be the underlying type of the global, i.e., it should not have
/// the top-level PointerType, which represents the address of the global.
/// If AllowInternal is set to true, this function will return types that
/// have InternalLinkage. By default, these types are not returned.
/// If AllowLocal is set to true, this function will return types that
/// have an local. By default, these types are not returned.
///
GlobalVariable *Module::getGlobalVariable(const std::string &Name,
bool AllowInternal) const {
bool AllowLocal) const {
if (Value *V = ValSymTab->lookup(Name)) {
GlobalVariable *Result = dyn_cast<GlobalVariable>(V);
if (Result && (AllowInternal || !Result->hasInternalLinkage()))
if (Result && (AllowLocal || !Result->hasLocalLinkage()))
return Result;
}
return 0;
@ -376,4 +376,3 @@ void Module::removeLibrary(const std::string& Lib) {
return;
}
}

View File

@ -350,7 +350,7 @@ void Verifier::visitGlobalValue(GlobalValue &GV) {
GV.hasExternalWeakLinkage() ||
GV.hasGhostLinkage() ||
(isa<GlobalAlias>(GV) &&
(GV.hasInternalLinkage() || GV.hasWeakLinkage())),
(GV.hasLocalLinkage() || GV.hasWeakLinkage())),
"Global is external, but doesn't have external or dllimport or weak linkage!",
&GV);
@ -384,7 +384,7 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) {
void Verifier::visitGlobalAlias(GlobalAlias &GA) {
Assert1(!GA.getName().empty(),
"Alias name cannot be empty!", &GA);
Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() ||
Assert1(GA.hasExternalLinkage() || GA.hasLocalLinkage() ||
GA.hasWeakLinkage(),
"Alias should have external or external weak linkage!", &GA);
Assert1(GA.getAliasee(),

View File

@ -0,0 +1,9 @@
; Test to make sure that the 'private' tag is not lost!
;
; RUN: llvm-as < %s | llvm-dis | grep private
declare void @foo()
define private void @foo() {
ret void
}

View File

@ -0,0 +1,22 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -mtriple=arm-linux-gnueabi > %t
; RUN: grep .Lfoo: %t
; RUN: egrep bl.*\.Lfoo %t
; RUN: grep .Lbaz: %t
; RUN: grep long.*\.Lbaz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,21 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc > %t
; RUN: grep .Lfoo: %t
; RUN: grep call.*\.Lfoo %t
; RUN: grep .Lbaz: %t
; RUN: grep movl.*\.Lbaz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,22 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -march=cellspu > %t
; RUN: grep .Lfoo: %t
; RUN: grep brsl.*\.Lfoo %t
; RUN: grep .Lbaz: %t
; RUN: grep ila.*\.Lbaz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,21 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -march=ia64 > %t
; RUN: grep .foo: %t
; RUN: grep br.call.sptk.*\.foo %t
; RUN: grep .baz: %t
; RUN: grep ltoff.*\.baz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,21 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -march=mips > %t
; RUN: grep \\\$foo: %t
; RUN: grep call.*\\\$foo %t
; RUN: grep \\\$baz: %t
; RUN: grep lw.*\\\$baz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,21 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu > %t
; RUN: grep .Lfoo: %t
; RUN: grep bl.*\.Lfoo %t
; RUN: grep .Lbaz: %t
; RUN: grep lis.*\.Lbaz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,21 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -march=sparc > %t
; RUN: grep .foo: %t
; RUN: grep call.*\.foo %t
; RUN: grep .baz: %t
; RUN: grep ld.*\.baz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,20 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep .Lfoo:
; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep call.*\.Lfoo
; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep .Lbaz:
; RUN: llvm-as < %s | llc -mtriple=x86_64-pc-linux | grep movl.*\.Lbaz
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -0,0 +1,21 @@
; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -march=xcore > %t
; RUN: grep .Lfoo: %t
; RUN: grep bl.*\.Lfoo %t
; RUN: grep .Lbaz: %t
; RUN: grep ldw.*\.Lbaz %t
declare void @foo()
define private void @foo() {
ret void
}
@baz = private global i32 4;
define i32 @bar() {
call void @foo()
%1 = load i32* @baz, align 4
ret i32 %1
}

View File

@ -199,7 +199,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
/// prune appropriate entries out of M1s list.
static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
if (!GV || GV->isDeclaration() || GV->hasInternalLinkage() ||
if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() ||
!GV->use_empty()) return;
std::vector<std::pair<Function*, int> > M1Tors, M2Tors;

View File

@ -68,6 +68,7 @@ namespace {
}
static char TypeCharForSymbol(GlobalValue &GV) {
/* FIXME: what to do with private linkage? */
if (GV.isDeclaration()) return 'U';
if (GV.hasLinkOnceLinkage()) return 'C';
if (GV.hasCommonLinkage()) return 'C';
@ -91,7 +92,7 @@ static void DumpSymbolNameForGlobalValue(GlobalValue &GV) {
return;
if ((TypeChar == 'U') && DefinedOnly)
return;
if (GV.hasInternalLinkage () && ExternalOnly)
if (GV.hasLocalLinkage () && ExternalOnly)
return;
if (OutputFormat == posix) {
std::cout << GV.getName () << " " << TypeCharForSymbol (GV) << " "