aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCDwarf.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-08-12[MCDwarf] Use emplace to avoid move assignment. NFCFangrui Song1-1/+1
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata1-4/+3
2022-06-12[MC][re-land] Omit DWARF unwind info if compact unwind is present where eligibleJez Ng1-2/+1
This reverts commit d941d597837d9e1405086f008c9bd6a71e7263c9. Differential Revision: https://reviews.llvm.org/D122258
2022-06-12Revert "[MC] Omit DWARF unwind info if compact unwind is present where eligible"Jez Ng1-1/+2
This reverts commit ef501bf85d8c869248e51371f0e74bcec0e7b229.
2022-06-12[MC] Omit DWARF unwind info if compact unwind is present where eligibleJez Ng1-2/+1
Previously, omitting unnecessary DWARF unwinds was only done in two cases: * For Darwin + aarch64, if no DWARF unwind info is needed for all the functions in a TU, then the `__eh_frame` section would be omitted entirely. If any one function needed DWARF unwind, then MC would emit DWARF unwind entries for all the functions in the TU. * For watchOS, MC would omit DWARF unwind on a per-function basis, as long as compact unwind was available for that function. This diff makes it so that we omit DWARF unwind on a per-function basis for Darwin + aarch64 as well. In addition, we introduce the flag `--emit-dwarf-unwind=` which can toggle between `always`, `no-compact-unwind` (only emit DWARF when CU cannot be emitted for a given function), and the target platform `default`. `no-compact-unwind` is particularly useful for newer x86_64 platforms: we don't want to omit DWARF unwind for x86_64 in general due to possible backwards compat issues, but we should make it possible for people to opt into this behavior if they are only targeting newer platforms. **Motivation:** I'm working on adding support for `__eh_frame` to LLD, but I'm concerned that we would suffer a perf hit. Processing compact unwind is already expensive, and that's a simpler format than EH frames. Given that MC currently produces one EH frame entry for every compact unwind entry, I don't think processing them will be cheap. I tried to do something clever on LLD's end to drop the unnecessary EH frames at parse time, but this made the code significantly more complex. So I'm looking at fixing this at the MC level instead. **Addendum:** It turns out that there was a latent bug in the X86 backend when `OmitDwarfIfHaveCompactUnwind` is naively enabled, which is not too surprising given that this combination has not been heretofore used. For functions that have unwind info that cannot be encoded with CU, MC would end up dropping both the compact unwind entry (OK; existing behavior) as well as the DWARF entries (not OK). This diff fixes things so that we emit the DWARF entry, as well as a CU entry with encoding `UNWIND_X86_MODE_DWARF` -- this basically tells the unwinder to look for the DWARF entry. I'm not 100% sure the `UNWIND_X86_MODE_DWARF` CU entry is necessary, this was the simplest fix. ld64 seems to be able to handle both the absence and presence of this CU entry. Ultimately ld64 (and LLD) will synthesize `UNWIND_X86_MODE_DWARF` if it is absent, so there is no impact to the final binary size. Reviewed By: davide, lhames Differential Revision: https://reviews.llvm.org/D122258
2022-06-10[MC] De-capitalize SwitchSection. NFCFangrui Song1-13/+13
Add SwitchSection to return switchSection. The API will be removed soon.
2022-06-08[MC] Add 'G' to augmentation string for MTE instrumented functionsFlorian Mayer1-0/+2
This was agreed on in https://lists.llvm.org/pipermail/llvm-dev/2020-May/141345.html The thread proposed two options * add a character to augmentation string and handle in libuwind * use a separate personality function. It was determined that this is the simpler and better option. This is part of ARM's Aarch64 ABI: https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#id22 The next step after this is teaching libunwind to untag when this augmentation character is set. Reviewed By: MaskRay, eugenis Differential Revision: https://reviews.llvm.org/D127007
2022-04-21[DWARF] Add API to get data from MCDwarfLineStrAlexander Yermolovich1-2/+8
This API will be used in D121876, to get finalized string data for .debug_line_str. Reviewed By: dblaikie, rafauler Differential Revision: https://reviews.llvm.org/D124052
2022-04-05[Support/Hash functions] Change the `final()` and `result()` of the hashing ↵Argyrios Kyrtzidis1-2/+1
functions to return an array of bytes Returning `std::array<uint8_t, N>` is better ergonomics for the hashing functions usage, instead of a `StringRef`: * When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural * Returning `std::array<uint8_t, N>` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef` As part of this patch also: * Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes. * Make `MD5Result` inherit from `std::array<uint8_t, 16>` which improves & simplifies its API. Differential Revision: https://reviews.llvm.org/D123100
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-1/+1
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-1/+1
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-21[DebugInfo][NFC] Do not call 'isRootFile' for DWARF Version < 5Igor Kudrin1-1/+1
A quicker comparison should be done first. Differential Revision: https://reviews.llvm.org/D117786
2022-01-21[DebugInfo] Fix handling '# line "file"' for DWARFv5Igor Kudrin1-1/+1
`CppHashInfo.Filename` is a `StringRef` that references a part of the source file and it is not null-terminated at the end of the file name. `AsmParser::parseAndMatchAndEmitTargetInstruction()` passes it to `getStreamer().emitDwarfFileDirective()`, and it eventually comes to `isRootFile()`. The comparison fails because `FileName.data()` is not properly terminated. In addition, the old code might cause a significant speed degradation for long source files. The `operator!=()` for `std::string` and `const char *` can be implemented in a way that it finds the length of the second argument first, which slows the comparison for long data. `parseAndMatchAndEmitTargetInstruction()` calls `emitDwarfFileDirective()` every time if `CppHashInfo.Filename` is not empty. As a result, the longer the source file is, the slower the compilation wend, and for a very long file, it might take hours instead of a couple of seconds normally. Differential Revision: https://reviews.llvm.org/D117785
2021-11-14[DebugInfo] Fix end_sequence of debug_line in LTO ObjectKyungwoo Lee1-11/+48
In a LTO build, the `end_sequence` in debug_line table for each compile unit (CU) points the end of text section which merged all CUs. The `end_sequence` needs to point to the end of each CU's range. This bug often causes invalid `debug_line` table in the final `.dSYM` binary for MachO after running `dsymutil` which tries to compensate an out-of-range address of `end_sequence`. The fix is to sync the line table termination with the range operations that are already maintained in DwarfDebug. When CU or section changes, or nodebug functions appear or module is finished, the prior pending line table is terminated using the last range label. In the MC path where no range is tracked, the old logic is conservatively used to end the line table using the section end symbol. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D108261
2021-09-30[MC] Make MCDwarfLineStr class publicMaksim Panchenko1-26/+9
Add MCDwarfLineStr class to the public API. Note that MCDwarfLineTableHeader::Emit(), takes MCDwarfLineStr as an Optional<> parameter making it impossible to use the API if the class is not publicly defined. Reviewed By: alexander-shaposhnikov Differential Revision: https://reviews.llvm.org/D109412
2021-06-17RISCV: adjust handling of relocation emission for RISCVSaleem Abdulrasool1-84/+10
This re-architects the RISCV relocation handling to bring the implementation closer in line with the implementation in binutils. We would previously aggressively resolve the relocation. With this restructuring, we always will emit a paired relocation for any symbolic difference of the type of S±T[±C] where S and T are labels and C is a constant. GAS has a special target hook controlled by `RELOC_EXPANSION_POSSIBLE` which indicates that a fixup may be expanded into multiple relocations. This is used by the RISCV backend to always emit a paired relocation - either ADD[WIDTH] + SUB[WIDTH] for text relocations or SET[WIDTH] + SUB[WIDTH] for a debug info relocation. Irrespective of whether linker relaxation support is enabled, symbolic difference is always emitted as a paired relocation. This change also sinks the target specific behaviour down into the target specific area rather than exposing it to the shared relocation handling. In the process, we also sink the "special" handling for debug information down into the RISCV target. Although this improves the path for the other targets, this is not necessarily entirely ideal either. The changes in the debug info emission could be done through another type of hook as this functionality would be required by any other target which wishes to do linker relaxation. However, as there are no other targets in LLVM which currently do this, this is a reasonable thing to do until such time as the code needs to be shared. Improve the handling of the relocation (and add a reduced test case from the Linux kernel) to ensure that we handle complex expressions for symbolic difference. This ensures that we correct relocate symbols with the adddends normalized and associated with the addition portion of the paired relocation. This change also addresses some review comments from Alex Bradbury about the relocations meant for use in the DWARF CFA being named incorrectly (using ADD6 instead of SET6) in the original change which introduced the relocation type. This resolves the issues with the symbolic difference emission sufficiently to enable building the Linux kernel with clang+IAS+lld (without linker relaxation). Resolves PR50153, PR50156! Fixes: ClangBuiltLinux/linux#1023, ClangBuiltLinux/linux#1143 Reviewed By: nickdesaulniers, maskray Differential Revision: https://reviews.llvm.org/D103539
2021-06-14Implement DW_CFA_LLVM_* for Heterogeneous DebuggingRamNalamothu1-0/+13
Add support in MC/MIR for writing/parsing, and DebugInfo. This is part of the Extensions for Heterogeneous Debugging defined at https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html Specifically the CFI instructions implemented here are defined at https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html#cfa-definition-instructions Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D76877
2021-03-12[Debug-Info] Add names for the debug line prologue.Esme-Yi1-4/+3
Summary: This is a minor patch to add names for the debug line prologue, as a follow-up of D95998. Reviewed By: dblaikie, ikudrin, shchenz Differential Revision: https://reviews.llvm.org/D98383
2021-03-04[XCOFF][DebugInfo] support DWARF for XCOFF for assembly output.Chen Zheng1-22/+9
Reviewed By: jasonliu Differential Revision: https://reviews.llvm.org/D95518
2021-02-27[Debug-Info][NFC] use emitDwarfUnitLength for debug line sectionChen Zheng1-24/+6
Use emitDwarfUnitLength for debug line, so we can benefit from overriding of emitDwarfUnitLength inside different streamers. Reviewed By: ikudrin, dblaikie Differential Revision: https://reviews.llvm.org/D95998
2021-01-21[MC] Use std::make_tuple to make some toolchains happy againMikael Holmen1-1/+1
My toolchain (LLVM 8.0, libstdc++ 5.4.0) complained with: 12:27:43 ../lib/MC/MCDwarf.cpp:814:10: error: chosen constructor is explicit in copy-initialization 12:27:43 return {Offset, Size, SetDelta}; 12:27:43 ^~~~~~~~~~~~~~~~~~~~~~~~ 12:27:43 /proj/flexasic/app/llvm/8.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.4.0/../../../../include/c++/5.4.0/tuple:479:19: note: explicit constructor declared here 12:27:43 constexpr tuple(_UElements&&... __elements) 12:27:43 ^ 12:27:43 1 error generated. This commit adds explicit calls to std::make_tuple to work around the problem.
2021-01-21MCDwarf: Delete uneeded parameterFangrui Song1-10/+9
And change signature
2020-12-21[MC] Split MCContext::createTempSymbol, default AlwaysAddSuffix to true, and ↵Fangrui Song1-6/+4
add comments CanBeUnnamed is rarely false. Splitting to a createNamedTempSymbol makes the intention clearer and matches the direction of reverted r240130 (to drop the unneeded parameters). No behavior change.
2020-06-18[MC] Rename a misnamed function. NFC.Igor Kudrin1-13/+13
The patch renames MakeStartMinusEndExpr() to makeEndMinusStartExpr() to better reflect an expression it creates and fix a naming style issue. Differential Revision: https://reviews.llvm.org/D82079
2020-06-16[MC] Generate .debug_frame in the 64-bit DWARF format [7/7]Igor Kudrin1-9/+26
Note that .eh_frame sections are generated in the 32-bit format even when debug sections are 64-bit, for compatibility reasons. They use relative references between entries, so they hardly benefit from the 64-bit format. Differential Revision: https://reviews.llvm.org/D81149
2020-06-16[MC] Fix DWARF forms for 64-bit DWARFv3 files [6/7]Igor Kudrin1-6/+7
DW_FORM_sec_offset was introduced in DWARFv4, so, for 64-bit DWARFv3, DW_FORM_data8 should be used instead. Differential Revision: https://reviews.llvm.org/D81148
2020-06-16[MC] Generate .debug_rnglists in the 64-bit DWARF format [5/7]Igor Kudrin1-3/+9
In addition, the patch fixes referencing the section within a compilation unit. Differential Revision: https://reviews.llvm.org/D81147
2020-06-16[MC] Generate .debug_aranges in the 64-bit DWARF format [4/7]Igor Kudrin1-7/+15
Differential Revision: https://reviews.llvm.org/D81146
2020-06-16[MC] Generate a compilation unit in the 64-bit DWARF format [3/7]Igor Kudrin1-14/+24
The patch enables producing DWARF64 compilation units and fixes generating references to .debug_abbrev and .debug_line sections. A similar change for .debug_ranges/.debug_rnglists will be added in a forthcoming patch. Differential Revision: https://reviews.llvm.org/D81145
2020-06-16[MC] Generate .debug_line in the 64-bit DWARF format [2/7]Igor Kudrin1-10/+21
Differential Revision: https://reviews.llvm.org/D81144
2020-05-24[MCDwarf] Delete unneeded DW_AT_unspecified_parametersFangrui Song1-13/+1
2020-05-24[MCDwarf] Delete unneeded DW_AT_prototyped for DW_TAG_labelFangrui Song1-4/+0
2020-05-22[MC] Fix double negation of DW_CFA_def_cfaFangrui Song1-1/+1
Negations are incorrectly added in numerous places and the code just happens to work. Also fix a missed DW_CFA_def_cfa_offset negation in c693b9c321d5a40d012340619674cf790c9ac86c: ARMAsmBackendDarwin::generateCompactUnwindEncoding
2020-05-22[MC] Fix double negation of DW_CFA_def_cfa_offsetFangrui Song1-1/+1
Negations are incorrectly added in two places and the code works just because the negations cancel each other.
2020-05-21[MC] Simplify MakeStartMinusEndExpr(). NFC.Igor Kudrin1-26/+22
The function does not need an MCStreamer per se; it was used only to get access to the MCContext. Differential Revision: https://reviews.llvm.org/D80205
2020-03-03[MCDwarf] Change emitListsTableHeaderStart to use a reference and fold ↵Fangrui Song1-16/+16
Start/End symbols generation into it Apply @dblaikie's suggestions in a post-commit review for D75375 Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D75568
2020-03-03[MCDwarf] Generate DWARF v5 .debug_rnglists for assembly filesFangrui Song1-44/+75
``` // clang -c -gdwarf-5 a.s -o a.o .section .init; ret .text; ret ``` .debug_info contains DW_AT_ranges and llvm-dwarfdump will report a verification error because .debug_rnglists does not exist (not implemented). This patch generates .debug_rnglists for assembly files. emitListsTableHeaderStart() in DwarfDebug.cpp can be shared with MCDwarf.cpp. Because CodeGen depends on MC, I move the function to MCDwarf.cpp Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D75375
2020-02-29[MC] Add MCStreamer::emitInt{8,16,32,64}Fangrui Song1-75/+75
Similar to AsmPrinter::emitInt{8,16,32,64}.
2020-02-14[MCStreamer] De-capitalize EmitValue EmitIntValue{,InHex}Fangrui Song1-93/+93
2020-02-14[MC] De-capitalize another set of MCStreamer::Emit* functionsFangrui Song1-27/+27
Emit{ValueTo,Code}Alignment Emit{DTP,TP,GP}* EmitSymbolValue etc
2020-02-14[MC] De-capitalize some MCStreamer::Emit* functionsFangrui Song1-27/+27
2020-02-13[AsmPrinter][MCStreamer] De-capitalize EmitInstruction and EmitCFI*Fangrui Song1-7/+7
2020-02-13[AsmPrinter] De-capitalize some AsmPrinter::Emit* functionsFangrui Song1-57/+57
Similar to rL328848.
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-2/+2
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-11-27[MC] Produce proper section relative relocations for COFF in .debug_frameMartin Storsjö1-1/+2
The third parameter to Streamer.EmitSymbolValue() is "bool IsSectionRelative = false". For ELF, these debug sections are mapped to address zero, so a normal, absolute address relocation works just fine, but COFF needs a section relative relocation, and COFF is the only target where needsDwarfSectionOffsetDirective() returns true. This matches how EmitSymbolValue is called elsewhere in the same source file. Differential Revision: https://reviews.llvm.org/D70661
2019-08-23Do a sweep of symbol internalization. NFC.Benjamin Kramer1-2/+2
llvm-svn: 369803
2019-07-19[DebugInfo] Generate fixups as emitting DWARF .debug_frame/.eh_frame.Hsiangkai Wang1-6/+34
It is necessary to generate fixups in .debug_frame or .eh_frame as relaxation is enabled due to the address delta may be changed after relaxation. There is an opcode with 6-bits data in debug frame encoding. So, we also need 6-bits fixup types. Differential Revision: https://reviews.llvm.org/D58335 llvm-svn: 366524
2019-07-18Revert "[DebugInfo] Generate fixups as emitting DWARF .debug_frame/.eh_frame."Hsiangkai Wang1-34/+6
This reverts commit 17e3cbf5fe656483d9016d0ba9e1d0cd8629379e. llvm-svn: 366444
2019-07-18[DebugInfo] Generate fixups as emitting DWARF .debug_frame/.eh_frame.Hsiangkai Wang1-6/+34
It is necessary to generate fixups in .debug_frame or .eh_frame as relaxation is enabled due to the address delta may be changed after relaxation. There is an opcode with 6-bits data in debug frame encoding. So, we also need 6-bits fixup types. Differential Revision: https://reviews.llvm.org/D58335 llvm-svn: 366442