llvm.org GIT mirror llvm / 1b3d4c8
Revert "[DebugInfo] Generate fixups as emitting DWARF .debug_frame/.eh_frame." This reverts commit 17e3cbf5fe656483d9016d0ba9e1d0cd8629379e. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366444 91177308-0d34-0410-b5e6-96231b3b80d8 Hsiangkai Wang a month ago
18 changed file(s) with 103 addition(s) and 246 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(DWARFDataExtractor Data, uint32_t *Offset, uint32_t EndOffset);
71 Error parse(DataExtractor 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 const DWARFSection &getDebugFrameSection() const { return Dummy; }
43 virtual const DWARFSection &getEHFrameSection() const { return Dummy; }
42 virtual StringRef getDebugFrameSection() const { return ""; }
43 virtual StringRef getEHFrameSection() const { return ""; }
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, uint32_t *Offset = nullptr,
632 uint32_t *Size = nullptr);
631 raw_ostream &OS);
633632 };
634633
635634 } // 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_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.
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.
5451
5552 FirstTargetFixupKind = 128,
5653
131128
132129 /// Return the generic fixup kind for a value with the given size. It
133130 /// is an error to pass an unsupported size.
134 static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel) {
131 static MCFixupKind getKindForSize(unsigned Size, bool isPCRel) {
135132 switch (Size) {
136133 default: llvm_unreachable("Invalid generic fixup size!");
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;
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;
165138 }
166139 }
167140
174147 case FK_Data_2: return FK_Data_Add_2;
175148 case FK_Data_4: return FK_Data_Add_4;
176149 case FK_Data_8: return FK_Data_Add_8;
177 case FK_Data_6b: return FK_Data_Add_6b;
178150 }
179151 }
180152
187159 case FK_Data_2: return FK_Data_Sub_2;
188160 case FK_Data_4: return FK_Data_Sub_4;
189161 case FK_Data_8: return FK_Data_Sub_8;
190 case FK_Data_6b: return FK_Data_Sub_6b;
191162 }
192163 }
193164
148148 case MCFragment::FT_CompactEncodedInst:
149149 case MCFragment::FT_Data:
150150 case MCFragment::FT_Dwarf:
151 case MCFragment::FT_DwarfFrame:
152151 return true;
153152 }
154153 }
232231 static bool classof(const MCFragment *F) {
233232 MCFragment::FragmentType Kind = F->getKind();
234233 return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data ||
235 Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf ||
236 Kind == MCFragment::FT_DwarfFrame;
234 Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf;;
237235 }
238236 };
239237
544542 }
545543 };
546544
547 class MCDwarfCallFrameFragment : public MCEncodedFragmentWithFixups<8, 1> {
545 class MCDwarfCallFrameFragment : public MCFragment {
548546 /// AddrDelta - The expression for the difference of the two symbols that
549547 /// make up the address delta between two .cfi_* dwarf directives.
550548 const MCExpr *AddrDelta;
551549
550 SmallString<8> Contents;
551
552552 public:
553553 MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
554 : MCEncodedFragmentWithFixups<8, 1>(FT_DwarfFrame, false, Sec),
555 AddrDelta(&AddrDelta) {}
554 : MCFragment(FT_DwarfFrame, false, Sec), AddrDelta(&AddrDelta) {
555 Contents.push_back(0);
556 }
556557
557558 /// \name Accessors
558559 /// @{
559560
560561 const MCExpr &getAddrDelta() const { return *AddrDelta; }
562
563 SmallString<8> &getContents() { return Contents; }
564 const SmallString<8> &getContents() const { return Contents; }
561565
562566 /// @}
563567
401401 }
402402
403403 if (const auto *Off = shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
404 DObj->getDebugFrameSection().Data))
404 DObj->getDebugFrameSection()))
405405 getDebugFrame()->dump(OS, getRegisterInfo(), *Off);
406406
407407 if (const auto *Off = shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
408 DObj->getEHFrameSection().Data))
408 DObj->getEHFrameSection()))
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, DObj->getDebugFrameSection(),
768 DWARFDataExtractor debugFrameData(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, DObj->getEHFrameSection(),
780 isLittleEndian(), DObj->getAddressSize());
779 DWARFDataExtractor debugFrameData(DObj->getEHFrameSection(), isLittleEndian(),
780 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;
13891387 DWARFSectionMap LocDWOSection;
13901388 DWARFSectionMap StringOffsetDWOSection;
13911389 DWARFSectionMap RangeDWOSection;
14061404 .Case("debug_loc", &LocSection)
14071405 .Case("debug_loclists", &LocListsSection)
14081406 .Case("debug_line", &LineSection)
1409 .Case("debug_frame", &DebugFrameSection)
1410 .Case("eh_frame", &EHFrameSection)
14111407 .Case("debug_str_offsets", &StringOffsetSection)
14121408 .Case("debug_ranges", &RangeSection)
14131409 .Case("debug_rnglists", &RnglistsSection)
14311427
14321428 StringRef AbbrevSection;
14331429 StringRef ARangeSection;
1430 StringRef DebugFrameSection;
1431 StringRef EHFrameSection;
14341432 StringRef StringSection;
14351433 StringRef MacinfoSection;
14361434 StringRef AbbrevDWOSection;
14501448 return StringSwitch(Name)
14511449 .Case("debug_abbrev", &AbbrevSection)
14521450 .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 const DWARFSection &getDebugFrameSection() const override {
1750 return DebugFrameSection;
1751 }
1752 const DWARFSection &getEHFrameSection() const override {
1753 return EHFrameSection;
1754 }
1749 StringRef getDebugFrameSection() const override { return DebugFrameSection; }
1750 StringRef getEHFrameSection() const override { return EHFrameSection; }
17551751 const DWARFSection &getLineSection() const override { return LineSection; }
17561752 StringRef getStringSection() const override { return StringSection; }
17571753 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(DWARFDataExtractor Data, uint32_t *Offset,
36 Error CFIProgram::parse(DataExtractor Data, uint32_t *Offset,
3737 uint32_t EndOffset) {
3838 while (*Offset < EndOffset) {
39 uint8_t Opcode = Data.getRelocatedValue(1, Offset);
39 uint8_t Opcode = Data.getU8(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.getRelocatedAddress(Offset));
76 addInstruction(Opcode, Data.getAddress(Offset));
7777 break;
7878 case DW_CFA_advance_loc1:
7979 // Operands: 1-byte delta
80 addInstruction(Opcode, Data.getRelocatedValue(1, Offset));
80 addInstruction(Opcode, Data.getU8(Offset));
8181 break;
8282 case DW_CFA_advance_loc2:
8383 // Operands: 2-byte delta
84 addInstruction(Opcode, Data.getRelocatedValue(2, Offset));
84 addInstruction(Opcode, Data.getU16(Offset));
8585 break;
8686 case DW_CFA_advance_loc4:
8787 // Operands: 4-byte delta
88 addInstruction(Opcode, Data.getRelocatedValue(4, Offset));
88 addInstruction(Opcode, Data.getU32(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.getRelocatedValue(4, &Offset);
363 uint64_t Length = Data.getU32(&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.getRelocatedValue(8, &Offset);
371 Length = Data.getU64(&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.getRelocatedAddress(&Offset);
515 AddressRange = Data.getRelocatedAddress(&Offset);
514 InitialLocation = Data.getAddress(&Offset);
515 AddressRange = Data.getAddress(&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},
7675 {"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
7776 {"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
7877 {"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
9392 {"FK_Data_Add_2", 0, 16, 0},
9493 {"FK_Data_Add_4", 0, 32, 0},
9594 {"FK_Data_Add_8", 0, 64, 0},
96 {"FK_Data_Add_6b", 0, 6, 0},
9795 {"FK_Data_Sub_1", 0, 8, 0},
9896 {"FK_Data_Sub_2", 0, 16, 0},
9997 {"FK_Data_Sub_4", 0, 32, 0},
100 {"FK_Data_Sub_8", 0, 64, 0},
101 {"FK_Data_Sub_6b", 0, 6, 0}};
98 {"FK_Data_Sub_8", 0, 64, 0}};
10299
103100 assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind");
104101 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();
846842 } else
847843 llvm_unreachable("Unknown fragment with fixups!");
848844 for (const MCFixup &Fixup : Fixups) {
972968 MCContext &Context = Layout.getAssembler().getContext();
973969 uint64_t OldSize = DF.getContents().size();
974970 int64_t AddrDelta;
975 bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
976 assert(Abs && "We created a line delta with an invalid expression");
977 (void)Abs;
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 }
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 (!getBackend().requiresDiffExpressionRelocations()) {
985 if (Abs) {
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 SmallVectorImpl> &Data = DF.getContents();
1019 SmallString<8> &Data = DF.getContents();
10201020 Data.clear();
10211021 raw_svector_ostream OSE(Data);
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
1022 MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
10381023 return OldSize != Data.size();
10391024 }
10401025
18961896 }
18971897
18981898 void MCDwarfFrameEmitter::EncodeAdvanceLoc(MCContext &Context,
1899 uint64_t AddrDelta, raw_ostream &OS,
1900 uint32_t *Offset, uint32_t *Size) {
1899 uint64_t AddrDelta,
1900 raw_ostream &OS) {
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;
19071903
19081904 support::endianness E =
19091905 Context.getAsmInfo()->isLittleEndian() ? support::little : support::big;
19101906 if (AddrDelta == 0) {
1911 if (WithFixups) {
1912 *Offset = 0;
1913 *Size = 0;
1914 }
19151907 } else if (isUIntN(6, AddrDelta)) {
19161908 uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
1917 if (WithFixups) {
1918 *Offset = OS.tell();
1919 *Size = 6;
1920 OS << uint8_t(dwarf::DW_CFA_advance_loc);
1921 } else
1922 OS << Opcode;
1909 OS << Opcode;
19231910 } else if (isUInt<8>(AddrDelta)) {
19241911 OS << uint8_t(dwarf::DW_CFA_advance_loc1);
1925 if (WithFixups) {
1926 *Offset = OS.tell();
1927 *Size = 8;
1928 OS.write_zeros(1);
1929 } else
1930 OS << uint8_t(AddrDelta);
1912 OS << uint8_t(AddrDelta);
19311913 } else if (isUInt<16>(AddrDelta)) {
19321914 OS << uint8_t(dwarf::DW_CFA_advance_loc2);
1933 if (WithFixups) {
1934 *Offset = OS.tell();
1935 *Size = 16;
1936 OS.write_zeros(2);
1937 } else
1938 support::endian::write(OS, AddrDelta, E);
1915 support::endian::write(OS, AddrDelta, E);
19391916 } else {
19401917 assert(isUInt<32>(AddrDelta));
19411918 OS << uint8_t(dwarf::DW_CFA_advance_loc4);
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 }
1919 support::endian::write(OS, AddrDelta, E);
1920 }
1921 }
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:
339337 case ELF::R_RISCV_ADD8:
340338 case ELF::R_RISCV_SUB8:
341339 case ELF::R_RISCV_ADD16:
359357 return (S + RA) & 0xFFFFFFFF;
360358 case ELF::R_RISCV_64:
361359 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;
366360 case ELF::R_RISCV_ADD8:
367361 return (A + (S + RA)) & 0xFF;
368362 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:
189188 return Value;
190189 case RISCV::fixup_riscv_lo12_i:
191190 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;
102100 case FK_Data_Sub_1:
103101 return ELF::R_RISCV_SUB8;
104102 case FK_Data_Sub_2:
107105 return ELF::R_RISCV_SUB32;
108106 case FK_Data_Sub_8:
109107 return ELF::R_RISCV_SUB64;
110 case FK_Data_Sub_6b:
111 return ELF::R_RISCV_SUB6;
112108 case RISCV::fixup_riscv_hi20:
113109 return ELF::R_RISCV_HI20;
114110 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_ADD
16 ; NORELAX-NOT: R_RISCV
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: 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
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
1313 ; READOBJ-RELOCS: Section (17) .rela.debug_line {
14 ; READOBJ-RELOCS: 0x5A R_RISCV_ADD16 - 0x0
15 ; READOBJ-RELOCS-NEXT: 0x5A R_RISCV_SUB16 - 0x0
14 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC
15 ; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 .Lline_table_start0 0x0
1616
1717 ; Check that we can print the source, even with relocations.
1818 ; OBJDUMP-SOURCE: Disassembly of section .text:
+0
-59
test/DebugInfo/RISCV/relax-debug-frame.ll less more
None ; 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_32 - 0x10
17 # RELAX-RELOC-NEXT: 0x14 R_RISCV_32 - 0x10
18 # RELAX-RELOC-NEXT: 0x18 R_RISCV_32 - 0x18
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
1922 # RELAX-RELOC-NEXT: 0x1C R_RISCV_ADD32 - 0x0
2023 # RELAX-RELOC-NEXT: 0x1C R_RISCV_SUB32 - 0x0
2124 # RELAX-RELOC-NEXT: 0x20 R_RISCV_ADD32 - 0x0
20022002 RangesTy &Ranges,
20032003 DWARFContext &OrigDwarf,
20042004 unsigned AddrSize) {
2005 StringRef FrameData = OrigDwarf.getDWARFObj().getDebugFrameSection().Data;
2005 StringRef FrameData = OrigDwarf.getDWARFObj().getDebugFrameSection();
20062006 if (FrameData.empty())
20072007 return;
20082008