[PowerPC CodeGen] patch for bug 15763
David Fang
fang at csl.cornell.edu
Fri Apr 26 16:47:44 PDT 2013
Revised patch attached for review.
Fang
>> Attached is a patch that fixes PIC codegen for PPC on darwin, by privatizing
>> all function stubs and lazy pointer symbols in emitted assembly.
>>
>> http://llvm.org/bugs/show_bug.cgi?id=15763
>>
>> Could PPC maintainers kindly review/apply? Thanks.
>
> getPrivateGlobalPrefix can take a twine, so it is probably better to do
>
> const char* Prefix;
> if (...)
> Prefix = = AP.MAI->getPrivateGlobalPrefix();
> else
> Prefix = "";
> MCSymbol Sym = Ctx.GetOrCreateSymbol(Twine(Prefix) + Twine(Name));
>
> Btw, is there a case where the prefix was already added? I.e., is
> Name.startswith(plp) ever true? It would be nice if the prefix could
> be added in one central location.
>
> Cheers,
> Rafael
>
--
David Fang
http://www.csl.cornell.edu/~fang/
-------------- next part --------------
diff --git a/lib/Target/PowerPC/PPCMCInstLower.cpp b/lib/Target/PowerPC/PPCMCInstLower.cpp
index 9b0df3e..7f4fcae 100644
--- a/lib/Target/PowerPC/PPCMCInstLower.cpp
+++ b/lib/Target/PowerPC/PPCMCInstLower.cpp
@@ -14,6 +14,7 @@
#include "PPC.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
@@ -46,8 +47,15 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
// If the target flags on the operand changes the name of the symbol, do that
// before we return the symbol.
if (MO.getTargetFlags() == PPCII::MO_DARWIN_STUB) {
Name += "$stub";
- MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
+ const char* const PGP = AP.MAI->getPrivateGlobalPrefix();
+ const char* Prefix = "";
+ if (!Name.startswith(PGP)) {
+ // http://llvm.org/bugs/show_bug.cgi?id=15763
+ // all stubs and lazy_ptrs should be local symbols, which need leading 'L'
+ Prefix = PGP;
+ }
+ MCSymbol *Sym = Ctx.GetOrCreateSymbol(Twine(Prefix) +Twine(Name));
MachineModuleInfoImpl::StubValueTy &StubSym =
getMachOMMI(AP).getFnStubEntry(Sym);
if (StubSym.getPointer())
diff --git a/test/CodeGen/PowerPC/stubs.ll b/test/CodeGen/PowerPC/stubs.ll
index cfcc50b..694f208 100644
--- a/test/CodeGen/PowerPC/stubs.ll
+++ b/test/CodeGen/PowerPC/stubs.ll
@@ -6,16 +6,16 @@ entry:
}
; CHECK: _test1:
-; CHECK: bl ___floatditf$stub
+; CHECK: bl L___floatditf$stub
; CHECK: .section __TEXT,__symbol_stub1,symbol_stubs,pure_instructions,16
-; CHECK: ___floatditf$stub:
+; CHECK: L___floatditf$stub:
; CHECK: .indirect_symbol ___floatditf
-; CHECK: lis r11, ha16(___floatditf$lazy_ptr)
-; CHECK: lwzu r12, lo16(___floatditf$lazy_ptr)(r11)
+; CHECK: lis r11, ha16(L___floatditf$lazy_ptr)
+; CHECK: lwzu r12, lo16(L___floatditf$lazy_ptr)(r11)
; CHECK: mtctr r12
; CHECK: bctr
; CHECK: .section __DATA,__la_symbol_ptr,lazy_symbol_pointers
-; CHECK: ___floatditf$lazy_ptr:
+; CHECK: L___floatditf$lazy_ptr:
; CHECK: .indirect_symbol ___floatditf
; CHECK: .long dyld_stub_binding_helper
More information about the llvm-commits
mailing list