diff options
author | Duncan Sands <baldrick@free.fr> | 2009-03-07 15:45:40 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2009-03-07 15:45:40 +0000 |
commit | 667d4b8de6dea70195ff12ef39a4deebffa2f5c7 (patch) | |
tree | 7c3eab01e7683698c4818410c678d6af0ebfa56b /lib/CodeGen | |
parent | 0dd2a6a89f49438b239638ab147ac5746d6c32c3 (diff) | |
download | llvm-667d4b8de6dea70195ff12ef39a4deebffa2f5c7.tar.gz llvm-667d4b8de6dea70195ff12ef39a4deebffa2f5c7.tar.bz2 llvm-667d4b8de6dea70195ff12ef39a4deebffa2f5c7.tar.xz |
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 17 | ||||
-rw-r--r-- | lib/CodeGen/ELFWriter.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/IntrinsicLowering.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/MachOWriter.cpp | 9 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/TargetLowering.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/ShadowStackGC.cpp | 4 |
6 files changed, 25 insertions, 17 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 5c4957aba1..9181216b5a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -3135,9 +3135,8 @@ public: GlobalVariable *GV = getGlobalVariable(V); if (!GV) return false; - - if (GV->getLinkage() != GlobalValue::InternalLinkage - && GV->getLinkage() != GlobalValue::LinkOnceLinkage) + + if (!GV->hasInternalLinkage () && !GV->hasLinkOnceLinkage()) return false; DIDescriptor DI(GV); @@ -3449,8 +3448,10 @@ class DwarfException : public Dwarf { } // If corresponding function is weak definition, this should be too. - if ((linkage == Function::WeakLinkage || - linkage == Function::LinkOnceLinkage) && + if ((linkage == Function::WeakAnyLinkage || + linkage == Function::WeakODRLinkage || + linkage == Function::LinkOnceAnyLinkage || + linkage == Function::LinkOnceODRLinkage) && TAI->getWeakDefDirective()) O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n"; @@ -3461,8 +3462,10 @@ class DwarfException : public Dwarf { // unwind info is to be available for non-EH uses. if (!EHFrameInfo.hasCalls && !UnwindTablesMandatory && - ((linkage != Function::WeakLinkage && - linkage != Function::LinkOnceLinkage) || + ((linkage != Function::WeakAnyLinkage && + linkage != Function::WeakODRLinkage && + linkage != Function::LinkOnceAnyLinkage && + linkage != Function::LinkOnceODRLinkage) || !TAI->getWeakDefDirective() || TAI->getSupportsWeakOmittedEHFrame())) { diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 7cca74b1fb..ddc4e3588b 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -174,8 +174,10 @@ bool ELFCodeEmitter::finishFunction(MachineFunction &F) { case GlobalValue::ExternalLinkage: FnSym.SetBind(ELFWriter::ELFSym::STB_GLOBAL); break; - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: FnSym.SetBind(ELFWriter::ELFSym::STB_WEAK); break; case GlobalValue::PrivateLinkage: diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 5b4de27b8a..56b1736b41 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -316,7 +316,7 @@ static Instruction *LowerPartSelect(CallInst *CI) { Name[i] = '_'; Module* M = F->getParent(); F = cast<Function>(M->getOrInsertFunction(Name, FT)); - F->setLinkage(GlobalValue::WeakLinkage); + F->setLinkage(GlobalValue::WeakAnyLinkage); // If we haven't defined the impl function yet, do so now if (F->isDeclaration()) { @@ -490,7 +490,7 @@ static Instruction *LowerPartSet(CallInst *CI) { Name[i] = '_'; Module* M = F->getParent(); F = cast<Function>(M->getOrInsertFunction(Name, FT)); - F->setLinkage(GlobalValue::WeakLinkage); + F->setLinkage(GlobalValue::WeakAnyLinkage); // If we haven't defined the impl function yet, do so now if (F->isDeclaration()) { diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp index 22c21578ec..5fe05a4e8f 100644 --- a/lib/CodeGen/MachOWriter.cpp +++ b/lib/CodeGen/MachOWriter.cpp @@ -956,9 +956,12 @@ MachOSym::MachOSym(const GlobalValue *gv, std::string name, uint8_t sect, default: assert(0 && "Unexpected linkage type!"); break; - case GlobalValue::WeakLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::CommonLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::CommonAnyLinkage: + case GlobalValue::CommonODRLinkage: assert(!isa<Function>(gv) && "Unexpected linkage type for Function!"); case GlobalValue::ExternalLinkage: GVName = TAI->getGlobalPrefix() + name; diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 7913c01963..a08dcb2e49 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -728,7 +728,7 @@ TargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { if (getTargetMachine().getRelocationModel() == Reloc::DynamicNoPIC && GA && !GA->getGlobal()->isDeclaration() && - !GA->getGlobal()->mayBeOverridden()) + !GA->getGlobal()->isWeakForLinker()) return true; // Otherwise assume nothing is safe. diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index 5a55760c7c..2402f81bb0 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -293,12 +293,12 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) { // If the root chain does not exist, insert a new one with linkonce // linkage! Head = new GlobalVariable(StackEntryPtrTy, false, - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, Constant::getNullValue(StackEntryPtrTy), "llvm_gc_root_chain", &M); } else if (Head->hasExternalLinkage() && Head->isDeclaration()) { Head->setInitializer(Constant::getNullValue(StackEntryPtrTy)); - Head->setLinkage(GlobalValue::LinkOnceLinkage); + Head->setLinkage(GlobalValue::LinkOnceAnyLinkage); } return true; |