llvm.org GIT mirror llvm / debd7e4
Simplify the handling of pcrel relocations on ELF. Now we do the right thing for all symbol differences and can drop the old EmitPCRelSymbolValue method. This also make getExprForFDESymbol on ELF equal to the one on MachO, and it can be made non-virtual. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130634 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 8 years ago
15 changed file(s) with 45 addition(s) and 70 deletion(s). Raw diff Collapse all Expand all
325325
326326 virtual const MCExpr *
327327 getExprForPersonalitySymbol(const MCSymbol *Sym,
328 unsigned Encoding,
328329 MCStreamer &Streamer) const;
329330
330 virtual const MCExpr *
331 getExprForFDESymbol(const MCSymbol *Sym, MCStreamer &Streamer) const;
331 const MCExpr *
332 getExprForFDESymbol(const MCSymbol *Sym,
333 unsigned Encoding,
334 MCStreamer &Streamer) const;
332335
333336 bool usesSunStyleELFSectionSwitchSyntax() const {
334337 return SunStyleELFSectionSwitchSyntax;
2424
2525 struct MCAsmInfoDarwin : public MCAsmInfo {
2626 explicit MCAsmInfoDarwin();
27 virtual const MCExpr *
28 getExprForFDESymbol(const MCSymbol *Sym, MCStreamer &Streamer) const;
2927 };
3028 }
3129
6262
6363 virtual void EmitLabel(MCSymbol *Symbol);
6464 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
65 bool isPCRel, unsigned AddrSpace);
65 unsigned AddrSpace);
6666 virtual void EmitULEB128Value(const MCExpr *Value);
6767 virtual void EmitSLEB128Value(const MCExpr *Value);
6868 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
4949 MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
5050 MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
5151
52 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
53 bool isPCRel, unsigned AddrSpace);
54
5552 std::vector FrameInfos;
5653 MCDwarfFrameInfo *getCurrentFrameInfo();
5754 void EnsureValidFrame();
310307 /// @param Size - The size of the integer (in bytes) to emit. This must
311308 /// match a native machine width.
312309 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
313 bool isPCRel, unsigned AddrSpace) = 0;
310 unsigned AddrSpace) = 0;
314311
315312 void EmitValue(const MCExpr *Value, unsigned Size, unsigned AddrSpace = 0);
316
317 void EmitPCRelValue(const MCExpr *Value, unsigned Size,
318 unsigned AddrSpace = 0);
319313
320314 /// EmitIntValue - Special case of EmitValue that avoids the client having
321315 /// to pass in a MCExpr for constant integers.
345339 /// having to pass in a MCExpr for MCSymbols.
346340 void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
347341 unsigned AddrSpace = 0);
348
349 void EmitPCRelSymbolValue(const MCSymbol *Sym, unsigned Size,
350 unsigned AddrSpace = 0);
351342
352343 /// EmitGPRel32Value - Emit the expression @p Value into the output as a
353344 /// gprel32 (32-bit GP relative) value.
14751475 if (IsPCRel) {
14761476 switch ((unsigned)Fixup.getKind()) {
14771477 default: llvm_unreachable("invalid fixup kind!");
1478
1479 case FK_Data_8: Type = ELF::R_X86_64_PC64; break;
1480 case FK_Data_4: Type = ELF::R_X86_64_PC32; break;
1481 case FK_Data_2: Type = ELF::R_X86_64_PC16; break;
1482
14781483 case FK_PCRel_8:
14791484 assert(Modifier == MCSymbolRefExpr::VK_None);
14801485 Type = ELF::R_X86_64_PC64;
14811486 break;
14821487 case X86::reloc_signed_4byte:
14831488 case X86::reloc_riprel_4byte_movq_load:
1484 case FK_Data_4: // FIXME?
14851489 case X86::reloc_riprel_4byte:
14861490 case FK_PCRel_4:
14871491 switch (Modifier) {
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/MC/MCAsmInfo.h"
15 #include "llvm/MC/MCContext.h"
1516 #include "llvm/MC/MCExpr.h"
1617 #include "llvm/MC/MCStreamer.h"
1718 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/Dwarf.h"
1820 #include
1921 #include
2022 using namespace llvm;
110112
111113 const MCExpr *
112114 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
115 unsigned Encoding,
113116 MCStreamer &Streamer) const {
114 return getExprForFDESymbol(Sym, Streamer);
117 return getExprForFDESymbol(Sym, Encoding, Streamer);
115118 }
116119
117120 const MCExpr *
118121 MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
122 unsigned Encoding,
119123 MCStreamer &Streamer) const {
120 return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
124 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
125 return MCSymbolRefExpr::Create(Sym, Streamer.getContext());
126
127 MCContext &Context = Streamer.getContext();
128 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
129 MCSymbol *PCSym = Context.CreateTempSymbol();
130 Streamer.EmitLabel(PCSym);
131 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
132 return MCBinaryExpr::CreateSub(Res, PC, Context);
121133 }
5858 DwarfUsesAbsoluteLabelForStmtList = false;
5959 DwarfUsesLabelOffsetForRanges = false;
6060 }
61
62 const MCExpr *
63 MCAsmInfoDarwin::getExprForFDESymbol(const MCSymbol *Sym,
64 MCStreamer &Streamer) const {
65 MCContext &Context = Streamer.getContext();
66 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context);
67 MCSymbol *PCSym = Context.CreateTempSymbol();
68 Streamer.EmitLabel(PCSym);
69 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context);
70 return MCBinaryExpr::CreateSub(Res, PC, Context);
71 }
161161 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
162162
163163 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
164 bool isPCRel, unsigned AddrSpace);
164 unsigned AddrSpace);
165165 virtual void EmitIntValue(uint64_t Value, unsigned Size,
166166 unsigned AddrSpace = 0);
167167
565565 }
566566
567567 void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
568 bool isPCRel, unsigned AddrSpace) {
568 unsigned AddrSpace) {
569569 assert(getCurrentSection() && "Cannot emit contents before setting section!");
570 assert(!isPCRel && "Cannot emit pc relative relocations!");
571570 const char *Directive = 0;
572571 switch (Size) {
573572 default: break;
467467 MCContext &context = streamer.getContext();
468468 const MCAsmInfo &asmInfo = context.getAsmInfo();
469469 const MCExpr *v = asmInfo.getExprForFDESymbol(&symbol,
470 symbolEncoding,
470471 streamer);
471472 unsigned size = getSizeForEncoding(streamer, symbolEncoding);
472 unsigned application = symbolEncoding & 0x70;
473 if (isa(v) && application == dwarf::DW_EH_PE_pcrel)
474 streamer.EmitPCRelValue(v, size);
475 else
476 streamer.EmitAbsValue(v, size);
473 streamer.EmitAbsValue(v, size);
477474 }
478475
479476 static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
480477 unsigned symbolEncoding) {
481478 MCContext &context = streamer.getContext();
482479 const MCAsmInfo &asmInfo = context.getAsmInfo();
483 const MCExpr *v = asmInfo.getExprForPersonalitySymbol(&symbol, streamer);
480 const MCExpr *v = asmInfo.getExprForPersonalitySymbol(&symbol,
481 symbolEncoding,
482 streamer);
484483 unsigned size = getSizeForEncoding(streamer, symbolEncoding);
485 unsigned application = symbolEncoding & 0x70;
486 if (isa(v) && application == dwarf::DW_EH_PE_pcrel)
487 streamer.EmitPCRelValue(v, size);
488 else
489 streamer.EmitValue(v, size);
484 streamer.EmitValue(v, size);
490485 }
491486
492487 static const MachineLocation TranslateMachineLocation(
153153 }
154154
155155 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
156 bool isPCRel, unsigned AddrSpace){
156 unsigned AddrSpace){
157157 LogCall("EmitValue");
158 return Child->EmitValueImpl(Value, Size, isPCRel, AddrSpace);
158 return Child->EmitValueImpl(Value, Size, AddrSpace);
159159 }
160160
161161 virtual void EmitULEB128Value(const MCExpr *Value) {
6666 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
6767
6868 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
69 bool isPCRel, unsigned AddrSpace) {}
69 unsigned AddrSpace) {}
7070 virtual void EmitULEB128Value(const MCExpr *Value) {}
7171 virtual void EmitSLEB128Value(const MCExpr *Value) {}
7272 virtual void EmitGPRel32Value(const MCExpr *Value) {}
8989 }
9090
9191 void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
92 bool isPCRel, unsigned AddrSpace) {
92 unsigned AddrSpace) {
9393 assert(AddrSpace == 0 && "Address space must be 0!");
9494 MCDataFragment *DF = getOrCreateDataFragment();
9595
101101 }
102102 DF->addFixup(MCFixup::Create(DF->getContents().size(),
103103 Value,
104 MCFixup::getKindForSize(Size, isPCRel)));
104 MCFixup::getKindForSize(Size, false)));
105105 DF->getContents().resize(DF->getContents().size() + Size, 0);
106106 }
107107
113113
114114 void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size,
115115 unsigned AddrSpace) {
116 EmitValueImpl(Value, Size, false, AddrSpace);
117 }
118
119 void MCStreamer::EmitPCRelValue(const MCExpr *Value, unsigned Size,
120 unsigned AddrSpace) {
121 EmitValueImpl(Value, Size, true, AddrSpace);
116 EmitValueImpl(Value, Size, AddrSpace);
122117 }
123118
124119 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
125 bool isPCRel, unsigned AddrSpace) {
126 EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size, isPCRel,
120 unsigned AddrSpace) {
121 EmitValueImpl(MCSymbolRefExpr::Create(Sym, getContext()), Size,
127122 AddrSpace);
128 }
129
130 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
131 unsigned AddrSpace) {
132 EmitSymbolValue(Sym, Size, false, AddrSpace);
133 }
134
135 void MCStreamer::EmitPCRelSymbolValue(const MCSymbol *Sym, unsigned Size,
136 unsigned AddrSpace) {
137 EmitSymbolValue(Sym, Size, true, AddrSpace);
138123 }
139124
140125 void MCStreamer::EmitGPRel32Value(const MCExpr *Value) {
142142 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
143143
144144 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
145 bool isPCRel, unsigned AddrSpace);
145 unsigned AddrSpace);
146146 virtual void EmitULEB128Value(const MCExpr *Value);
147147 virtual void EmitSLEB128Value(const MCExpr *Value);
148148 virtual void EmitGPRel32Value(const MCExpr *Value);
351351 }
352352
353353 void PTXMCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
354 bool isPCRel, unsigned AddrSpace) {
354 unsigned AddrSpace) {
355355 assert(getCurrentSection() && "Cannot emit contents before setting section!");
356 assert(!isPCRel && "Cannot emit pc relative relocations!");
357356 const char *Directive = 0;
358357 switch (Size) {
359358 default: break;
581581 uint64_t Size, unsigned ByteAlignment) {}
582582 virtual void EmitBytes(StringRef Data, unsigned AddrSpace) {}
583583 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
584 bool isPCRel, unsigned AddrSpace) {}
584 unsigned AddrSpace) {}
585585 virtual void EmitULEB128Value(const MCExpr *Value) {}
586586 virtual void EmitSLEB128Value(const MCExpr *Value) {}
587587 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,