diff options
author | Matheus Almeida <matheus.almeida@imgtec.com> | 2014-03-26 13:40:29 +0000 |
---|---|---|
committer | Matheus Almeida <matheus.almeida@imgtec.com> | 2014-03-26 13:40:29 +0000 |
commit | f79b2814210bedecf393700269952be805ead910 (patch) | |
tree | 5483423f1d25f596fa1c7ddd4770f1c887d6272a /llvm/lib | |
parent | c0a3c1d66b479b4e1e72e70d65bbfb2ee66c16f6 (diff) | |
download | bcm5719-llvm-f79b2814210bedecf393700269952be805ead910.tar.gz bcm5719-llvm-f79b2814210bedecf393700269952be805ead910.zip |
[mips] Add support for '.option pic2'.
The directive '.option pic2' enables PIC from assembly source.
At the moment none of the macros/directives check the PIC bit
but that's going to be fixed relatively soon. For example, the
expansion of macros like 'la' depend on the relocation model.
llvm-svn: 204803
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/Target/Mips/MipsTargetStreamer.h | 4 |
3 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index d733caae500..394703595fa 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -2596,6 +2596,17 @@ bool MipsAsmParser::parseDirectiveOption() { return false; } + if (Option == "pic2") { + getTargetStreamer().emitDirectiveOptionPic2(); + Parser.Lex(); + if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { + Error(Parser.getTok().getLoc(), + "unexpected token in .option pic2 directive"); + Parser.eatToEndOfStatement(); + } + return false; + } + // Unknown option. Warning(Parser.getTok().getLoc(), "unknown option in .option directive"); Parser.eatToEndOfStatement(); diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp index f31743a2eae..afe501b2ea5 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp @@ -89,6 +89,10 @@ void MipsTargetAsmStreamer::emitDirectiveOptionPic0() { OS << "\t.option\tpic0\n"; } +void MipsTargetAsmStreamer::emitDirectiveOptionPic2() { + OS << "\t.option\tpic2\n"; +} + void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) { OS << "\t.frame\t$" @@ -132,6 +136,9 @@ MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S, MCAssembler &MCA = getStreamer().getAssembler(); uint64_t Features = STI.getFeatureBits(); Triple T(STI.getTargetTriple()); + Pic = (MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_) + ? true + : false; // Update e_header flags unsigned EFlags = 0; @@ -311,10 +318,24 @@ void MipsTargetELFStreamer::emitDirectiveAbiCalls() { void MipsTargetELFStreamer::emitDirectiveOptionPic0() { MCAssembler &MCA = getStreamer().getAssembler(); unsigned Flags = MCA.getELFHeaderEFlags(); + // This option overrides other PIC options like -KPIC. + Pic = false; Flags &= ~ELF::EF_MIPS_PIC; MCA.setELFHeaderEFlags(Flags); } +void MipsTargetELFStreamer::emitDirectiveOptionPic2() { + MCAssembler &MCA = getStreamer().getAssembler(); + unsigned Flags = MCA.getELFHeaderEFlags(); + Pic = true; + // NOTE: We are following the GAS behaviour here which means the directive + // 'pic2' also sets the CPIC bit in the ELF header. This is different from + // what is stated in the SYSV ABI which consider the bits EF_MIPS_PIC and + // EF_MIPS_CPIC to be mutually exclusive. + Flags |= ELF::EF_MIPS_PIC | ELF::EF_MIPS_CPIC; + MCA.setELFHeaderEFlags(Flags); +} + void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) { // FIXME: implement. diff --git a/llvm/lib/Target/Mips/MipsTargetStreamer.h b/llvm/lib/Target/Mips/MipsTargetStreamer.h index 5550e7d5602..72d6891e427 100644 --- a/llvm/lib/Target/Mips/MipsTargetStreamer.h +++ b/llvm/lib/Target/Mips/MipsTargetStreamer.h @@ -35,6 +35,7 @@ public: virtual void emitDirectiveEnt(const MCSymbol &Symbol) = 0; virtual void emitDirectiveAbiCalls() = 0; virtual void emitDirectiveOptionPic0() = 0; + virtual void emitDirectiveOptionPic2() = 0; virtual void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg) = 0; virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) = 0; @@ -66,6 +67,7 @@ public: virtual void emitDirectiveEnt(const MCSymbol &Symbol); virtual void emitDirectiveAbiCalls(); virtual void emitDirectiveOptionPic0(); + virtual void emitDirectiveOptionPic2(); virtual void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg); virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff); @@ -79,6 +81,7 @@ public: class MipsTargetELFStreamer : public MipsTargetStreamer { bool MicroMipsEnabled; const MCSubtargetInfo &STI; + bool Pic; public: bool isMicroMipsEnabled() const { return MicroMipsEnabled; } @@ -105,6 +108,7 @@ public: virtual void emitDirectiveEnt(const MCSymbol &Symbol); virtual void emitDirectiveAbiCalls(); virtual void emitDirectiveOptionPic0(); + virtual void emitDirectiveOptionPic2(); virtual void emitFrame(unsigned StackReg, unsigned StackSize, unsigned ReturnReg); virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff); |