llvm.org GIT mirror llvm / 7ef46a7
Revert r343341 - Cannot reproduce the build failure locally and the build logs have been deleted. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347490 91177308-0d34-0410-b5e6-96231b3b80d8 Luke Cheeseman 10 months ago
26 changed file(s) with 202 addition(s) and 81 deletion(s). Raw diff Collapse all Expand all
1717 defined HANDLE_DW_VIRTUALITY || defined HANDLE_DW_DEFAULTED || \
1818 defined HANDLE_DW_CC || defined HANDLE_DW_LNS || defined HANDLE_DW_LNE || \
1919 defined HANDLE_DW_LNCT || defined HANDLE_DW_MACRO || \
20 defined HANDLE_DW_RLE || defined HANDLE_DW_CFA || \
20 defined HANDLE_DW_RLE || \
21 (defined HANDLE_DW_CFA && defined HANDLE_DW_CFA_PRED) || \
2122 defined HANDLE_DW_APPLE_PROPERTY || defined HANDLE_DW_UT || \
2223 defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX || \
2324 defined HANDLE_DW_END)
8283
8384 #ifndef HANDLE_DW_CFA
8485 #define HANDLE_DW_CFA(ID, NAME)
86 #endif
87
88 #ifndef HANDLE_DW_CFA_PRED
89 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
8590 #endif
8691
8792 #ifndef HANDLE_DW_APPLE_PROPERTY
830835 HANDLE_DW_CFA(0x15, val_offset_sf)
831836 HANDLE_DW_CFA(0x16, val_expression)
832837 // Vendor extensions:
833 HANDLE_DW_CFA(0x1d, MIPS_advance_loc8)
834 HANDLE_DW_CFA(0x2d, GNU_window_save)
835 HANDLE_DW_CFA(0x2e, GNU_args_size)
838 HANDLE_DW_CFA_PRED(0x1d, MIPS_advance_loc8, SELECT_MIPS64)
839 HANDLE_DW_CFA_PRED(0x2d, GNU_window_save, SELECT_SPARC)
840 HANDLE_DW_CFA_PRED(0x2d, AARCH64_negate_ra_state, SELECT_AARCH64)
841 HANDLE_DW_CFA_PRED(0x2e, GNU_args_size, SELECT_X86)
836842
837843 // Apple Objective-C Property Attributes.
838844 // Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
915921 #undef HANDLE_DW_MACRO
916922 #undef HANDLE_DW_RLE
917923 #undef HANDLE_DW_CFA
924 #undef HANDLE_DW_CFA_PRED
918925 #undef HANDLE_DW_APPLE_PROPERTY
919926 #undef HANDLE_DW_UT
920927 #undef HANDLE_DWARF_SECTION
2525 #include "llvm/Support/ErrorHandling.h"
2626 #include "llvm/Support/Format.h"
2727 #include "llvm/Support/FormatVariadicDetails.h"
28 #include "llvm/ADT/Triple.h"
2829
2930 namespace llvm {
3031 class StringRef;
271272 /// Call frame instruction encodings.
272273 enum CallFrameInfo {
273274 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
275 #define HANDLE_DW_CFA_PRED(ID, NAME, ARCH) DW_CFA_##NAME = ID,
274276 #include "llvm/BinaryFormat/Dwarf.def"
275277 DW_CFA_extended = 0x00,
276278
429431 StringRef LNExtendedString(unsigned Encoding);
430432 StringRef MacinfoString(unsigned Encoding);
431433 StringRef RangeListEncodingString(unsigned Encoding);
432 StringRef CallFrameString(unsigned Encoding);
434 StringRef CallFrameString(unsigned Encoding, Triple::ArchType Arch);
433435 StringRef ApplePropertyString(unsigned);
434436 StringRef UnitTypeString(unsigned);
435437 StringRef AtomTypeString(unsigned Atom);
8989 bool CheckedForDWP = false;
9090 std::string DWPName;
9191
92 Triple::ArchType Arch;
9293 std::unique_ptr RegInfo;
9394
9495 /// Read compile units from the debug_info section (if necessary)
350351 /// Loads register info for the architecture of the provided object file.
351352 /// Improves readability of dumped DWARF expressions. Requires the caller to
352353 /// have initialized the relevant target descriptions.
353 Error loadRegisterInfo(const object::ObjectFile &Obj);
354 Error loadArchitectureInfo(const object::ObjectFile &Obj);
354355
355356 /// Get address size from CUs.
356357 /// TODO: refactor compile_units() to make this const.
1212 #include "llvm/ADT/ArrayRef.h"
1313 #include "llvm/ADT/iterator.h"
1414 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/Triple.h"
1516 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1617 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1718 #include "llvm/Support/Error.h"
5859 unsigned size() const { return (unsigned)Instructions.size(); }
5960 bool empty() const { return Instructions.empty(); }
6061
61 CFIProgram(uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor)
62 CFIProgram(uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor,
63 Triple::ArchType Arch)
6264 : CodeAlignmentFactor(CodeAlignmentFactor),
63 DataAlignmentFactor(DataAlignmentFactor) {}
65 DataAlignmentFactor(DataAlignmentFactor),
66 Arch(Arch) {}
6467
6568 /// Parse and store a sequence of CFI instructions from Data,
6669 /// starting at *Offset and ending at EndOffset. *Offset is updated
7578 std::vector Instructions;
7679 const uint64_t CodeAlignmentFactor;
7780 const int64_t DataAlignmentFactor;
81 Triple::ArchType Arch;
7882
7983 /// Convenience method to add a new instruction with the given opcode.
8084 void addInstruction(uint8_t Opcode) {
129133 enum FrameKind { FK_CIE, FK_FDE };
130134
131135 FrameEntry(FrameKind K, uint64_t Offset, uint64_t Length, uint64_t CodeAlign,
132 int64_t DataAlign)
133 : Kind(K), Offset(Offset), Length(Length), CFIs(CodeAlign, DataAlign) {}
136 int64_t DataAlign, Triple::ArchType Arch)
137 : Kind(K), Offset(Offset), Length(Length),
138 CFIs(CodeAlign, DataAlign, Arch) {}
134139
135140 virtual ~FrameEntry() {}
136141
167172 int64_t DataAlignmentFactor, uint64_t ReturnAddressRegister,
168173 SmallString<8> AugmentationData, uint32_t FDEPointerEncoding,
169174 uint32_t LSDAPointerEncoding, Optional Personality,
170 Optional PersonalityEnc)
175 Optional PersonalityEnc, Triple::ArchType Arch)
171176 : FrameEntry(FK_CIE, Offset, Length, CodeAlignmentFactor,
172 DataAlignmentFactor),
177 DataAlignmentFactor, Arch),
173178 Version(Version), Augmentation(std::move(Augmentation)),
174179 AddressSize(AddressSize), SegmentDescriptorSize(SegmentDescriptorSize),
175180 CodeAlignmentFactor(CodeAlignmentFactor),
223228 // is obtained lazily once it's actually required.
224229 FDE(uint64_t Offset, uint64_t Length, int64_t LinkedCIEOffset,
225230 uint64_t InitialLocation, uint64_t AddressRange, CIE *Cie,
226 Optional LSDAAddress)
231 Optional LSDAAddress, Triple::ArchType Arch)
227232 : FrameEntry(FK_FDE, Offset, Length,
228233 Cie ? Cie->getCodeAlignmentFactor() : 0,
229 Cie ? Cie->getDataAlignmentFactor() : 0),
234 Cie ? Cie->getDataAlignmentFactor() : 0,
235 Arch),
230236 LinkedCIEOffset(LinkedCIEOffset), InitialLocation(InitialLocation),
231237 AddressRange(AddressRange), LinkedCIE(Cie), LSDAAddress(LSDAAddress) {}
232238
255261
256262 /// A parsed .debug_frame or .eh_frame section
257263 class DWARFDebugFrame {
264 const Triple::ArchType Arch;
258265 // True if this is parsing an eh_frame section.
259266 const bool IsEH;
260267 // Not zero for sane pointer values coming out of eh_frame
271278 // it is a .debug_frame section. EHFrameAddress should be different
272279 // than zero for correct parsing of .eh_frame addresses when they
273280 // use a PC-relative encoding.
274 DWARFDebugFrame(bool IsEH = false, uint64_t EHFrameAddress = 0);
281 DWARFDebugFrame(Triple::ArchType Arch,
282 bool IsEH = false, uint64_t EHFrameAddress = 0);
275283 ~DWARFDebugFrame();
276284
277285 /// Dump the section data into the given stream.
429429 OpUndefined,
430430 OpRegister,
431431 OpWindowSave,
432 OpNegateRAState,
432433 OpGnuArgsSize
433434 };
434435
506507 /// .cfi_window_save SPARC register window is saved.
507508 static MCCFIInstruction createWindowSave(MCSymbol *L) {
508509 return MCCFIInstruction(OpWindowSave, L, 0, 0, "");
510 }
511
512 /// .cfi_negate_ra_state AArch64 negate RA state.
513 static MCCFIInstruction createNegateRAState(MCSymbol *L) {
514 return MCCFIInstruction(OpNegateRAState, L, 0, 0, "");
509515 }
510516
511517 /// .cfi_restore says that the rule for Register is now the same as it
895895 virtual void EmitCFIUndefined(int64_t Register);
896896 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
897897 virtual void EmitCFIWindowSave();
898 virtual void EmitCFINegateRAState();
898899
899900 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
900901 virtual void EmitWinCFIEndProc(SMLoc Loc = SMLoc());
1212
1313 #include "llvm/BinaryFormat/Dwarf.h"
1414 #include "llvm/ADT/StringSwitch.h"
15 #include "llvm/ADT/Triple.h"
1516 #include "llvm/Support/ErrorHandling.h"
1617
1718 using namespace llvm;
454455 }
455456 }
456457
457 StringRef llvm::dwarf::CallFrameString(unsigned Encoding) {
458 StringRef llvm::dwarf::CallFrameString(unsigned Encoding,
459 Triple::ArchType Arch) {
460 assert(Arch != llvm::Triple::ArchType::UnknownArch);
461 #define SELECT_AARCH64 (Arch == llvm::Triple::aarch64_be || Arch == llvm::Triple::aarch64)
462 #define SELECT_MIPS64 Arch == llvm::Triple::mips64
463 #define SELECT_SPARC (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9)
464 #define SELECT_X86 (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
465 #define HANDLE_DW_CFA(ID, NAME)
466 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED) \
467 if (ID == Encoding && PRED) \
468 return "DW_CFA_" #NAME;
469 #include "llvm/BinaryFormat/Dwarf.def"
470
458471 switch (Encoding) {
459472 default:
460473 return StringRef();
474 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
461475 #define HANDLE_DW_CFA(ID, NAME) \
462476 case DW_CFA_##NAME: \
463477 return "DW_CFA_" #NAME;
464478 #include "llvm/BinaryFormat/Dwarf.def"
479
480 #undef SELECT_X86
481 #undef SELECT_SPARC
482 #undef SELECT_MIPS64
483 #undef SELECT_AARCH64
465484 }
466485 }
467486
211211 case MCCFIInstruction::OpWindowSave:
212212 OutStreamer->EmitCFIWindowSave();
213213 break;
214 case MCCFIInstruction::OpNegateRAState:
215 OutStreamer->EmitCFINegateRAState();
216 break;
214217 case MCCFIInstruction::OpSameValue:
215218 OutStreamer->EmitCFISameValue(Inst.getRegister());
216219 break;
206206 case MCCFIInstruction::OpUndefined:
207207 case MCCFIInstruction::OpRegister:
208208 case MCCFIInstruction::OpWindowSave:
209 case MCCFIInstruction::OpNegateRAState:
209210 case MCCFIInstruction::OpGnuArgsSize:
210211 break;
211212 }
219219 .Case("undefined", MIToken::kw_cfi_undefined)
220220 .Case("register", MIToken::kw_cfi_register)
221221 .Case("window_save", MIToken::kw_cfi_window_save)
222 .Case("negate_ra_sign_state", MIToken::kw_cfi_aarch64_negate_ra_sign_state)
222223 .Case("blockaddress", MIToken::kw_blockaddress)
223224 .Case("intrinsic", MIToken::kw_intrinsic)
224225 .Case("target-index", MIToken::kw_target_index)
8888 kw_cfi_restore_state,
8989 kw_cfi_undefined,
9090 kw_cfi_window_save,
91 kw_cfi_aarch64_negate_ra_sign_state,
9192 kw_blockaddress,
9293 kw_intrinsic,
9394 kw_target_index,
18191819 case MIToken::kw_cfi_window_save:
18201820 CFIIndex = MF.addFrameInst(MCCFIInstruction::createWindowSave(nullptr));
18211821 break;
1822 case MIToken::kw_cfi_aarch64_negate_ra_sign_state:
1823 CFIIndex = MF.addFrameInst(MCCFIInstruction::createNegateRAState(nullptr));
1824 break;
18221825 case MIToken::kw_cfi_escape: {
18231826 std::string Values;
18241827 if (parseCFIEscapeValues(Values))
21112114 case MIToken::kw_cfi_restore_state:
21122115 case MIToken::kw_cfi_undefined:
21132116 case MIToken::kw_cfi_window_save:
2117 case MIToken::kw_cfi_aarch64_negate_ra_sign_state:
21142118 return parseCFIOperand(Dest);
21152119 case MIToken::kw_blockaddress:
21162120 return parseBlockAddressOperand(Dest);
696696 if (MCSymbol *Label = CFI.getLabel())
697697 MachineOperand::printSymbol(OS, *Label);
698698 break;
699 case MCCFIInstruction::OpNegateRAState:
700 OS << "negate_ra_sign_state ";
701 if (MCSymbol *Label = CFI.getLabel())
702 MachineOperand::printSymbol(OS, *Label);
703 break;
699704 default:
700705 // TODO: Print the other CFI Operations.
701706 OS << "";
766766 // http://lists.dwarfstd.org/htdig.cgi/dwarf-discuss-dwarfstd.org/2011-December/001173.html
767767 DWARFDataExtractor debugFrameData(DObj->getDebugFrameSection(),
768768 isLittleEndian(), DObj->getAddressSize());
769 DebugFrame.reset(new DWARFDebugFrame(false /* IsEH */));
769 DebugFrame.reset(new DWARFDebugFrame(Arch, false /* IsEH */));
770770 DebugFrame->parse(debugFrameData);
771771 return DebugFrame.get();
772772 }
777777
778778 DWARFDataExtractor debugFrameData(DObj->getEHFrameSection(), isLittleEndian(),
779779 DObj->getAddressSize());
780 DebugFrame.reset(new DWARFDebugFrame(true /* IsEH */));
780 DebugFrame.reset(new DWARFDebugFrame(Arch, true /* IsEH */));
781781 DebugFrame->parse(debugFrameData);
782782 return DebugFrame.get();
783783 }
16431643 function_ref HandleError,
16441644 std::string DWPName) {
16451645 auto DObj = llvm::make_unique(Obj, L, HandleError);
1646 return llvm::make_unique(std::move(DObj), std::move(DWPName));
1646 std::unique_ptr Ctx =
1647 llvm::make_unique(std::move(DObj), std::move(DWPName));
1648 logAllUnhandledErrors(Ctx->loadArchitectureInfo(Obj), errs(),
1649 Obj.getFileName() + ": ");
1650 return Ctx;
16471651 }
16481652
16491653 std::unique_ptr
16541658 return llvm::make_unique(std::move(DObj), "");
16551659 }
16561660
1657 Error DWARFContext::loadRegisterInfo(const object::ObjectFile &Obj) {
1661 Error DWARFContext::loadArchitectureInfo(const object::ObjectFile &Obj) {
16581662 // Detect the architecture from the object file. We usually don't need OS
16591663 // info to lookup a target and create register info.
1664 Arch = Triple::ArchType(Obj.getArch());
1665
16601666 Triple TT;
16611667 TT.setArch(Triple::ArchType(Obj.getArch()));
16621668 TT.setVendor(Triple::UnknownVendor);
224224 switch (Type) {
225225 case OT_Unset: {
226226 OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to";
227 auto OpcodeName = CallFrameString(Opcode);
227 auto OpcodeName = CallFrameString(Opcode, Arch);
228228 if (!OpcodeName.empty())
229229 OS << " " << OpcodeName;
230230 else
278278 if (Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK)
279279 Opcode &= DWARF_CFI_PRIMARY_OPCODE_MASK;
280280 OS.indent(2 * IndentLevel);
281 OS << CallFrameString(Opcode) << ":";
281 OS << CallFrameString(Opcode, Arch) << ":";
282282 for (unsigned i = 0; i < Instr.Ops.size(); ++i)
283283 printOperand(OS, MRI, IsEH, Instr, i, Instr.Ops[i]);
284284 OS << '\n';
324324 OS << "\n";
325325 }
326326
327 DWARFDebugFrame::DWARFDebugFrame(bool IsEH, uint64_t EHFrameAddress)
328 : IsEH(IsEH), EHFrameAddress(EHFrameAddress) {}
327 DWARFDebugFrame::DWARFDebugFrame(Triple::ArchType Arch,
328 bool IsEH, uint64_t EHFrameAddress)
329 : Arch(Arch), IsEH(IsEH), EHFrameAddress(EHFrameAddress) {}
329330
330331 DWARFDebugFrame::~DWARFDebugFrame() = default;
331332
459460 StartOffset, Length, Version, AugmentationString, AddressSize,
460461 SegmentDescriptorSize, CodeAlignmentFactor, DataAlignmentFactor,
461462 ReturnAddressRegister, AugmentationData, FDEPointerEncoding,
462 LSDAPointerEncoding, Personality, PersonalityEncoding);
463 LSDAPointerEncoding, Personality, PersonalityEncoding, Arch);
463464 CIEs[StartOffset] = Cie.get();
464465 Entries.emplace_back(std::move(Cie));
465466 } else {
511512
512513 Entries.emplace_back(new FDE(StartOffset, Length, CIEPointer,
513514 InitialLocation, AddressRange,
514 Cie, LSDAAddress));
515 Cie, LSDAAddress, Arch));
515516 }
516517
517518 if (Error E =
284284 void EmitCFIUndefined(int64_t Register) override;
285285 void EmitCFIRegister(int64_t Register1, int64_t Register2) override;
286286 void EmitCFIWindowSave() override;
287 void EmitCFINegateRAState() override;
287288 void EmitCFIReturnColumn(int64_t Register) override;
288289
289290 void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
15681569 EmitEOL();
15691570 }
15701571
1572 void MCAsmStreamer::EmitCFINegateRAState() {
1573 MCStreamer::EmitCFINegateRAState();
1574 OS << "\t.cfi_negate_ra_state";
1575 EmitEOL();
1576 }
1577
15711578 void MCAsmStreamer::EmitCFIReturnColumn(int64_t Register) {
15721579 MCStreamer::EmitCFIReturnColumn(Register);
15731580 OS << "\t.cfi_return_column " << Register;
13311331 Streamer.EmitIntValue(dwarf::DW_CFA_GNU_window_save, 1);
13321332 return;
13331333
1334 case MCCFIInstruction::OpNegateRAState:
1335 Streamer.EmitIntValue(dwarf::DW_CFA_AARCH64_negate_ra_state, 1);
1336 return;
1337
13341338 case MCCFIInstruction::OpUndefined: {
13351339 unsigned Reg = Instr.getRegister();
13361340 Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1);
576576 CurFrame->Instructions.push_back(Instruction);
577577 }
578578
579 void MCStreamer::EmitCFINegateRAState() {
580 MCSymbol *Label = EmitCFILabel();
581 MCCFIInstruction Instruction = MCCFIInstruction::createNegateRAState(Label);
582 MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
583 if (!CurFrame)
584 return;
585 CurFrame->Instructions.push_back(Instruction);
586 }
587
579588 void MCStreamer::EmitCFIReturnColumn(int64_t Register) {
580589 MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
581590 if (!CurFrame)
819819 MBB, MBBI, DL,
820820 TII->get(ShouldSignWithAKey(MF) ? AArch64::PACIASP : AArch64::PACIBSP))
821821 .setMIFlag(MachineInstr::FrameSetup);
822
823 unsigned CFIIndex =
824 MF.addFrameInst(MCCFIInstruction::createNegateRAState(nullptr));
825 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
826 .addCFIIndex(CFIIndex)
827 .setMIFlags(MachineInstr::FrameSetup);
822828 }
823829
824830 // All calls are tail calls in GHC calling conv, and functions have no
174174
175175 bool parseDirectiveReq(StringRef Name, SMLoc L);
176176 bool parseDirectiveUnreq(SMLoc L);
177 bool parseDirectiveCFINegateRAState();
177178
178179 bool validateInstruction(MCInst &Inst, SMLoc &IDLoc,
179180 SmallVectorImpl &Loc);
50255026 parseDirectiveUnreq(Loc);
50265027 else if (IDVal == ".inst")
50275028 parseDirectiveInst(Loc);
5029 else if (IDVal == ".cfi_negate_ra_state")
5030 parseDirectiveCFINegateRAState();
50285031 else if (IsMachO) {
50295032 if (IDVal == MCLOHDirectiveName())
50305033 parseDirectiveLOH(IDVal, Loc);
53955398 Parser.Lex(); // Eat the identifier.
53965399 if (parseToken(AsmToken::EndOfStatement))
53975400 return addErrorSuffix("in '.unreq' directive");
5401 return false;
5402 }
5403
5404 bool AArch64AsmParser::parseDirectiveCFINegateRAState() {
5405 if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
5406 return true;
5407 getStreamer().EmitCFINegateRAState();
53985408 return false;
53995409 }
54005410
2323 ; CHECK-LABEL: @leaf_sign_all
2424 ; CHECK: paciasp
2525 ; CHECK: autiasp
26 ; CHECK-NEXT: ret
26 ; CHECK: ret
2727 define i32 @leaf_sign_all(i32 %x) "sign-return-address"="all" {
2828 ret i32 %x
2929 }
3030
3131 ; CHECK: @leaf_clobbers_lr
3232 ; CHECK: paciasp
33 ; CHECK-NEXT: str x30, [sp, #-16]!
33 ; CHECK: str x30, [sp, #-16]!
3434 ; CHECK: ldr x30, [sp], #16
3535 ; CHECK-NEXT: autiasp
36 ; CHECK-NEXT: ret
36 ; CHECK: ret
3737 define i64 @leaf_clobbers_lr(i64 %x) "sign-return-address"="non-leaf" {
3838 call void asm sideeffect "mov x30, $0", "r,~{lr}"(i64 %x) #1
3939 ret i64 %x
4444 ; CHECK: @non_leaf_sign_all
4545 ; CHECK: paciasp
4646 ; CHECK: autiasp
47 ; CHECK-NEXT: ret
47 ; CHECK: ret
4848 define i32 @non_leaf_sign_all(i32 %x) "sign-return-address"="all" {
4949 %call = call i32 @foo(i32 %x)
5050 ret i32 %call
5252
5353 ; CHECK: @non_leaf_sign_non_leaf
5454 ; CHECK: paciasp
55 ; CHECK-NEXT: str x30, [sp, #-16]!
55 ; CHECK: str x30, [sp, #-16]!
5656 ; CHECK: ldr x30, [sp], #16
57 ; CHECK-NEXT: autiasp
58 ; CHECK-NEXT: ret
57 ; CHECK: autiasp
58 ; CHECK: ret
5959 define i32 @non_leaf_sign_non_leaf(i32 %x) "sign-return-address"="non-leaf" {
6060 %call = call i32 @foo(i32 %x)
6161 ret i32 %call
6464 ; CHECK-LABEL: @leaf_sign_all_v83
6565 ; CHECK: paciasp
6666 ; CHECK-NOT: ret
67 ; CHECK-NEXT: retaa
67 ; CHECK: retaa
6868 ; CHECK-NOT: ret
6969 define i32 @leaf_sign_all_v83(i32 %x) "sign-return-address"="all" "target-features"="+v8.3a" {
7070 ret i32 %x
7474
7575 ; CHECK-LABEL: @spill_lr_and_tail_call
7676 ; CHECK: paciasp
77 ; CHECK-NEXT: str x30, [sp, #-16]!
77 ; CHECK: str x30, [sp, #-16]!
7878 ; CHECK: ldr x30, [sp], #16
79 ; CHECK-NEXT: autiasp
80 ; CHECK-NEXT: b bar
79 ; CHECK: autiasp
80 ; CHECK: b bar
8181 define fastcc void @spill_lr_and_tail_call(i64 %x) "sign-return-address"="all" {
8282 call void asm sideeffect "mov x30, $0", "r,~{lr}"(i64 %x) #1
8383 tail call fastcc i64 @bar(i64 %x)
4444 ; CHECK: CFI_INSTRUCTION escape 0x61, 0x62, 0x63
4545 CFI_INSTRUCTION window_save
4646 ; CHECK: CFI_INSTRUCTION window_save
47 CFI_INSTRUCTION negate_ra_sign_state
48 ; CHECK: CFI_INSTRUCTION negate_ra_sign_state
4749 RET_ReallyLR
1414 # CHECK-NEXT: 0x0000002b: DW_TAG_subprogram [2] *
1515 # CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
1616 # CHECK-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000016)
17 # CHECK-NEXT: DW_AT_frame_base [DW_FORM_exprloc] (DW_OP_reg6)
17 # CHECK-NEXT: DW_AT_frame_base [DW_FORM_exprloc] (DW_OP_reg6 RBP)
1818 # CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000061] = "main")
1919 # CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1] (0x01)
2020 # CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1] (1)
405405
406406 static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
407407 raw_ostream &OS) {
408 logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
409 Filename.str() + ": ");
410408 // The UUID dump already contains all the same information.
411409 if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
412410 OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';
1515 #include "llvm/BinaryFormat/Dwarf.h"
1616 #include "llvm/Object/ELF.h"
1717 #include "llvm/Object/ELFTypes.h"
18 #include "llvm/Object/ELFObjectFile.h"
1819 #include "llvm/Support/Casting.h"
1920 #include "llvm/Support/ScopedPrinter.h"
2021 #include "llvm/Support/Debug.h"
3031 template
3132 class PrinterContext {
3233 ScopedPrinter &W;
33 const object::ELFFile *Obj;
34 const object::ELFObjectFile *ObjF;
3435
3536 void printEHFrameHdr(uint64_t Offset, uint64_t Address, uint64_t Size) const;
3637
3738 void printEHFrame(const typename ELFT::Shdr *EHFrameShdr) const;
3839
3940 public:
40 PrinterContext(ScopedPrinter &W, const object::ELFFile *Obj)
41 : W(W), Obj(Obj) {}
41 PrinterContext(ScopedPrinter &W, const object::ELFObjectFile *ObjF)
42 : W(W), ObjF(ObjF) {}
4243
4344 void printUnwindInformation() const;
4445 };
5859
5960 template
6061 void PrinterContext::printUnwindInformation() const {
62 const object::ELFFile *Obj = ObjF->getELFFile();
6163 const typename ELFT::Phdr *EHFramePhdr = nullptr;
6264
6365 auto PHs = Obj->program_headers();
100102 W.startLine() << format("Offset: 0x%" PRIx64 "\n", EHFrameHdrOffset);
101103 W.startLine() << format("Size: 0x%" PRIx64 "\n", EHFrameHdrSize);
102104
105 const object::ELFFile *Obj = ObjF->getELFFile();
103106 const auto *EHFrameHdrShdr = findSectionByAddress(Obj, EHFrameHdrAddress);
104107 if (EHFrameHdrShdr) {
105108 auto SectionName = Obj->getSectionName(EHFrameHdrShdr);
172175 ShOffset, Address);
173176 W.indent();
174177
178 const object::ELFFile *Obj = ObjF->getELFFile();
175179 auto Result = Obj->getSectionContents(EHFrameShdr);
176180 if (Error E = Result.takeError())
177181 reportError(toString(std::move(E)));
182186 Contents.size()),
183187 ELFT::TargetEndianness == support::endianness::little,
184188 ELFT::Is64Bits ? 8 : 4);
185 DWARFDebugFrame EHFrame(/*IsEH=*/true, /*EHFrameAddress=*/Address);
189 DWARFDebugFrame EHFrame(Triple::ArchType(ObjF->getArch()), /*IsEH=*/true,
190 /*EHFrameAddress=*/Address);
186191 EHFrame.parse(DE);
187192
188193 for (const auto &Entry : EHFrame) {
139139 template
140140 class ELFDumper : public ObjDumper {
141141 public:
142 ELFDumper(const ELFFile *Obj, ScopedPrinter &Writer);
142 ELFDumper(const object::ELFObjectFile *ObjF, ScopedPrinter &Writer);
143143
144144 void printFileHeaders() override;
145145 void printSectionHeaders() override;
181181 TYPEDEF_ELF_TYPES(ELFT)
182182
183183 DynRegionInfo checkDRI(DynRegionInfo DRI) {
184 const ELFFile *Obj = ObjF->getELFFile();
184185 if (DRI.Addr < Obj->base() ||
185186 (const uint8_t *)DRI.Addr + DRI.Size > Obj->base() + Obj->getBufSize())
186187 error(llvm::object::object_error::parse_failed);
188189 }
189190
190191 DynRegionInfo createDRIFrom(const Elf_Phdr *P, uintX_t EntSize) {
191 return checkDRI({Obj->base() + P->p_offset, P->p_filesz, EntSize});
192 return checkDRI({ObjF->getELFFile()->base() + P->p_offset, P->p_filesz, EntSize});
192193 }
193194
194195 DynRegionInfo createDRIFrom(const Elf_Shdr *S) {
195 return checkDRI({Obj->base() + S->sh_offset, S->sh_size, S->sh_entsize});
196 return checkDRI({ObjF->getELFFile()->base() + S->sh_offset, S->sh_size, S->sh_entsize});
196197 }
197198
198199 void parseDynamicTable(ArrayRef LoadSegments);
206207 void LoadVersionNeeds(const Elf_Shdr *ec) const;
207208 void LoadVersionDefs(const Elf_Shdr *sec) const;
208209
209 const ELFO *Obj;
210 const object::ELFObjectFile *ObjF;
210211 DynRegionInfo DynRelRegion;
211212 DynRegionInfo DynRelaRegion;
212213 DynRegionInfo DynRelrRegion;
289290 StringRef StrTable, SymtabName;
290291 size_t Entries = 0;
291292 Elf_Sym_Range Syms(nullptr, nullptr);
293 const ELFFile *Obj = ObjF->getELFFile();
292294 if (IsDynamic) {
293295 StrTable = DynamicStringTable;
294296 Syms = dynamic_symbols();
478480 namespace llvm {
479481
480482 template
481 static std::error_code createELFDumper(const ELFFile *Obj,
483 static std::error_code createELFDumper(const ELFObjectFile *Obj,
482484 ScopedPrinter &Writer,
483485 std::unique_ptr &Result) {
484486 Result.reset(new ELFDumper(Obj, Writer));
490492 std::unique_ptr &Result) {
491493 // Little-endian 32-bit
492494 if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj))
493 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
495 return createELFDumper(ELFObj, Writer, Result);
494496
495497 // Big-endian 32-bit
496498 if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj))
497 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
499 return createELFDumper(ELFObj, Writer, Result);
498500
499501 // Little-endian 64-bit
500502 if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj))
501 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
503 return createELFDumper(ELFObj, Writer, Result);
502504
503505 // Big-endian 64-bit
504506 if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj))
505 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
507 return createELFDumper(ELFObj, Writer, Result);
506508
507509 return readobj_error::unsupported_obj_file_format;
508510 }
515517 void ELFDumper::LoadVersionNeeds(const Elf_Shdr *sec) const {
516518 unsigned vn_size = sec->sh_size; // Size of section in bytes
517519 unsigned vn_count = sec->sh_info; // Number of Verneed entries
518 const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
520 const char *sec_start = (const char *)ObjF->getELFFile()->base() + sec->sh_offset;
519521 const char *sec_end = sec_start + vn_size;
520522 // The first Verneed entry is at the start of the section.
521523 const char *p = sec_start;
549551 void ELFDumper::LoadVersionDefs(const Elf_Shdr *sec) const {
550552 unsigned vd_size = sec->sh_size; // Size of section in bytes
551553 unsigned vd_count = sec->sh_info; // Number of Verdef entries
552 const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
554 const char *sec_start = (const char *)ObjF->getELFFile()->base() + sec->sh_offset;
553555 const char *sec_end = sec_start + vd_size;
554556 // The first Verdef entry is at the start of the section.
555557 const char *p = sec_start;
727729
728730 template void ELFDumper::printVersionInfo() {
729731 // Dump version symbol section.
730 printVersionSymbolSection(this, Obj, dot_gnu_version_sec, W);
732 printVersionSymbolSection(this, ObjF->getELFFile(), dot_gnu_version_sec, W);
731733
732734 // Dump version definition section.
733 printVersionDefinitionSection(this, Obj, dot_gnu_version_d_sec, W);
735 printVersionDefinitionSection(this, ObjF->getELFFile(), dot_gnu_version_d_sec, W);
734736
735737 // Dump version dependency section.
736 printVersionDependencySection(this, Obj, dot_gnu_version_r_sec, W);
738 printVersionDependencySection(this, ObjF->getELFFile(), dot_gnu_version_r_sec, W);
737739 }
738740
739741 template
754756
755757 // Get the corresponding version index entry
756758 const Elf_Versym *vs = unwrapOrError(
757 Obj->template getEntry(dot_gnu_version_sec, entry_index));
759 ObjF->getELFFile()->template getEntry(dot_gnu_version_sec, entry_index));
758760 size_t version_index = vs->vs_index & ELF::VERSYM_VERSION;
759761
760762 // Special markers for unversioned symbols.
787789
788790 template
789791 StringRef ELFDumper::getStaticSymbolName(uint32_t Index) const {
792 const ELFFile *Obj = ObjF->getELFFile();
790793 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*DotSymtabSec));
791794 Elf_Sym_Range Syms = unwrapOrError(Obj->symbols(DotSymtabSec));
792795 if (Index >= Syms.size())
834837 if (SectionIndex == SHN_XINDEX)
835838 SectionIndex = unwrapOrError(object::getExtendedSymbolTableIndex(
836839 Symbol, FirstSym, ShndxTable));
840 const ELFFile *Obj = ObjF->getELFFile();
837841 const typename ELFT::Shdr *Sec =
838842 unwrapOrError(Obj->getSection(SectionIndex));
839843 SectionName = unwrapOrError(Obj->getSectionName(Sec));
14061410 }
14071411
14081412 template
1409 ELFDumper::ELFDumper(const ELFFile *Obj, ScopedPrinter &Writer)
1410 : ObjDumper(Writer), Obj(Obj) {
1413 ELFDumper::ELFDumper(const object::ELFObjectFile *ObjF,
1414 ScopedPrinter &Writer)
1415 : ObjDumper(Writer), ObjF(ObjF) {
14111416 SmallVector LoadSegments;
1417 const ELFFile *Obj = ObjF->getELFFile();
14121418 for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
14131419 if (Phdr.p_type == ELF::PT_DYNAMIC) {
14141420 DynamicTable = createDRIFrom(&Phdr, sizeof(Elf_Dyn));
14891495 uint64_t Delta = VAddr - Phdr.p_vaddr;
14901496 if (Delta >= Phdr.p_filesz)
14911497 report_fatal_error("Virtual address is not in any segment");
1492 return Obj->base() + Phdr.p_offset + Delta;
1498 return ObjF->getELFFile()->base() + Phdr.p_offset + Delta;
14931499 };
14941500
14951501 uint64_t SONameOffset = 0;
15881594
15891595 template
15901596 void ELFDumper::printFileHeaders() {
1591 ELFDumperStyle->printFileHeaders(Obj);
1592 }
1593
1594 template void ELFDumper::printSectionHeaders() {
1595 ELFDumperStyle->printSectionHeaders(Obj);
1597 ELFDumperStyle->printFileHeaders(ObjF->getELFFile());
1598 }
1599
1600 template
1601 void ELFDumper::printSectionHeaders() {
1602 ELFDumperStyle->printSectionHeaders(ObjF->getELFFile());
15961603 }
15971604
15981605 template
15991606 void ELFDumper::printRelocations() {
1600 ELFDumperStyle->printRelocations(Obj);
1607 ELFDumperStyle->printRelocations(ObjF->getELFFile());
16011608 }
16021609
16031610 template void ELFDumper::printProgramHeaders() {
1604 ELFDumperStyle->printProgramHeaders(Obj);
1611 ELFDumperStyle->printProgramHeaders(ObjF->getELFFile());
16051612 }
16061613
16071614 template void ELFDumper::printDynamicRelocations() {
1608 ELFDumperStyle->printDynamicRelocations(Obj);
1615 ELFDumperStyle->printDynamicRelocations(ObjF->getELFFile());
16091616 }
16101617
16111618 template
16121619 void ELFDumper::printSymbols() {
1613 ELFDumperStyle->printSymbols(Obj);
1620 ELFDumperStyle->printSymbols(ObjF->getELFFile());
16141621 }
16151622
16161623 template
16171624 void ELFDumper::printDynamicSymbols() {
1618 ELFDumperStyle->printDynamicSymbols(Obj);
1625 ELFDumperStyle->printDynamicSymbols(ObjF->getELFFile());
16191626 }
16201627
16211628 template void ELFDumper::printHashHistogram() {
1622 ELFDumperStyle->printHashHistogram(Obj);
1629 ELFDumperStyle->printHashHistogram(ObjF->getELFFile());
16231630 }
16241631
16251632 template void ELFDumper::printCGProfile() {
1626 ELFDumperStyle->printCGProfile(Obj);
1633 ELFDumperStyle->printCGProfile(ObjF->getELFFile());
16271634 }
16281635
16291636 template void ELFDumper::printNotes() {
1630 ELFDumperStyle->printNotes(Obj);
1637 ELFDumperStyle->printNotes(ObjF->getELFFile());
16311638 }
16321639
16331640 template void ELFDumper::printELFLinkerOptions() {
1634 ELFDumperStyle->printELFLinkerOptions(Obj);
1641 ELFDumperStyle->printELFLinkerOptions(ObjF->getELFFile());
16351642 }
16361643
16371644 static const char *getTypeString(unsigned Arch, uint64_t Type) {
18751882
18761883 template
18771884 void ELFDumper::printUnwindInfo() {
1878 const unsigned Machine = Obj->getHeader()->e_machine;
1885 const unsigned Machine = ObjF->getELFFile()->getHeader()->e_machine;
18791886 if (Machine == EM_386 || Machine == EM_X86_64) {
1880 DwarfCFIEH::PrinterContext Ctx(W, Obj);
1887 DwarfCFIEH::PrinterContext Ctx(W, ObjF);
18811888 return Ctx.printUnwindInformation();
18821889 }
18831890 W.startLine() << "UnwindInfo not implemented.\n";
18861893 namespace {
18871894
18881895 template <> void ELFDumper::printUnwindInfo() {
1896 const ELFFile *Obj = ObjF->getELFFile();
18891897 const unsigned Machine = Obj->getHeader()->e_machine;
18901898 if (Machine == EM_ARM) {
18911899 ARM::EHABI::PrinterContext Ctx(W, Obj, DotSymtabSec);
19281936 uintX_t Tag = Entry.getTag();
19291937 ++I;
19301938 W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, opts::Output != opts::GNU) << " "
1931 << format("%-21s", getTypeString(Obj->getHeader()->e_machine, Tag));
1939 << format("%-21s", getTypeString(ObjF->getELFFile()->getHeader()->e_machine, Tag));
19321940 printValue(Tag, Entry.getVal());
19331941 OS << "\n";
19341942 }
19952003 namespace {
19962004
19972005 template <> void ELFDumper::printAttributes() {
2006 const ELFFile *Obj = ObjF->getELFFile();
19982007 if (Obj->getHeader()->e_machine != EM_ARM) {
19992008 W.startLine() << "Attributes not implemented.\n";
20002009 return;
22802289 }
22812290
22822291 template void ELFDumper::printMipsPLTGOT() {
2292 const ELFFile *Obj = ObjF->getELFFile();
22832293 if (Obj->getHeader()->e_machine != EM_MIPS)
22842294 reportError("MIPS PLT GOT is available for MIPS targets only");
22852295
23642374 }
23652375
23662376 template void ELFDumper::printMipsABIFlags() {
2377 const ELFFile *Obj = ObjF->getELFFile();
23672378 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.abiflags");
23682379 if (!Shdr) {
23692380 W.startLine() << "There is no .MIPS.abiflags section in the file.\n";
24092420 }
24102421
24112422 template void ELFDumper::printMipsReginfo() {
2423 const ELFFile *Obj = ObjF->getELFFile();
24122424 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo");
24132425 if (!Shdr) {
24142426 W.startLine() << "There is no .reginfo section in the file.\n";
24262438 }
24272439
24282440 template void ELFDumper::printMipsOptions() {
2441 const ELFFile *Obj = ObjF->getELFFile();
24292442 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.options");
24302443 if (!Shdr) {
24312444 W.startLine() << "There is no .MIPS.options section in the file.\n";
24552468 }
24562469
24572470 template void ELFDumper::printStackMap() const {
2471 const ELFFile *Obj = ObjF->getELFFile();
24582472 const Elf_Shdr *StackMapSection = nullptr;
24592473 for (const auto &Sec : unwrapOrError(Obj->sections())) {
24602474 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
24752489 }
24762490
24772491 template void ELFDumper::printGroupSections() {
2478 ELFDumperStyle->printGroupSections(Obj);
2492 ELFDumperStyle->printGroupSections(ObjF->getELFFile());
24792493 }
24802494
24812495 template void ELFDumper::printAddrsig() {
2482 ELFDumperStyle->printAddrsig(Obj);
2496 ELFDumperStyle->printAddrsig(ObjF->getELFFile());
24832497 }
24842498
24852499 static inline void printFields(formatted_raw_ostream &OS, StringRef Str1,