llvm.org GIT mirror llvm / 637d89f
Add support for ELF PLT references for ARM MC asm printing. Adding a new VariantKind to the MCSymbolExpr seems like overkill, but I'm not sure there's a more straightforward way to get the printing difference captured. (i.e., x86 uses @PLT, ARM uses (PLT)). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114613 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 9 years ago
6 changed file(s) with 52 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
136136 VK_TPOFF,
137137 VK_ARM_HI16, // The R_ARM_MOVT_ABS relocation (:upper16: in the asm file)
138138 VK_ARM_LO16, // The R_ARM_MOVW_ABS_NC relocation (:lower16: in the asm file)
139 VK_ARM_PLT, // ARM-style PLT symbol references. i.e., (PLT) instead of @PLT
139140 VK_TLVP // Mach-O thread local variable relocation
140141 };
141142
4949 else
5050 OS << Sym;
5151
52 if (SRE.getKind() != MCSymbolRefExpr::VK_None &&
53 SRE.getKind() != MCSymbolRefExpr::VK_ARM_HI16 &&
54 SRE.getKind() != MCSymbolRefExpr::VK_ARM_LO16)
52 if (SRE.getKind() == MCSymbolRefExpr::VK_ARM_PLT)
53 OS << MCSymbolRefExpr::getVariantKindName(SRE.getKind());
54 else if (SRE.getKind() != MCSymbolRefExpr::VK_None &&
55 SRE.getKind() != MCSymbolRefExpr::VK_ARM_HI16 &&
56 SRE.getKind() != MCSymbolRefExpr::VK_ARM_LO16)
5557 OS << '@' << MCSymbolRefExpr::getVariantKindName(SRE.getKind());
5658
5759 return;
176178 case VK_TPOFF: return "TPOFF";
177179 case VK_ARM_HI16: return ":upper16:";
178180 case VK_ARM_LO16: return ":lower16:";
181 case VK_ARM_PLT: return "(PLT)";
179182 case VK_TLVP: return "TLVP";
180183 }
181184 }
180180
181181 /// MO_HI16 - On a symbol operand, this represents a relocation containing
182182 /// higher 16 bit of the address. Used only via movt instruction.
183 MO_HI16
183 MO_HI16,
184
185 /// MO_PLT - On a symbol operand, this represents an ELF PLT reference on a
186 /// call operand.
187 MO_PLT
184188 };
185189 } // end namespace ARMII
186190
11941194 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
11951195 Callee = DAG.getNode(ARMISD::PIC_ADD, dl,
11961196 getPointerTy(), Callee, PICLabel);
1197 } else
1198 Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy());
1197 } else {
1198 // On ELF targets for PIC code, direct calls should go through the PLT
1199 unsigned OpFlags = 0;
1200 if (Subtarget->isTargetELF() &&
1201 getTargetMachine().getRelocationModel() == Reloc::PIC_)
1202 OpFlags = ARMII::MO_PLT;
1203 Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags);
1204 }
11991205 } else if (ExternalSymbolSDNode *S = dyn_cast(Callee)) {
12001206 isDirect = true;
12011207 bool isStub = Subtarget->isTargetDarwin() &&
12161222 SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32);
12171223 Callee = DAG.getNode(ARMISD::PIC_ADD, dl,
12181224 getPointerTy(), Callee, PICLabel);
1219 } else
1220 Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy());
1225 } else {
1226 unsigned OpFlags = 0;
1227 // On ELF targets for PIC code, direct calls should go through the PLT
1228 if (Subtarget->isTargetELF() &&
1229 getTargetMachine().getRelocationModel() == Reloc::PIC_)
1230 OpFlags = ARMII::MO_PLT;
1231 Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags);
1232 }
12211233 }
12221234
12231235 // FIXME: handle tail calls differently.
3232 const MCSymbolRefExpr *ARMMCInstLower::
3333 GetSymbolRef(const MachineOperand &MO) const {
3434 assert(MO.isGlobal() && "Isn't a global address reference?");
35 // FIXME: HANDLE PLT references how??
3635
3736 const MCSymbolRefExpr *SymRef;
3837 const MCSymbol *Symbol = GetGlobalAddressSymbol(MO.getGlobal());
4847 case ARMII::MO_HI16:
4948 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx);
5049 break;
50 case ARMII::MO_PLT:
51 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_PLT, Ctx);
52 break;
5153 }
5254
5355 return SymRef;
5456 }
5557
56 MCSymbol *ARMMCInstLower::
58 const MCSymbolRefExpr *ARMMCInstLower::
5759 GetExternalSymbolSymbol(const MachineOperand &MO) const {
58 // FIXME: HANDLE PLT references how??
59 // FIXME: This probably needs to be merged with the above SymbolRef stuff
60 // to handle :lower16: and :upper16: (?)
60 const MCSymbolRefExpr *SymRef;
61 const MCSymbol *Symbol = Printer.GetExternalSymbolSymbol(MO.getSymbolName());
62
6163 switch (MO.getTargetFlags()) {
62 default: assert(0 && "Unknown target flag on GV operand");
63 case 0: break;
64 default: assert(0 && "Unknown target flag on external symbol operand");
65 case 0:
66 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
67 break;
68 case ARMII::MO_LO16:
69 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx);
70 break;
71 case ARMII::MO_HI16:
72 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx);
73 break;
74 case ARMII::MO_PLT:
75 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_PLT, Ctx);
76 break;
6477 }
6578
66 return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
79 return SymRef;
6780 }
6881
6982
156169 MCOp = LowerSymbolRefOperand(MO, GetSymbolRef(MO));
157170 break;
158171 case MachineOperand::MO_ExternalSymbol:
159 MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
172 MCOp = LowerSymbolRefOperand(MO, GetExternalSymbolSymbol(MO));
160173 break;
161174 case MachineOperand::MO_JumpTableIndex:
162175 MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
4242 //MCSymbol *GetPICBaseSymbol() const;
4343 MCSymbol *GetGlobalAddressSymbol(const GlobalValue *GV) const;
4444 const MCSymbolRefExpr *GetSymbolRef(const MachineOperand &MO) const;
45 MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
45 const MCSymbolRefExpr *GetExternalSymbolSymbol(const MachineOperand &MO)
46 const;
4647 MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
4748 MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
4849 MCOperand LowerSymbolRefOperand(const MachineOperand &MO,