llvm.org GIT mirror llvm / 4aebf83
Fully fix the movw/movt addend. The issue is not if the value is pcrel. It is whether we have a relocation or not. If we have a relocation, the static linker will select the upper bits. If we don't have a relocation, we have to do it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307730 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
17 changed file(s) with 48 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
7272 /// reported via \p Ctx.
7373 virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
7474 const MCValue &Target, MutableArrayRef Data,
75 uint64_t Value, bool IsPCRel) const = 0;
75 uint64_t Value, bool IsResolved) const = 0;
7676
7777 /// @}
7878
654654 uint64_t FixedValue;
655655 bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
656656 MCFixupKindInfo::FKF_IsPCRel;
657 if (!evaluateFixup(Layout, Fixup, &F, Target, FixedValue)) {
657 bool IsResolved = evaluateFixup(Layout, Fixup, &F, Target, FixedValue);
658 if (!IsResolved) {
658659 // The fixup was unresolved, we need a relocation. Inform the object
659660 // writer of the relocation, and give it an opportunity to adjust the
660661 // fixup value if need be.
661662 getWriter().recordRelocation(*this, Layout, &F, Fixup, Target, IsPCRel,
662663 FixedValue);
663664 }
664 return std::make_tuple(Target, FixedValue, IsPCRel);
665 return std::make_tuple(Target, FixedValue, IsResolved);
665666 }
666667
667668 void MCAssembler::layout(MCAsmLayout &Layout) {
737738 llvm_unreachable("Unknown fragment with fixups!");
738739 for (const MCFixup &Fixup : Fixups) {
739740 uint64_t FixedValue;
740 bool IsPCRel;
741 bool IsResolved;
741742 MCValue Target;
742 std::tie(Target, FixedValue, IsPCRel) =
743 std::tie(Target, FixedValue, IsResolved) =
743744 handleFixup(Layout, Frag, Fixup);
744745 getBackend().applyFixup(*this, Fixup, Target, Contents, FixedValue,
745 IsPCRel);
746 IsResolved);
746747 }
747748 }
748749 }
7272
7373 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
7474 const MCValue &Target, MutableArrayRef Data,
75 uint64_t Value, bool IsPCRel) const override;
75 uint64_t Value, bool IsResolved) const override;
7676
7777 bool mayNeedRelaxation(const MCInst &Inst) const override;
7878 bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
263263 void AArch64AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
264264 const MCValue &Target,
265265 MutableArrayRef Data, uint64_t Value,
266 bool IsPCRel) const {
266 bool IsResolved) const {
267267 unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind());
268268 if (!Value)
269269 return; // Doesn't change encoding.
3131
3232 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
3333 const MCValue &Target, MutableArrayRef Data,
34 uint64_t Value, bool IsPCRel) const override;
34 uint64_t Value, bool IsResolved) const override;
3535 bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
3636 const MCRelaxableFragment *DF,
3737 const MCAsmLayout &Layout) const override {
9999 void AMDGPUAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
100100 const MCValue &Target,
101101 MutableArrayRef Data, uint64_t Value,
102 bool IsPCRel) const {
102 bool IsResolved) const {
103103 Value = adjustFixupValue(Fixup, Value, &Asm.getContext());
104104 if (!Value)
105105 return; // Doesn't change encoding.
360360 unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
361361 const MCFixup &Fixup,
362362 const MCValue &Target, uint64_t Value,
363 bool IsPCRel, MCContext &Ctx,
364 bool IsLittleEndian,
365 bool IsResolved) const {
363 bool IsResolved, MCContext &Ctx,
364 bool IsLittleEndian) const {
366365 unsigned Kind = Fixup.getKind();
367366
368367 // MachO tries to make .o files that look vaguely pre-linked, so for MOVW/MOVT
391390 case FK_SecRel_4:
392391 return Value;
393392 case ARM::fixup_arm_movt_hi16:
394 if (!IsPCRel && !STI->getTargetTriple().isOSBinFormatELF())
393 if (IsResolved || !STI->getTargetTriple().isOSBinFormatELF())
395394 Value >>= 16;
396395 LLVM_FALLTHROUGH;
397396 case ARM::fixup_arm_movw_lo16: {
403402 return Value;
404403 }
405404 case ARM::fixup_t2_movt_hi16:
406 if (!IsPCRel && !STI->getTargetTriple().isOSBinFormatELF())
405 if (IsResolved || !STI->getTargetTriple().isOSBinFormatELF())
407406 Value >>= 16;
408407 LLVM_FALLTHROUGH;
409408 case ARM::fixup_t2_movw_lo16: {
884883 void ARMAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
885884 const MCValue &Target,
886885 MutableArrayRef Data, uint64_t Value,
887 bool IsPCRel) const {
886 bool IsResolved) const {
888887 unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind());
889888 MCContext &Ctx = Asm.getContext();
890 Value = adjustFixupValue(Asm, Fixup, Target, Value, IsPCRel, Ctx,
891 IsLittleEndian, true);
889 Value = adjustFixupValue(Asm, Fixup, Target, Value, IsResolved, Ctx,
890 IsLittleEndian);
892891 if (!Value)
893892 return; // Doesn't change encoding.
894893
4141 const MCValue &Target) override;
4242
4343 unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
44 const MCValue &Target, uint64_t Value, bool IsPCRel,
45 MCContext &Ctx, bool IsLittleEndian,
46 bool IsResolved) const;
44 const MCValue &Target, uint64_t Value,
45 bool IsResolved, MCContext &Ctx,
46 bool IsLittleEndian) const;
4747
4848 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
4949 const MCValue &Target, MutableArrayRef Data,
50 uint64_t Value, bool IsPCRel) const override;
50 uint64_t Value, bool IsResolved) const override;
5151
5252 unsigned getRelaxedOpcode(unsigned Op) const;
5353
2828
2929 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
3030 const MCValue &Target, MutableArrayRef Data,
31 uint64_t Value, bool IsPCRel) const override;
31 uint64_t Value, bool IsResolved) const override;
3232
3333 MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override;
3434
6464 void BPFAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
6565 const MCValue &Target,
6666 MutableArrayRef Data, uint64_t Value,
67 bool IsPCRel) const {
67 bool IsResolved) const {
6868 if (Fixup.getKind() == FK_SecRel_4 || Fixup.getKind() == FK_SecRel_8) {
6969 assert(Value == 0);
7070 } else if (Fixup.getKind() == FK_Data_4 || Fixup.getKind() == FK_Data_8) {
411411 /// fixup kind as appropriate.
412412 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
413413 const MCValue &Target, MutableArrayRef Data,
414 uint64_t FixupValue, bool IsPCRel) const override {
414 uint64_t FixupValue, bool IsResolved) const override {
415415
416416 // When FixupValue is 0 the relocation is external and there
417417 // is nothing for us to do.
5050
5151 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
5252 const MCValue &Target, MutableArrayRef Data,
53 uint64_t Value, bool IsPCRel) const override;
53 uint64_t Value, bool IsResolved) const override;
5454
5555 MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override;
5656
9191 void LanaiAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
9292 const MCValue &Target,
9393 MutableArrayRef Data, uint64_t Value,
94 bool /*IsPCRel*/) const {
94 bool /*IsResolved*/) const {
9595 MCFixupKind Kind = Fixup.getKind();
9696 Value = adjustFixupValue(static_cast(Kind), Value);
9797
237237 void MipsAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
238238 const MCValue &Target,
239239 MutableArrayRef Data, uint64_t Value,
240 bool IsPCRel) const {
240 bool IsResolved) const {
241241 MCFixupKind Kind = Fixup.getKind();
242242 MCContext &Ctx = Asm.getContext();
243243 Value = adjustFixupValue(Fixup, Value, Ctx);
3939
4040 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
4141 const MCValue &Target, MutableArrayRef Data,
42 uint64_t Value, bool IsPCRel) const override;
42 uint64_t Value, bool IsResolved) const override;
4343
4444 Optional getFixupKind(StringRef Name) const override;
4545 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
114114
115115 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
116116 const MCValue &Target, MutableArrayRef Data,
117 uint64_t Value, bool IsPCRel) const override {
117 uint64_t Value, bool IsResolved) const override {
118118 Value = adjustFixupValue(Fixup.getKind(), Value);
119119 if (!Value) return; // Doesn't change encoding.
120120
3333
3434 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
3535 const MCValue &Target, MutableArrayRef Data,
36 uint64_t Value, bool IsPCRel) const override;
36 uint64_t Value, bool IsResolved) const override;
3737
3838 MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override;
3939
7272 void RISCVAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
7373 const MCValue &Target,
7474 MutableArrayRef Data, uint64_t Value,
75 bool IsPCRel) const {
75 bool IsResolved) const {
7676 return;
7777 }
7878
275275
276276 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
277277 const MCValue &Target, MutableArrayRef Data,
278 uint64_t Value, bool IsPCRel) const override {
278 uint64_t Value, bool IsResolved) const override {
279279
280280 Value = adjustFixupValue(Fixup.getKind(), Value);
281281 if (!Value) return; // Doesn't change encoding.
5151 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override;
5252 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
5353 const MCValue &Target, MutableArrayRef Data,
54 uint64_t Value, bool IsPCRel) const override;
54 uint64_t Value, bool IsResolved) const override;
5555 bool mayNeedRelaxation(const MCInst &Inst) const override {
5656 return false;
5757 }
9393 const MCFixup &Fixup,
9494 const MCValue &Target,
9595 MutableArrayRef Data, uint64_t Value,
96 bool IsPCRel) const {
96 bool IsResolved) const {
9797 MCFixupKind Kind = Fixup.getKind();
9898 unsigned Offset = Fixup.getOffset();
9999 unsigned BitSize = getFixupKindInfo(Kind).TargetSize;
109109
110110 void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
111111 const MCValue &Target, MutableArrayRef Data,
112 uint64_t Value, bool IsPCRel) const override {
112 uint64_t Value, bool IsResolved) const override {
113113 unsigned Size = 1 << getFixupKindLog2Size(Fixup.getKind());
114114
115115 assert(Fixup.getOffset() + Size <= Data.size() && "Invalid fixup offset!");
1515 .LPC0_2:
1616 movw r0, :lower16:extern_symbol+1234
1717 movt r0, :upper16:extern_symbol+1234
18
19 movw r0, :lower16:(foo - bar + 1234)
20 movt r0, :upper16:(foo - bar + 1234)
21 foo:
22 bar:
23
1824 @ ASM: movw r0, :lower16:(GOT-(.LPC0_2+8))
1925 @ ASM-NEXT: movt r0, :upper16:(GOT-(.LPC0_2+8))
2026 @ ASM: movw r0, :lower16:(extern_symbol+1234)
21 @ ASM-NEXT: movt r0, :upper16:(extern_symbol+1234)
27 @ ASM: movw r0, :lower16:((foo-bar)+1234)
28 @ ASM-NEXT: movt r0, :upper16:((foo-bar)+1234)
2229
2330 @OBJ: Disassembly of section .text:
2431 @OBJ-NEXT: barf:
3037 @OBJ-NEXT: 00000008: R_ARM_MOVW_ABS_NC extern_symbol
3138 @OBJ-NEXT: c: d2 04 40 e3 movt r0, #1234
3239 @OBJ-NEXT: 0000000c: R_ARM_MOVT_ABS extern_symbol
40 @OBJ-NEXT: 10: d2 04 00 e3 movw r0, #1234
41 @OBJ-NEXT: 14: 00 00 40 e3 movt r0, #0
3342
3443 @THUMB: Disassembly of section .text:
3544 @THUMB-NEXT: barf:
4150 @THUMB-NEXT: 00000008: R_ARM_THM_MOVW_ABS_NC extern_symbol
4251 @THUMB-NEXT: c: c0 f2 d2 40 movt r0, #1234
4352 @THUMB-NEXT: 0000000c: R_ARM_THM_MOVT_ABS extern_symbol
53 @THUMB-NEXT: 10: 40 f2 d2 40 movw r0, #1234
54 @THUMB-NEXT: 14: c0 f2 00 00 movt r0, #0