llvm.org GIT mirror llvm / c8ecb42
Revert r347490 as it breaks address sanitizer builds git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347499 91177308-0d34-0410-b5e6-96231b3b80d8 Luke Cheeseman 10 months ago
26 changed file(s) with 81 addition(s) and 202 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 || \
21 (defined HANDLE_DW_CFA && defined HANDLE_DW_CFA_PRED) || \
20 defined HANDLE_DW_RLE || defined HANDLE_DW_CFA || \
2221 defined HANDLE_DW_APPLE_PROPERTY || defined HANDLE_DW_UT || \
2322 defined HANDLE_DWARF_SECTION || defined HANDLE_DW_IDX || \
2423 defined HANDLE_DW_END)
8382
8483 #ifndef HANDLE_DW_CFA
8584 #define HANDLE_DW_CFA(ID, NAME)
86 #endif
87
88 #ifndef HANDLE_DW_CFA_PRED
89 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
9085 #endif
9186
9287 #ifndef HANDLE_DW_APPLE_PROPERTY
835830 HANDLE_DW_CFA(0x15, val_offset_sf)
836831 HANDLE_DW_CFA(0x16, val_expression)
837832 // Vendor extensions:
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)
833 HANDLE_DW_CFA(0x1d, MIPS_advance_loc8)
834 HANDLE_DW_CFA(0x2d, GNU_window_save)
835 HANDLE_DW_CFA(0x2e, GNU_args_size)
842836
843837 // Apple Objective-C Property Attributes.
844838 // Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
921915 #undef HANDLE_DW_MACRO
922916 #undef HANDLE_DW_RLE
923917 #undef HANDLE_DW_CFA
924 #undef HANDLE_DW_CFA_PRED
925918 #undef HANDLE_DW_APPLE_PROPERTY
926919 #undef HANDLE_DW_UT
927920 #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"
2928
3029 namespace llvm {
3130 class StringRef;
272271 /// Call frame instruction encodings.
273272 enum CallFrameInfo {
274273 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
275 #define HANDLE_DW_CFA_PRED(ID, NAME, ARCH) DW_CFA_##NAME = ID,
276274 #include "llvm/BinaryFormat/Dwarf.def"
277275 DW_CFA_extended = 0x00,
278276
431429 StringRef LNExtendedString(unsigned Encoding);
432430 StringRef MacinfoString(unsigned Encoding);
433431 StringRef RangeListEncodingString(unsigned Encoding);
434 StringRef CallFrameString(unsigned Encoding, Triple::ArchType Arch);
432 StringRef CallFrameString(unsigned Encoding);
435433 StringRef ApplePropertyString(unsigned);
436434 StringRef UnitTypeString(unsigned);
437435 StringRef AtomTypeString(unsigned Atom);
8989 bool CheckedForDWP = false;
9090 std::string DWPName;
9191
92 Triple::ArchType Arch;
9392 std::unique_ptr RegInfo;
9493
9594 /// Read compile units from the debug_info section (if necessary)
351350 /// Loads register info for the architecture of the provided object file.
352351 /// Improves readability of dumped DWARF expressions. Requires the caller to
353352 /// have initialized the relevant target descriptions.
354 Error loadArchitectureInfo(const object::ObjectFile &Obj);
353 Error loadRegisterInfo(const object::ObjectFile &Obj);
355354
356355 /// Get address size from CUs.
357356 /// 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"
1615 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1716 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1817 #include "llvm/Support/Error.h"
5958 unsigned size() const { return (unsigned)Instructions.size(); }
6059 bool empty() const { return Instructions.empty(); }
6160
62 CFIProgram(uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor,
63 Triple::ArchType Arch)
61 CFIProgram(uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor)
6462 : CodeAlignmentFactor(CodeAlignmentFactor),
65 DataAlignmentFactor(DataAlignmentFactor),
66 Arch(Arch) {}
63 DataAlignmentFactor(DataAlignmentFactor) {}
6764
6865 /// Parse and store a sequence of CFI instructions from Data,
6966 /// starting at *Offset and ending at EndOffset. *Offset is updated
7875 std::vector Instructions;
7976 const uint64_t CodeAlignmentFactor;
8077 const int64_t DataAlignmentFactor;
81 Triple::ArchType Arch;
8278
8379 /// Convenience method to add a new instruction with the given opcode.
8480 void addInstruction(uint8_t Opcode) {
133129 enum FrameKind { FK_CIE, FK_FDE };
134130
135131 FrameEntry(FrameKind K, uint64_t Offset, uint64_t Length, uint64_t CodeAlign,
136 int64_t DataAlign, Triple::ArchType Arch)
137 : Kind(K), Offset(Offset), Length(Length),
138 CFIs(CodeAlign, DataAlign, Arch) {}
132 int64_t DataAlign)
133 : Kind(K), Offset(Offset), Length(Length), CFIs(CodeAlign, DataAlign) {}
139134
140135 virtual ~FrameEntry() {}
141136
172167 int64_t DataAlignmentFactor, uint64_t ReturnAddressRegister,
173168 SmallString<8> AugmentationData, uint32_t FDEPointerEncoding,
174169 uint32_t LSDAPointerEncoding, Optional Personality,
175 Optional PersonalityEnc, Triple::ArchType Arch)
170 Optional PersonalityEnc)
176171 : FrameEntry(FK_CIE, Offset, Length, CodeAlignmentFactor,
177 DataAlignmentFactor, Arch),
172 DataAlignmentFactor),
178173 Version(Version), Augmentation(std::move(Augmentation)),
179174 AddressSize(AddressSize), SegmentDescriptorSize(SegmentDescriptorSize),
180175 CodeAlignmentFactor(CodeAlignmentFactor),
228223 // is obtained lazily once it's actually required.
229224 FDE(uint64_t Offset, uint64_t Length, int64_t LinkedCIEOffset,
230225 uint64_t InitialLocation, uint64_t AddressRange, CIE *Cie,
231 Optional LSDAAddress, Triple::ArchType Arch)
226 Optional LSDAAddress)
232227 : FrameEntry(FK_FDE, Offset, Length,
233228 Cie ? Cie->getCodeAlignmentFactor() : 0,
234 Cie ? Cie->getDataAlignmentFactor() : 0,
235 Arch),
229 Cie ? Cie->getDataAlignmentFactor() : 0),
236230 LinkedCIEOffset(LinkedCIEOffset), InitialLocation(InitialLocation),
237231 AddressRange(AddressRange), LinkedCIE(Cie), LSDAAddress(LSDAAddress) {}
238232
261255
262256 /// A parsed .debug_frame or .eh_frame section
263257 class DWARFDebugFrame {
264 const Triple::ArchType Arch;
265258 // True if this is parsing an eh_frame section.
266259 const bool IsEH;
267260 // Not zero for sane pointer values coming out of eh_frame
278271 // it is a .debug_frame section. EHFrameAddress should be different
279272 // than zero for correct parsing of .eh_frame addresses when they
280273 // use a PC-relative encoding.
281 DWARFDebugFrame(Triple::ArchType Arch,
282 bool IsEH = false, uint64_t EHFrameAddress = 0);
274 DWARFDebugFrame(bool IsEH = false, uint64_t EHFrameAddress = 0);
283275 ~DWARFDebugFrame();
284276
285277 /// Dump the section data into the given stream.
429429 OpUndefined,
430430 OpRegister,
431431 OpWindowSave,
432 OpNegateRAState,
433432 OpGnuArgsSize
434433 };
435434
507506 /// .cfi_window_save SPARC register window is saved.
508507 static MCCFIInstruction createWindowSave(MCSymbol *L) {
509508 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, "");
515509 }
516510
517511 /// .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();
899898
900899 virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
901900 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"
1615 #include "llvm/Support/ErrorHandling.h"
1716
1817 using namespace llvm;
455454 }
456455 }
457456
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
457 StringRef llvm::dwarf::CallFrameString(unsigned Encoding) {
471458 switch (Encoding) {
472459 default:
473460 return StringRef();
474 #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
475461 #define HANDLE_DW_CFA(ID, NAME) \
476462 case DW_CFA_##NAME: \
477463 return "DW_CFA_" #NAME;
478464 #include "llvm/BinaryFormat/Dwarf.def"
479
480 #undef SELECT_X86
481 #undef SELECT_SPARC
482 #undef SELECT_MIPS64
483 #undef SELECT_AARCH64
484465 }
485466 }
486467
211211 case MCCFIInstruction::OpWindowSave:
212212 OutStreamer->EmitCFIWindowSave();
213213 break;
214 case MCCFIInstruction::OpNegateRAState:
215 OutStreamer->EmitCFINegateRAState();
216 break;
217214 case MCCFIInstruction::OpSameValue:
218215 OutStreamer->EmitCFISameValue(Inst.getRegister());
219216 break;
206206 case MCCFIInstruction::OpUndefined:
207207 case MCCFIInstruction::OpRegister:
208208 case MCCFIInstruction::OpWindowSave:
209 case MCCFIInstruction::OpNegateRAState:
210209 case MCCFIInstruction::OpGnuArgsSize:
211210 break;
212211 }
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)
223222 .Case("blockaddress", MIToken::kw_blockaddress)
224223 .Case("intrinsic", MIToken::kw_intrinsic)
225224 .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,
9291 kw_blockaddress,
9392 kw_intrinsic,
9493 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;
18251822 case MIToken::kw_cfi_escape: {
18261823 std::string Values;
18271824 if (parseCFIEscapeValues(Values))
21142111 case MIToken::kw_cfi_restore_state:
21152112 case MIToken::kw_cfi_undefined:
21162113 case MIToken::kw_cfi_window_save:
2117 case MIToken::kw_cfi_aarch64_negate_ra_sign_state:
21182114 return parseCFIOperand(Dest);
21192115 case MIToken::kw_blockaddress:
21202116 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;
704699 default:
705700 // TODO: Print the other CFI Operations.
706701 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(Arch, false /* IsEH */));
769 DebugFrame.reset(new DWARFDebugFrame(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(Arch, true /* IsEH */));
780 DebugFrame.reset(new DWARFDebugFrame(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 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;
1646 return llvm::make_unique(std::move(DObj), std::move(DWPName));
16511647 }
16521648
16531649 std::unique_ptr
16581654 return llvm::make_unique(std::move(DObj), "");
16591655 }
16601656
1661 Error DWARFContext::loadArchitectureInfo(const object::ObjectFile &Obj) {
1657 Error DWARFContext::loadRegisterInfo(const object::ObjectFile &Obj) {
16621658 // Detect the architecture from the object file. We usually don't need OS
16631659 // info to lookup a target and create register info.
1664 Arch = Triple::ArchType(Obj.getArch());
1665
16661660 Triple TT;
16671661 TT.setArch(Triple::ArchType(Obj.getArch()));
16681662 TT.setVendor(Triple::UnknownVendor);
224224 switch (Type) {
225225 case OT_Unset: {
226226 OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to";
227 auto OpcodeName = CallFrameString(Opcode, Arch);
227 auto OpcodeName = CallFrameString(Opcode);
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, Arch) << ":";
281 OS << CallFrameString(Opcode) << ":";
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(Triple::ArchType Arch,
328 bool IsEH, uint64_t EHFrameAddress)
329 : Arch(Arch), IsEH(IsEH), EHFrameAddress(EHFrameAddress) {}
327 DWARFDebugFrame::DWARFDebugFrame(bool IsEH, uint64_t EHFrameAddress)
328 : IsEH(IsEH), EHFrameAddress(EHFrameAddress) {}
330329
331330 DWARFDebugFrame::~DWARFDebugFrame() = default;
332331
460459 StartOffset, Length, Version, AugmentationString, AddressSize,
461460 SegmentDescriptorSize, CodeAlignmentFactor, DataAlignmentFactor,
462461 ReturnAddressRegister, AugmentationData, FDEPointerEncoding,
463 LSDAPointerEncoding, Personality, PersonalityEncoding, Arch);
462 LSDAPointerEncoding, Personality, PersonalityEncoding);
464463 CIEs[StartOffset] = Cie.get();
465464 Entries.emplace_back(std::move(Cie));
466465 } else {
512511
513512 Entries.emplace_back(new FDE(StartOffset, Length, CIEPointer,
514513 InitialLocation, AddressRange,
515 Cie, LSDAAddress, Arch));
514 Cie, LSDAAddress));
516515 }
517516
518517 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;
288287 void EmitCFIReturnColumn(int64_t Register) override;
289288
290289 void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) override;
15691568 EmitEOL();
15701569 }
15711570
1572 void MCAsmStreamer::EmitCFINegateRAState() {
1573 MCStreamer::EmitCFINegateRAState();
1574 OS << "\t.cfi_negate_ra_state";
1575 EmitEOL();
1576 }
1577
15781571 void MCAsmStreamer::EmitCFIReturnColumn(int64_t Register) {
15791572 MCStreamer::EmitCFIReturnColumn(Register);
15801573 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
13381334 case MCCFIInstruction::OpUndefined: {
13391335 unsigned Reg = Instr.getRegister();
13401336 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
588579 void MCStreamer::EmitCFIReturnColumn(int64_t Register) {
589580 MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
590581 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);
828822 }
829823
830824 // 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();
178177
179178 bool validateInstruction(MCInst &Inst, SMLoc &IDLoc,
180179 SmallVectorImpl &Loc);
50265025 parseDirectiveUnreq(Loc);
50275026 else if (IDVal == ".inst")
50285027 parseDirectiveInst(Loc);
5029 else if (IDVal == ".cfi_negate_ra_state")
5030 parseDirectiveCFINegateRAState();
50315028 else if (IsMachO) {
50325029 if (IDVal == MCLOHDirectiveName())
50335030 parseDirectiveLOH(IDVal, Loc);
53985395 Parser.Lex(); // Eat the identifier.
53995396 if (parseToken(AsmToken::EndOfStatement))
54005397 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();
54085398 return false;
54095399 }
54105400
2323 ; CHECK-LABEL: @leaf_sign_all
2424 ; CHECK: paciasp
2525 ; CHECK: autiasp
26 ; CHECK: ret
26 ; CHECK-NEXT: 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: str x30, [sp, #-16]!
33 ; CHECK-NEXT: str x30, [sp, #-16]!
3434 ; CHECK: ldr x30, [sp], #16
3535 ; CHECK-NEXT: autiasp
36 ; CHECK: ret
36 ; CHECK-NEXT: 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: ret
47 ; CHECK-NEXT: 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: str x30, [sp, #-16]!
55 ; CHECK-NEXT: str x30, [sp, #-16]!
5656 ; CHECK: ldr x30, [sp], #16
57 ; CHECK: autiasp
58 ; CHECK: ret
57 ; CHECK-NEXT: autiasp
58 ; CHECK-NEXT: 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: retaa
67 ; CHECK-NEXT: 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: str x30, [sp, #-16]!
77 ; CHECK-NEXT: str x30, [sp, #-16]!
7878 ; CHECK: ldr x30, [sp], #16
79 ; CHECK: autiasp
80 ; CHECK: b bar
79 ; CHECK-NEXT: autiasp
80 ; CHECK-NEXT: 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
4947 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 RBP)
17 # CHECK-NEXT: DW_AT_frame_base [DW_FORM_exprloc] (DW_OP_reg6)
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() + ": ");
408410 // The UUID dump already contains all the same information.
409411 if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
410412 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"
1918 #include "llvm/Support/Casting.h"
2019 #include "llvm/Support/ScopedPrinter.h"
2120 #include "llvm/Support/Debug.h"
3130 template
3231 class PrinterContext {
3332 ScopedPrinter &W;
34 const object::ELFObjectFile *ObjF;
33 const object::ELFFile *Obj;
3534
3635 void printEHFrameHdr(uint64_t Offset, uint64_t Address, uint64_t Size) const;
3736
3837 void printEHFrame(const typename ELFT::Shdr *EHFrameShdr) const;
3938
4039 public:
41 PrinterContext(ScopedPrinter &W, const object::ELFObjectFile *ObjF)
42 : W(W), ObjF(ObjF) {}
40 PrinterContext(ScopedPrinter &W, const object::ELFFile *Obj)
41 : W(W), Obj(Obj) {}
4342
4443 void printUnwindInformation() const;
4544 };
5958
6059 template
6160 void PrinterContext::printUnwindInformation() const {
62 const object::ELFFile *Obj = ObjF->getELFFile();
6361 const typename ELFT::Phdr *EHFramePhdr = nullptr;
6462
6563 auto PHs = Obj->program_headers();
102100 W.startLine() << format("Offset: 0x%" PRIx64 "\n", EHFrameHdrOffset);
103101 W.startLine() << format("Size: 0x%" PRIx64 "\n", EHFrameHdrSize);
104102
105 const object::ELFFile *Obj = ObjF->getELFFile();
106103 const auto *EHFrameHdrShdr = findSectionByAddress(Obj, EHFrameHdrAddress);
107104 if (EHFrameHdrShdr) {
108105 auto SectionName = Obj->getSectionName(EHFrameHdrShdr);
175172 ShOffset, Address);
176173 W.indent();
177174
178 const object::ELFFile *Obj = ObjF->getELFFile();
179175 auto Result = Obj->getSectionContents(EHFrameShdr);
180176 if (Error E = Result.takeError())
181177 reportError(toString(std::move(E)));
186182 Contents.size()),
187183 ELFT::TargetEndianness == support::endianness::little,
188184 ELFT::Is64Bits ? 8 : 4);
189 DWARFDebugFrame EHFrame(Triple::ArchType(ObjF->getArch()), /*IsEH=*/true,
190 /*EHFrameAddress=*/Address);
185 DWARFDebugFrame EHFrame(/*IsEH=*/true, /*EHFrameAddress=*/Address);
191186 EHFrame.parse(DE);
192187
193188 for (const auto &Entry : EHFrame) {
139139 template
140140 class ELFDumper : public ObjDumper {
141141 public:
142 ELFDumper(const object::ELFObjectFile *ObjF, ScopedPrinter &Writer);
142 ELFDumper(const ELFFile *Obj, 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();
185184 if (DRI.Addr < Obj->base() ||
186185 (const uint8_t *)DRI.Addr + DRI.Size > Obj->base() + Obj->getBufSize())
187186 error(llvm::object::object_error::parse_failed);
189188 }
190189
191190 DynRegionInfo createDRIFrom(const Elf_Phdr *P, uintX_t EntSize) {
192 return checkDRI({ObjF->getELFFile()->base() + P->p_offset, P->p_filesz, EntSize});
191 return checkDRI({Obj->base() + P->p_offset, P->p_filesz, EntSize});
193192 }
194193
195194 DynRegionInfo createDRIFrom(const Elf_Shdr *S) {
196 return checkDRI({ObjF->getELFFile()->base() + S->sh_offset, S->sh_size, S->sh_entsize});
195 return checkDRI({Obj->base() + S->sh_offset, S->sh_size, S->sh_entsize});
197196 }
198197
199198 void parseDynamicTable(ArrayRef LoadSegments);
207206 void LoadVersionNeeds(const Elf_Shdr *ec) const;
208207 void LoadVersionDefs(const Elf_Shdr *sec) const;
209208
210 const object::ELFObjectFile *ObjF;
209 const ELFO *Obj;
211210 DynRegionInfo DynRelRegion;
212211 DynRegionInfo DynRelaRegion;
213212 DynRegionInfo DynRelrRegion;
290289 StringRef StrTable, SymtabName;
291290 size_t Entries = 0;
292291 Elf_Sym_Range Syms(nullptr, nullptr);
293 const ELFFile *Obj = ObjF->getELFFile();
294292 if (IsDynamic) {
295293 StrTable = DynamicStringTable;
296294 Syms = dynamic_symbols();
480478 namespace llvm {
481479
482480 template
483 static std::error_code createELFDumper(const ELFObjectFile *Obj,
481 static std::error_code createELFDumper(const ELFFile *Obj,
484482 ScopedPrinter &Writer,
485483 std::unique_ptr &Result) {
486484 Result.reset(new ELFDumper(Obj, Writer));
492490 std::unique_ptr &Result) {
493491 // Little-endian 32-bit
494492 if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj))
495 return createELFDumper(ELFObj, Writer, Result);
493 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
496494
497495 // Big-endian 32-bit
498496 if (const ELF32BEObjectFile *ELFObj = dyn_cast(Obj))
499 return createELFDumper(ELFObj, Writer, Result);
497 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
500498
501499 // Little-endian 64-bit
502500 if (const ELF64LEObjectFile *ELFObj = dyn_cast(Obj))
503 return createELFDumper(ELFObj, Writer, Result);
501 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
504502
505503 // Big-endian 64-bit
506504 if (const ELF64BEObjectFile *ELFObj = dyn_cast(Obj))
507 return createELFDumper(ELFObj, Writer, Result);
505 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
508506
509507 return readobj_error::unsupported_obj_file_format;
510508 }
517515 void ELFDumper::LoadVersionNeeds(const Elf_Shdr *sec) const {
518516 unsigned vn_size = sec->sh_size; // Size of section in bytes
519517 unsigned vn_count = sec->sh_info; // Number of Verneed entries
520 const char *sec_start = (const char *)ObjF->getELFFile()->base() + sec->sh_offset;
518 const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
521519 const char *sec_end = sec_start + vn_size;
522520 // The first Verneed entry is at the start of the section.
523521 const char *p = sec_start;
551549 void ELFDumper::LoadVersionDefs(const Elf_Shdr *sec) const {
552550 unsigned vd_size = sec->sh_size; // Size of section in bytes
553551 unsigned vd_count = sec->sh_info; // Number of Verdef entries
554 const char *sec_start = (const char *)ObjF->getELFFile()->base() + sec->sh_offset;
552 const char *sec_start = (const char *)Obj->base() + sec->sh_offset;
555553 const char *sec_end = sec_start + vd_size;
556554 // The first Verdef entry is at the start of the section.
557555 const char *p = sec_start;
729727
730728 template void ELFDumper::printVersionInfo() {
731729 // Dump version symbol section.
732 printVersionSymbolSection(this, ObjF->getELFFile(), dot_gnu_version_sec, W);
730 printVersionSymbolSection(this, Obj, dot_gnu_version_sec, W);
733731
734732 // Dump version definition section.
735 printVersionDefinitionSection(this, ObjF->getELFFile(), dot_gnu_version_d_sec, W);
733 printVersionDefinitionSection(this, Obj, dot_gnu_version_d_sec, W);
736734
737735 // Dump version dependency section.
738 printVersionDependencySection(this, ObjF->getELFFile(), dot_gnu_version_r_sec, W);
736 printVersionDependencySection(this, Obj, dot_gnu_version_r_sec, W);
739737 }
740738
741739 template
756754
757755 // Get the corresponding version index entry
758756 const Elf_Versym *vs = unwrapOrError(
759 ObjF->getELFFile()->template getEntry(dot_gnu_version_sec, entry_index));
757 Obj->template getEntry(dot_gnu_version_sec, entry_index));
760758 size_t version_index = vs->vs_index & ELF::VERSYM_VERSION;
761759
762760 // Special markers for unversioned symbols.
789787
790788 template
791789 StringRef ELFDumper::getStaticSymbolName(uint32_t Index) const {
792 const ELFFile *Obj = ObjF->getELFFile();
793790 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*DotSymtabSec));
794791 Elf_Sym_Range Syms = unwrapOrError(Obj->symbols(DotSymtabSec));
795792 if (Index >= Syms.size())
837834 if (SectionIndex == SHN_XINDEX)
838835 SectionIndex = unwrapOrError(object::getExtendedSymbolTableIndex(
839836 Symbol, FirstSym, ShndxTable));
840 const ELFFile *Obj = ObjF->getELFFile();
841837 const typename ELFT::Shdr *Sec =
842838 unwrapOrError(Obj->getSection(SectionIndex));
843839 SectionName = unwrapOrError(Obj->getSectionName(Sec));
14101406 }
14111407
14121408 template
1413 ELFDumper::ELFDumper(const object::ELFObjectFile *ObjF,
1414 ScopedPrinter &Writer)
1415 : ObjDumper(Writer), ObjF(ObjF) {
1409 ELFDumper::ELFDumper(const ELFFile *Obj, ScopedPrinter &Writer)
1410 : ObjDumper(Writer), Obj(Obj) {
14161411 SmallVector LoadSegments;
1417 const ELFFile *Obj = ObjF->getELFFile();
14181412 for (const Elf_Phdr &Phdr : unwrapOrError(Obj->program_headers())) {
14191413 if (Phdr.p_type == ELF::PT_DYNAMIC) {
14201414 DynamicTable = createDRIFrom(&Phdr, sizeof(Elf_Dyn));
14951489 uint64_t Delta = VAddr - Phdr.p_vaddr;
14961490 if (Delta >= Phdr.p_filesz)
14971491 report_fatal_error("Virtual address is not in any segment");
1498 return ObjF->getELFFile()->base() + Phdr.p_offset + Delta;
1492 return Obj->base() + Phdr.p_offset + Delta;
14991493 };
15001494
15011495 uint64_t SONameOffset = 0;
15941588
15951589 template
15961590 void ELFDumper::printFileHeaders() {
1597 ELFDumperStyle->printFileHeaders(ObjF->getELFFile());
1598 }
1599
1600 template
1601 void ELFDumper::printSectionHeaders() {
1602 ELFDumperStyle->printSectionHeaders(ObjF->getELFFile());
1591 ELFDumperStyle->printFileHeaders(Obj);
1592 }
1593
1594 template void ELFDumper::printSectionHeaders() {
1595 ELFDumperStyle->printSectionHeaders(Obj);
16031596 }
16041597
16051598 template
16061599 void ELFDumper::printRelocations() {
1607 ELFDumperStyle->printRelocations(ObjF->getELFFile());
1600 ELFDumperStyle->printRelocations(Obj);
16081601 }
16091602
16101603 template void ELFDumper::printProgramHeaders() {
1611 ELFDumperStyle->printProgramHeaders(ObjF->getELFFile());
1604 ELFDumperStyle->printProgramHeaders(Obj);
16121605 }
16131606
16141607 template void ELFDumper::printDynamicRelocations() {
1615 ELFDumperStyle->printDynamicRelocations(ObjF->getELFFile());
1608 ELFDumperStyle->printDynamicRelocations(Obj);
16161609 }
16171610
16181611 template
16191612 void ELFDumper::printSymbols() {
1620 ELFDumperStyle->printSymbols(ObjF->getELFFile());
1613 ELFDumperStyle->printSymbols(Obj);
16211614 }
16221615
16231616 template
16241617 void ELFDumper::printDynamicSymbols() {
1625 ELFDumperStyle->printDynamicSymbols(ObjF->getELFFile());
1618 ELFDumperStyle->printDynamicSymbols(Obj);
16261619 }
16271620
16281621 template void ELFDumper::printHashHistogram() {
1629 ELFDumperStyle->printHashHistogram(ObjF->getELFFile());
1622 ELFDumperStyle->printHashHistogram(Obj);
16301623 }
16311624
16321625 template void ELFDumper::printCGProfile() {
1633 ELFDumperStyle->printCGProfile(ObjF->getELFFile());
1626 ELFDumperStyle->printCGProfile(Obj);
16341627 }
16351628
16361629 template void ELFDumper::printNotes() {
1637 ELFDumperStyle->printNotes(ObjF->getELFFile());
1630 ELFDumperStyle->printNotes(Obj);
16381631 }
16391632
16401633 template void ELFDumper::printELFLinkerOptions() {
1641 ELFDumperStyle->printELFLinkerOptions(ObjF->getELFFile());
1634 ELFDumperStyle->printELFLinkerOptions(Obj);
16421635 }
16431636
16441637 static const char *getTypeString(unsigned Arch, uint64_t Type) {
18821875
18831876 template
18841877 void ELFDumper::printUnwindInfo() {
1885 const unsigned Machine = ObjF->getELFFile()->getHeader()->e_machine;
1878 const unsigned Machine = Obj->getHeader()->e_machine;
18861879 if (Machine == EM_386 || Machine == EM_X86_64) {
1887 DwarfCFIEH::PrinterContext Ctx(W, ObjF);
1880 DwarfCFIEH::PrinterContext Ctx(W, Obj);
18881881 return Ctx.printUnwindInformation();
18891882 }
18901883 W.startLine() << "UnwindInfo not implemented.\n";
18931886 namespace {
18941887
18951888 template <> void ELFDumper::printUnwindInfo() {
1896 const ELFFile *Obj = ObjF->getELFFile();
18971889 const unsigned Machine = Obj->getHeader()->e_machine;
18981890 if (Machine == EM_ARM) {
18991891 ARM::EHABI::PrinterContext Ctx(W, Obj, DotSymtabSec);
19361928 uintX_t Tag = Entry.getTag();
19371929 ++I;
19381930 W.startLine() << " " << format_hex(Tag, Is64 ? 18 : 10, opts::Output != opts::GNU) << " "
1939 << format("%-21s", getTypeString(ObjF->getELFFile()->getHeader()->e_machine, Tag));
1931 << format("%-21s", getTypeString(Obj->getHeader()->e_machine, Tag));
19401932 printValue(Tag, Entry.getVal());
19411933 OS << "\n";
19421934 }
20031995 namespace {
20041996
20051997 template <> void ELFDumper::printAttributes() {
2006 const ELFFile *Obj = ObjF->getELFFile();
20071998 if (Obj->getHeader()->e_machine != EM_ARM) {
20081999 W.startLine() << "Attributes not implemented.\n";
20092000 return;
22892280 }
22902281
22912282 template void ELFDumper::printMipsPLTGOT() {
2292 const ELFFile *Obj = ObjF->getELFFile();
22932283 if (Obj->getHeader()->e_machine != EM_MIPS)
22942284 reportError("MIPS PLT GOT is available for MIPS targets only");
22952285
23742364 }
23752365
23762366 template void ELFDumper::printMipsABIFlags() {
2377 const ELFFile *Obj = ObjF->getELFFile();
23782367 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.abiflags");
23792368 if (!Shdr) {
23802369 W.startLine() << "There is no .MIPS.abiflags section in the file.\n";
24202409 }
24212410
24222411 template void ELFDumper::printMipsReginfo() {
2423 const ELFFile *Obj = ObjF->getELFFile();
24242412 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".reginfo");
24252413 if (!Shdr) {
24262414 W.startLine() << "There is no .reginfo section in the file.\n";
24382426 }
24392427
24402428 template void ELFDumper::printMipsOptions() {
2441 const ELFFile *Obj = ObjF->getELFFile();
24422429 const Elf_Shdr *Shdr = findSectionByName(*Obj, ".MIPS.options");
24432430 if (!Shdr) {
24442431 W.startLine() << "There is no .MIPS.options section in the file.\n";
24682455 }
24692456
24702457 template void ELFDumper::printStackMap() const {
2471 const ELFFile *Obj = ObjF->getELFFile();
24722458 const Elf_Shdr *StackMapSection = nullptr;
24732459 for (const auto &Sec : unwrapOrError(Obj->sections())) {
24742460 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
24892475 }
24902476
24912477 template void ELFDumper::printGroupSections() {
2492 ELFDumperStyle->printGroupSections(ObjF->getELFFile());
2478 ELFDumperStyle->printGroupSections(Obj);
24932479 }
24942480
24952481 template void ELFDumper::printAddrsig() {
2496 ELFDumperStyle->printAddrsig(ObjF->getELFFile());
2482 ELFDumperStyle->printAddrsig(Obj);
24972483 }
24982484
24992485 static inline void printFields(formatted_raw_ostream &OS, StringRef Str1,