llvm.org GIT mirror llvm / 17e3cbf
[DebugInfo] Generate fixups as emitting DWARF .debug_frame/.eh_frame. It is necessary to generate fixups in .debug_frame or .eh_frame as relaxation is enabled due to the address delta may be changed after relaxation. There is an opcode with 6-bits data in debug frame encoding. So, we also need 6-bits fixup types. Differential Revision: https://reviews.llvm.org/D58335 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366442 91177308-0d34-0410-b5e6-96231b3b80d8 Hsiangkai Wang a month ago
18 changed file(s) with 246 addition(s) and 103 deletion(s). Raw diff Collapse all Expand all
6868 /// starting at *Offset and ending at EndOffset. *Offset is updated
6969 /// to EndOffset upon successful parsing, or indicates the offset
7070 /// where a problem occurred in case an error is returned.
71 Error parse(DataExtractor Data, uint32_t *Offset, uint32_t EndOffset);
71 Error parse(DWARFDataExtractor Data, uint32_t *Offset, uint32_t EndOffset);
7272
7373 void dump(raw_ostream &OS, const MCRegisterInfo *MRI, bool IsEH,
7474 unsigned IndentLevel = 1) const;
3939 virtual const DWARFSection &getLocSection() const { return Dummy; }
4040 virtual const DWARFSection &getLoclistsSection() const { return Dummy; }
4141 virtual StringRef getARangeSection() const { return ""; }
42 virtual StringRef getDebugFrameSection() const { return ""; }
43 virtual StringRef getEHFrameSection() const { return ""; }
42 virtual const DWARFSection &getDebugFrameSection() const { return Dummy; }
43 virtual const DWARFSection &getEHFrameSection() const { return Dummy; }
4444 virtual const DWARFSection &getLineSection() const { return Dummy; }
4545 virtual StringRef getLineStringSection() const { return ""; }
4646 virtual StringRef getStringSection() const { return ""; }
628628 static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH);
629629 static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta);
630630 static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta,
631 raw_ostream &OS);
631 raw_ostream &OS, uint32_t *Offset = nullptr,
632 uint32_t *Size = nullptr);
632633 };
633634
634635 } // end namespace llvm
1919
2020 /// Extensible enumeration to represent the type of a fixup.
2121 enum MCFixupKind {
22 FK_NONE = 0, ///< A no-op fixup.
23 FK_Data_1, ///< A one-byte fixup.
24 FK_Data_2, ///< A two-byte fixup.
25 FK_Data_4, ///< A four-byte fixup.
26 FK_Data_8, ///< A eight-byte fixup.
27 FK_PCRel_1, ///< A one-byte pc relative fixup.
28 FK_PCRel_2, ///< A two-byte pc relative fixup.
29 FK_PCRel_4, ///< A four-byte pc relative fixup.
30 FK_PCRel_8, ///< A eight-byte pc relative fixup.
31 FK_GPRel_1, ///< A one-byte gp relative fixup.
32 FK_GPRel_2, ///< A two-byte gp relative fixup.
33 FK_GPRel_4, ///< A four-byte gp relative fixup.
34 FK_GPRel_8, ///< A eight-byte gp relative fixup.
35 FK_DTPRel_4, ///< A four-byte dtp relative fixup.
36 FK_DTPRel_8, ///< A eight-byte dtp relative fixup.
37 FK_TPRel_4, ///< A four-byte tp relative fixup.
38 FK_TPRel_8, ///< A eight-byte tp relative fixup.
39 FK_SecRel_1, ///< A one-byte section relative fixup.
40 FK_SecRel_2, ///< A two-byte section relative fixup.
41 FK_SecRel_4, ///< A four-byte section relative fixup.
42 FK_SecRel_8, ///< A eight-byte section relative fixup.
43 FK_Data_Add_1, ///< A one-byte add fixup.
44 FK_Data_Add_2, ///< A two-byte add fixup.
45 FK_Data_Add_4, ///< A four-byte add fixup.
46 FK_Data_Add_8, ///< A eight-byte add fixup.
47 FK_Data_Sub_1, ///< A one-byte sub fixup.
48 FK_Data_Sub_2, ///< A two-byte sub fixup.
49 FK_Data_Sub_4, ///< A four-byte sub fixup.
50 FK_Data_Sub_8, ///< A eight-byte sub fixup.
22 FK_NONE = 0, ///< A no-op fixup.
23 FK_Data_1, ///< A one-byte fixup.
24 FK_Data_2, ///< A two-byte fixup.
25 FK_Data_4, ///< A four-byte fixup.
26 FK_Data_8, ///< A eight-byte fixup.
27 FK_Data_6b, ///< A six-bits fixup.
28 FK_PCRel_1, ///< A one-byte pc relative fixup.
29 FK_PCRel_2, ///< A two-byte pc relative fixup.
30 FK_PCRel_4, ///< A four-byte pc relative fixup.
31 FK_PCRel_8, ///< A eight-byte pc relative fixup.
32 FK_GPRel_1, ///< A one-byte gp relative fixup.
33 FK_GPRel_2, ///< A two-byte gp relative fixup.
34 FK_GPRel_4, ///< A four-byte gp relative fixup.
35 FK_GPRel_8, ///< A eight-byte gp relative fixup.
36 FK_DTPRel_4, ///< A four-byte dtp relative fixup.
37 FK_DTPRel_8, ///< A eight-byte dtp relative fixup.
38 FK_TPRel_4, ///< A four-byte tp relative fixup.
39 FK_TPRel_8, ///< A eight-byte tp relative fixup.
40 FK_SecRel_1, ///< A one-byte section relative fixup.
41 FK_SecRel_2, ///< A two-byte section relative fixup.
42 FK_SecRel_4, ///< A four-byte section relative fixup.
43 FK_SecRel_8, ///< A eight-byte section relative fixup.
44 FK_Data_Add_1, ///< A one-byte add fixup.
45 FK_Data_Add_2, ///< A two-byte add fixup.
46 FK_Data_Add_4, ///< A four-byte add fixup.
47 FK_Data_Add_8, ///< A eight-byte add fixup.
48 FK_Data_Add_6b, ///< A six-bits add fixup.
49 FK_Data_Sub_1, ///< A one-byte sub fixup.
50 FK_Data_Sub_2, ///< A two-byte sub fixup.
51 FK_Data_Sub_4, ///< A four-byte sub fixup.
52 FK_Data_Sub_8, ///< A eight-byte sub fixup.
53 FK_Data_Sub_6b, ///< A six-bits sub fixup.
5154
5255 FirstTargetFixupKind = 128,
5356
128131
129132 /// Return the generic fixup kind for a value with the given size. It
130133 /// is an error to pass an unsupported size.
131 static MCFixupKind getKindForSize(unsigned Size, bool isPCRel) {
134 static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel) {
132135 switch (Size) {
133136 default: llvm_unreachable("Invalid generic fixup size!");
134 case 1: return isPCRel ? FK_PCRel_1 : FK_Data_1;
135 case 2: return isPCRel ? FK_PCRel_2 : FK_Data_2;
136 case 4: return isPCRel ? FK_PCRel_4 : FK_Data_4;
137 case 8: return isPCRel ? FK_PCRel_8 : FK_Data_8;
137 case 1:
138 return IsPCRel ? FK_PCRel_1 : FK_Data_1;
139 case 2:
140 return IsPCRel ? FK_PCRel_2 : FK_Data_2;
141 case 4:
142 return IsPCRel ? FK_PCRel_4 : FK_Data_4;
143 case 8:
144 return IsPCRel ? FK_PCRel_8 : FK_Data_8;
145 }
146 }
147
148 /// Return the generic fixup kind for a value with the given size in bits.
149 /// It is an error to pass an unsupported size.
150 static MCFixupKind getKindForSizeInBits(unsigned Size, bool IsPCRel) {
151 switch (Size) {
152 default:
153 llvm_unreachable("Invalid generic fixup size!");
154 case 6:
155 assert(!IsPCRel && "Invalid pc-relative fixup size!");
156 return FK_Data_6b;
157 case 8:
158 return IsPCRel ? FK_PCRel_1 : FK_Data_1;
159 case 16:
160 return IsPCRel ? FK_PCRel_2 : FK_Data_2;
161 case 32:
162 return IsPCRel ? FK_PCRel_4 : FK_Data_4;
163 case 64:
164 return IsPCRel ? FK_PCRel_8 : FK_Data_8;
138165 }
139166 }
140167
147174 case FK_Data_2: return FK_Data_Add_2;
148175 case FK_Data_4: return FK_Data_Add_4;
149176 case FK_Data_8: return FK_Data_Add_8;
177 case FK_Data_6b: return FK_Data_Add_6b;
150178 }
151179 }
152180
159187 case FK_Data_2: return FK_Data_Sub_2;
160188 case FK_Data_4: return FK_Data_Sub_4;
161189 case FK_Data_8: return FK_Data_Sub_8;
190 case FK_Data_6b: return FK_Data_Sub_6b;
162191 }
163192 }
164193
148148 case MCFragment::FT_CompactEncodedInst:
149149 case MCFragment::FT_Data:
150150 case MCFragment::FT_Dwarf:
151 case MCFragment::FT_DwarfFrame:
151152 return true;
152153 }
153154 }
231232 static bool classof(const MCFragment *F) {
232233 MCFragment::FragmentType Kind = F->getKind();
233234 return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data ||
234 Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf;;
235 Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf ||
236 Kind == MCFragment::FT_DwarfFrame;
235237 }
236238 };
237239
542544 }
543545 };
544546
545 class MCDwarfCallFrameFragment : public MCFragment {
547 class MCDwarfCallFrameFragment : public MCEncodedFragmentWithFixups<8, 1> {
546548 /// AddrDelta - The expression for the difference of the two symbols that
547549 /// make up the address delta between two .cfi_* dwarf directives.
548550 const MCExpr *AddrDelta;
549551
550 SmallString<8> Contents;
551
552552 public:
553553 MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
554 : MCFragment(FT_DwarfFrame, false, Sec), AddrDelta(&AddrDelta) {
555 Contents.push_back(0);
556 }
554 : MCEncodedFragmentWithFixups<8, 1>(FT_DwarfFrame, false, Sec),
555 AddrDelta(&AddrDelta) {}
557556
558557 /// \name Accessors
559558 /// @{
560559
561560 const MCExpr &getAddrDelta() const { return *AddrDelta; }
562
563 SmallString<8> &getContents() { return Contents; }
564 const SmallString<8> &getContents() const { return Contents; }
565561
566562 /// @}
567563
401401 }
402402
403403 if (const auto *Off = shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
404 DObj->getDebugFrameSection()))
404 DObj->getDebugFrameSection().Data))
405405 getDebugFrame()->dump(OS, getRegisterInfo(), *Off);
406406
407407 if (const auto *Off = shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
408 DObj->getEHFrameSection()))
408 DObj->getEHFrameSection().Data))
409409 getEHFrame()->dump(OS, getRegisterInfo(), *Off);
410410
411411 if (DumpType & DIDT_DebugMacro) {
765765 // provides this information). This problem is fixed in DWARFv4
766766 // See this dwarf-discuss discussion for more details:
767767 // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
768 DWARFDataExtractor debugFrameData(DObj->getDebugFrameSection(),
768 DWARFDataExtractor debugFrameData(*DObj, DObj->getDebugFrameSection(),
769769 isLittleEndian(), DObj->getAddressSize());
770770 DebugFrame.reset(new DWARFDebugFrame(getArch(), false /* IsEH */));
771771 DebugFrame->parse(debugFrameData);
776776 if (EHFrame)
777777 return EHFrame.get();
778778
779 DWARFDataExtractor debugFrameData(DObj->getEHFrameSection(), isLittleEndian(),
780 DObj->getAddressSize());
779 DWARFDataExtractor debugFrameData(*DObj, DObj->getEHFrameSection(),
780 isLittleEndian(), DObj->getAddressSize());
781781 DebugFrame.reset(new DWARFDebugFrame(getArch(), true /* IsEH */));
782782 DebugFrame->parse(debugFrameData);
783783 return DebugFrame.get();
13841384 DWARFSectionMap RnglistsSection;
13851385 DWARFSectionMap StringOffsetSection;
13861386 DWARFSectionMap LineDWOSection;
1387 DWARFSectionMap DebugFrameSection;
1388 DWARFSectionMap EHFrameSection;
13871389 DWARFSectionMap LocDWOSection;
13881390 DWARFSectionMap StringOffsetDWOSection;
13891391 DWARFSectionMap RangeDWOSection;
14041406 .Case("debug_loc", &LocSection)
14051407 .Case("debug_loclists", &LocListsSection)
14061408 .Case("debug_line", &LineSection)
1409 .Case("debug_frame", &DebugFrameSection)
1410 .Case("eh_frame", &EHFrameSection)
14071411 .Case("debug_str_offsets", &StringOffsetSection)
14081412 .Case("debug_ranges", &RangeSection)
14091413 .Case("debug_rnglists", &RnglistsSection)
14271431
14281432 StringRef AbbrevSection;
14291433 StringRef ARangeSection;
1430 StringRef DebugFrameSection;
1431 StringRef EHFrameSection;
14321434 StringRef StringSection;
14331435 StringRef MacinfoSection;
14341436 StringRef AbbrevDWOSection;
14481450 return StringSwitch(Name)
14491451 .Case("debug_abbrev", &AbbrevSection)
14501452 .Case("debug_aranges", &ARangeSection)
1451 .Case("debug_frame", &DebugFrameSection)
1452 .Case("eh_frame", &EHFrameSection)
14531453 .Case("debug_str", &StringSection)
14541454 .Case("debug_macinfo", &MacinfoSection)
14551455 .Case("debug_abbrev.dwo", &AbbrevDWOSection)
17461746 const DWARFSection &getLocSection() const override { return LocSection; }
17471747 const DWARFSection &getLoclistsSection() const override { return LocListsSection; }
17481748 StringRef getARangeSection() const override { return ARangeSection; }
1749 StringRef getDebugFrameSection() const override { return DebugFrameSection; }
1750 StringRef getEHFrameSection() const override { return EHFrameSection; }
1749 const DWARFSection &getDebugFrameSection() const override {
1750 return DebugFrameSection;
1751 }
1752 const DWARFSection &getEHFrameSection() const override {
1753 return EHFrameSection;
1754 }
17511755 const DWARFSection &getLineSection() const override { return LineSection; }
17521756 StringRef getStringSection() const override { return StringSection; }
17531757 const DWARFSection &getRangeSection() const override { return RangeSection; }
3333 const uint8_t DWARF_CFI_PRIMARY_OPCODE_MASK = 0xc0;
3434 const uint8_t DWARF_CFI_PRIMARY_OPERAND_MASK = 0x3f;
3535
36 Error CFIProgram::parse(DataExtractor Data, uint32_t *Offset,
36 Error CFIProgram::parse(DWARFDataExtractor Data, uint32_t *Offset,
3737 uint32_t EndOffset) {
3838 while (*Offset < EndOffset) {
39 uint8_t Opcode = Data.getU8(Offset);
39 uint8_t Opcode = Data.getRelocatedValue(1, Offset);
4040 // Some instructions have a primary opcode encoded in the top bits.
4141 uint8_t Primary = Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK;
4242
7373 break;
7474 case DW_CFA_set_loc:
7575 // Operands: Address
76 addInstruction(Opcode, Data.getAddress(Offset));
76 addInstruction(Opcode, Data.getRelocatedAddress(Offset));
7777 break;
7878 case DW_CFA_advance_loc1:
7979 // Operands: 1-byte delta
80 addInstruction(Opcode, Data.getU8(Offset));
80 addInstruction(Opcode, Data.getRelocatedValue(1, Offset));
8181 break;
8282 case DW_CFA_advance_loc2:
8383 // Operands: 2-byte delta
84 addInstruction(Opcode, Data.getU16(Offset));
84 addInstruction(Opcode, Data.getRelocatedValue(2, Offset));
8585 break;
8686 case DW_CFA_advance_loc4:
8787 // Operands: 4-byte delta
88 addInstruction(Opcode, Data.getU32(Offset));
88 addInstruction(Opcode, Data.getRelocatedValue(4, Offset));
8989 break;
9090 case DW_CFA_restore_extended:
9191 case DW_CFA_undefined:
360360 uint32_t StartOffset = Offset;
361361
362362 bool IsDWARF64 = false;
363 uint64_t Length = Data.getU32(&Offset);
363 uint64_t Length = Data.getRelocatedValue(4, &Offset);
364364 uint64_t Id;
365365
366366 if (Length == UINT32_MAX) {
368368 // field being 0xffffffff. Then, the next 64 bits are the actual entry
369369 // length.
370370 IsDWARF64 = true;
371 Length = Data.getU64(&Offset);
371 Length = Data.getRelocatedValue(8, &Offset);
372372 }
373373
374374 // At this point, Offset points to the next field after Length.
511511 ReportError(StartOffset, "Parsing augmentation data at %lx failed");
512512 }
513513 } else {
514 InitialLocation = Data.getAddress(&Offset);
515 AddressRange = Data.getAddress(&Offset);
514 InitialLocation = Data.getRelocatedAddress(&Offset);
515 AddressRange = Data.getRelocatedAddress(&Offset);
516516 }
517517
518518 Entries.emplace_back(new FDE(StartOffset, Length, CIEPointer,
7272 {"FK_Data_2", 0, 16, 0},
7373 {"FK_Data_4", 0, 32, 0},
7474 {"FK_Data_8", 0, 64, 0},
75 {"FK_Data_6b", 0, 6, 0},
7576 {"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
7677 {"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
7778 {"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
9293 {"FK_Data_Add_2", 0, 16, 0},
9394 {"FK_Data_Add_4", 0, 32, 0},
9495 {"FK_Data_Add_8", 0, 64, 0},
96 {"FK_Data_Add_6b", 0, 6, 0},
9597 {"FK_Data_Sub_1", 0, 8, 0},
9698 {"FK_Data_Sub_2", 0, 16, 0},
9799 {"FK_Data_Sub_4", 0, 32, 0},
98 {"FK_Data_Sub_8", 0, 64, 0}};
100 {"FK_Data_Sub_8", 0, 64, 0},
101 {"FK_Data_Sub_6b", 0, 6, 0}};
99102
100103 assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind");
101104 return Builtins[Kind];
839839 getBackend().shouldInsertFixupForCodeAlign(*this, Layout, *AF);
840840 }
841841 continue;
842 } else if (auto *FragWithFixups =
843 dyn_cast(&Frag)) {
844 Fixups = FragWithFixups->getFixups();
845 Contents = FragWithFixups->getContents();
842846 } else
843847 llvm_unreachable("Unknown fragment with fixups!");
844848 for (const MCFixup &Fixup : Fixups) {
968972 MCContext &Context = Layout.getAssembler().getContext();
969973 uint64_t OldSize = DF.getContents().size();
970974 int64_t AddrDelta;
971 bool Abs;
972 if (getBackend().requiresDiffExpressionRelocations())
973 Abs = DF.getAddrDelta().evaluateAsAbsolute(AddrDelta, Layout);
974 else {
975 Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
976 assert(Abs && "We created a line delta with an invalid expression");
977 }
975 bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
976 assert(Abs && "We created a line delta with an invalid expression");
977 (void)Abs;
978978 int64_t LineDelta;
979979 LineDelta = DF.getLineDelta();
980980 SmallVectorImpl &Data = DF.getContents();
982982 raw_svector_ostream OSE(Data);
983983 DF.getFixups().clear();
984984
985 if (Abs) {
985 if (!getBackend().requiresDiffExpressionRelocations()) {
986986 MCDwarfLineAddr::Encode(Context, getDWARFLinetableParams(), LineDelta,
987987 AddrDelta, OSE);
988988 } else {
10161016 bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
10171017 assert(Abs && "We created call frame with an invalid expression");
10181018 (void) Abs;
1019 SmallString<8> &Data = DF.getContents();
1019 SmallVectorImpl> &Data = DF.getContents();
10201020 Data.clear();
10211021 raw_svector_ostream OSE(Data);
1022 MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
1022 DF.getFixups().clear();
1023
1024 if (getBackend().requiresDiffExpressionRelocations()) {
1025 uint32_t Offset;
1026 uint32_t Size;
1027 MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE, &Offset,
1028 &Size);
1029 if (Size) {
1030 DF.getFixups().push_back(MCFixup::create(
1031 Offset, &DF.getAddrDelta(),
1032 MCFixup::getKindForSizeInBits(Size /*In bits.*/, false /*isPCRel*/)));
1033 }
1034 } else {
1035 MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
1036 }
1037
10231038 return OldSize != Data.size();
10241039 }
10251040
18961896 }
18971897
18981898 void MCDwarfFrameEmitter::EncodeAdvanceLoc(MCContext &Context,
1899 uint64_t AddrDelta,
1900 raw_ostream &OS) {
1899 uint64_t AddrDelta, raw_ostream &OS,
1900 uint32_t *Offset, uint32_t *Size) {
19011901 // Scale the address delta by the minimum instruction length.
19021902 AddrDelta = ScaleAddrDelta(Context, AddrDelta);
1903
1904 bool WithFixups = false;
1905 if (Offset && Size)
1906 WithFixups = true;
19031907
19041908 support::endianness E =
19051909 Context.getAsmInfo()->isLittleEndian() ? support::little : support::big;
19061910 if (AddrDelta == 0) {
1911 if (WithFixups) {
1912 *Offset = 0;
1913 *Size = 0;
1914 }
19071915 } else if (isUIntN(6, AddrDelta)) {
19081916 uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
1909 OS << Opcode;
1917 if (WithFixups) {
1918 *Offset = OS.tell();
1919 *Size = 6;
1920 OS << uint8_t(dwarf::DW_CFA_advance_loc);
1921 } else
1922 OS << Opcode;
19101923 } else if (isUInt<8>(AddrDelta)) {
19111924 OS << uint8_t(dwarf::DW_CFA_advance_loc1);
1912 OS << uint8_t(AddrDelta);
1925 if (WithFixups) {
1926 *Offset = OS.tell();
1927 *Size = 8;
1928 OS.write_zeros(1);
1929 } else
1930 OS << uint8_t(AddrDelta);
19131931 } else if (isUInt<16>(AddrDelta)) {
19141932 OS << uint8_t(dwarf::DW_CFA_advance_loc2);
1915 support::endian::write(OS, AddrDelta, E);
1933 if (WithFixups) {
1934 *Offset = OS.tell();
1935 *Size = 16;
1936 OS.write_zeros(2);
1937 } else
1938 support::endian::write(OS, AddrDelta, E);
19161939 } else {
19171940 assert(isUInt<32>(AddrDelta));
19181941 OS << uint8_t(dwarf::DW_CFA_advance_loc4);
1919 support::endian::write(OS, AddrDelta, E);
1920 }
1921 }
1942 if (WithFixups) {
1943 *Offset = OS.tell();
1944 *Size = 32;
1945 OS.write_zeros(4);
1946 } else
1947 support::endian::write(OS, AddrDelta, E);
1948 }
1949 }
334334 case ELF::R_RISCV_NONE:
335335 case ELF::R_RISCV_32:
336336 case ELF::R_RISCV_64:
337 case ELF::R_RISCV_SET6:
338 case ELF::R_RISCV_SUB6:
337339 case ELF::R_RISCV_ADD8:
338340 case ELF::R_RISCV_SUB8:
339341 case ELF::R_RISCV_ADD16:
357359 return (S + RA) & 0xFFFFFFFF;
358360 case ELF::R_RISCV_64:
359361 return S + RA;
362 case ELF::R_RISCV_SET6:
363 return (A + (S + RA)) & 0xFF;
364 case ELF::R_RISCV_SUB6:
365 return (A - (S + RA)) & 0xFF;
360366 case ELF::R_RISCV_ADD8:
361367 return (A + (S + RA)) & 0xFF;
362368 case ELF::R_RISCV_SUB8:
185185 case FK_Data_2:
186186 case FK_Data_4:
187187 case FK_Data_8:
188 case FK_Data_6b:
188189 return Value;
189190 case RISCV::fixup_riscv_lo12_i:
190191 case RISCV::fixup_riscv_pcrel_lo12_i:
9797 return ELF::R_RISCV_ADD32;
9898 case FK_Data_Add_8:
9999 return ELF::R_RISCV_ADD64;
100 case FK_Data_Add_6b:
101 return ELF::R_RISCV_SET6;
100102 case FK_Data_Sub_1:
101103 return ELF::R_RISCV_SUB8;
102104 case FK_Data_Sub_2:
105107 return ELF::R_RISCV_SUB32;
106108 case FK_Data_Sub_8:
107109 return ELF::R_RISCV_SUB64;
110 case FK_Data_Sub_6b:
111 return ELF::R_RISCV_SUB6;
108112 case RISCV::fixup_riscv_hi20:
109113 return ELF::R_RISCV_HI20;
110114 case RISCV::fixup_riscv_lo12_i:
1313 store i32 0, i32* %retval, align 4
1414 ; RELAX: R_RISCV_ADD64 b
1515 ; RELAX: R_RISCV_SUB64 a
16 ; NORELAX-NOT: R_RISCV
16 ; NORELAX-NOT: R_RISCV_ADD
1717 call void asm sideeffect "a:\0Ab:\0A.dword b-a", ""()
1818 ret i32 0
1919 }
55
66 ; Check that we actually have relocations, otherwise this is kind of pointless.
77 ; READOBJ-RELOCS: Section (8) .rela.debug_info {
8 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0x0
9 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 - 0x0
10 ; READOBJ-RELOCS: Section (11) .rela.debug_addr {
11 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0x0
12 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 - 0x0
8 ; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 - 0x0
9 ; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 - 0x0
10 ; READOBJ-RELOCS: Section (15) .rela.debug_frame {
11 ; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 - 0x0
12 ; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 - 0x0
1313 ; READOBJ-RELOCS: Section (17) .rela.debug_line {
14 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC
15 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 .Lline_table_start0 0x0
14 ; READOBJ-RELOCS: 0x5A R_RISCV_ADD16 - 0x0
15 ; READOBJ-RELOCS-NEXT: 0x5A R_RISCV_SUB16 - 0x0
1616
1717 ; Check that we can print the source, even with relocations.
1818 ; OBJDUMP-SOURCE: Disassembly of section .text:
0 ; RUN: llc -filetype=obj -mtriple=riscv32 -mattr=+relax %s -o - \
1 ; RUN: | llvm-readobj -r | FileCheck -check-prefix=RELAX %s
2 ; RUN: llc -filetype=obj -mtriple=riscv32 -mattr=+relax %s -o - \
3 ; RUN: | llvm-dwarfdump --debug-frame - \
4 ; RUN: | FileCheck -check-prefix=RELAX-DWARFDUMP %s
5 ;
6 ; RELAX: Section{{.*}}.rela.{{eh|debug}}_frame {
7 ; RELAX-NOT: {{[}]}}
8 ; RELAX: 0x20 R_RISCV_ADD32
9 ; RELAX: 0x20 R_RISCV_SUB32
10 ; RELAX-NOT: {{[}]}}
11 ; RELAX: 0x25 R_RISCV_SET6
12 ; RELAX: 0x25 R_RISCV_SUB6
13 ;
14 ; RELAX-DWARFDUMP: CIE
15 ; RELAX-DWARFDUMP: DW_CFA_advance_loc
16 ; RELAX-DWARFDUMP: DW_CFA_def_cfa_offset
17 ; RELAX-DWARFDUMP: DW_CFA_offset
18 ; RELAX-DWARFDUMP: DW_CFA_restore
19 source_filename = "frame.c"
20
21 ; Function Attrs: noinline nounwind optnone
22 define i32 @init() {
23 entry:
24 ret i32 0
25 }
26
27 ; Function Attrs: noinline nounwind optnone
28 define i32 @foo(i32 signext %value) {
29 entry:
30 %value.addr = alloca i32, align 4
31 store i32 %value, i32* %value.addr, align 4
32 %0 = load i32, i32* %value.addr, align 4
33 ret i32 %0
34 }
35
36 ; Function Attrs: noinline nounwind optnone
37 define i32 @bar() {
38 entry:
39 %result = alloca i32, align 4
40 %v = alloca i32, align 4
41 %call = call i32 @init()
42 store i32 %call, i32* %v, align 4
43 %0 = load i32, i32* %v, align 4
44 %call1 = call i32 @foo(i32 signext %0)
45 store i32 %call1, i32* %result, align 4
46 %1 = load i32, i32* %result, align 4
47 ret i32 %1
48 }
49
50 !llvm.dbg.cu = !{!0}
51 !llvm.module.flags = !{!3, !4, !5}
52
53 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
54 !1 = !DIFile(filename: "line.c", directory: "./")
55 !2 = !{}
56 !3 = !{i32 2, !"Dwarf Version", i32 4}
57 !4 = !{i32 2, !"Debug Info Version", i32 3}
58 !5 = !{i32 1, !"wchar_size", i32 4}
1313 # preparation for follow-on patches to fix it.
1414
1515 # RELAX-RELOC: Section (4) .rela.eh_frame {
16 # RELAX-RELOC-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC
17 # RELAX-RELOC-NEXT: 0x0 R_RISCV_SUB32 - 0x0
18 # RELAX-RELOC-NEXT: 0x14 R_RISCV_ADD32 - 0x0
19 # RELAX-RELOC-NEXT: 0x14 R_RISCV_SUB32 - 0x0
20 # RELAX-RELOC-NEXT: 0x18 R_RISCV_ADD32 - 0x0
21 # RELAX-RELOC-NEXT: 0x18 R_RISCV_SUB32 - 0x0
16 # RELAX-RELOC-NEXT: 0x0 R_RISCV_32 - 0x10
17 # RELAX-RELOC-NEXT: 0x14 R_RISCV_32 - 0x10
18 # RELAX-RELOC-NEXT: 0x18 R_RISCV_32 - 0x18
2219 # RELAX-RELOC-NEXT: 0x1C R_RISCV_ADD32 - 0x0
2320 # RELAX-RELOC-NEXT: 0x1C R_RISCV_SUB32 - 0x0
2421 # RELAX-RELOC-NEXT: 0x20 R_RISCV_ADD32 - 0x0
20022002 RangesTy &Ranges,
20032003 DWARFContext &OrigDwarf,
20042004 unsigned AddrSize) {
2005 StringRef FrameData = OrigDwarf.getDWARFObj().getDebugFrameSection();
2005 StringRef FrameData = OrigDwarf.getDWARFObj().getDebugFrameSection().Data;
20062006 if (FrameData.empty())
20072007 return;
20082008