aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCCodeView.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-03Move FragmentAllocator from MCContext to MCObjectStreamerFangrui Song1-6/+3
In MCContext::reset, delete a stale comment as MCCodeView no longer owns or deallocates MCFragment.
2025-08-02MCFragment: Store the number of variable-size tail fixups as uint8_tFangrui Song1-0/+2
Decrease sizeof(MCFragment) by 8 on 64-bit machines.
2025-07-20MCFragment: Remove setContents/setFixupsFangrui Song1-5/+8
Make the fixed-size part of MCFragment append-only to support allocating content as trailing data. Update CodeView callers to use setVarContents instead of setContents. Remove unused setFixups.
2025-07-19MC: Optimize getOrCreateDataFragmentFangrui Song1-2/+2
... by eagerly allocating an empty fragment when adding a fragment with a variable-size tail. X86AsmBackend, The JCC erratum mitigation and x86-pad-for-align set a flag for FT_Relaxable, which needs to be moved to emitInstructionBegin. ``` if (CF->getKind() == MCFragment::FT_Relaxable) CF->setAllowAutoPadding(canPadInst(Inst, OS)); ``` Follow-up to #148544
2025-07-15MC: Restructure MCFragment as a fixed part and a variable tailFangrui Song1-1/+1
Refactor the fragment representation of `push rax; jmp foo; nop; jmp foo`, previously encoded as `MCDataFragment(nop); MCRelaxableFragment(jmp foo); MCDataFragment(nop); MCRelaxableFragment(jmp foo)`, to ``` MCFragment(fixed: push rax, variable: jmp foo) MCFragment(fixed: nop, variable: jmp foo) ``` Changes: * Eliminate MCEncodedFragment, moving content and fixup storage to MCFragment. * The new MCFragment contains a fixed-size content (similar to previous MCDataFragment) and an optional variable-size tail. * The variable-size tail supports FT_Relaxable, FT_LEB, FT_Dwarf, and FT_DwarfFrame, with plans to extend to other fragment types. dyn_cast/isa should be avoided for the converted fragment subclasses. * In `setVarFixups`, source fixup offsets are relative to the variable part's start. Stored fixup (in `FixupStorage`) offsets are relative to the fixed part's start. A lot of code does `getFragmentOffset(Frag) + Fixup.getOffset()`, expecting the fixup offset to be relative to the fixed part's start. * HexagonAsmBackend::fixupNeedsRelaxationAdvanced needs to know the associated instruction for a fixup. We have to add a `const MCFragment &` parameter. * In MCObjectStreamer, extend `absoluteSymbolDiff` to apply to FT_Relaxable as otherwise there would be many more FT_DwarfFrame fragments in -g compilations. https://llvm-compile-time-tracker.com/compare.php?from=28e1473e8e523150914e8c7ea50b44fb0d2a8d65&to=778d68ad1d48e7f111ea853dd249912c601bee89&stat=instructions:u ``` stage2-O0-g instructins:u geomeon (-0.07%) stage1-ReleaseLTO-g (link only) max-rss geomean (-0.39%) ``` ``` % /t/clang-old -g -c sqlite3.i -w -mllvm -debug-only=mc-dump &| awk '/^[0-9]+/{s[$2]++;tot++} END{print "Total",tot; n=asorti(s, si); for(i=1;i<=n;i++) print si[i],s[si[i]]}' Total 59675 Align 2215 Data 29700 Dwarf 12044 DwarfCallFrame 4216 Fill 92 LEB 12 Relaxable 11396 % /t/clang-new -g -c sqlite3.i -w -mllvm -debug-only=mc-dump &| awk '/^[0-9]+/{s[$2]++;tot++} END{print "Total",tot; n=asorti(s, si); for(i=1;i<=n;i++) print si[i],s[si[i]]}' Total 32287 Align 2215 Data 2312 Dwarf 12044 DwarfCallFrame 4216 Fill 92 LEB 12 Relaxable 11396 ``` Pull Request: https://github.com/llvm/llvm-project/pull/148544
2025-07-01MC: Store fragment content and fixups out-of-lineFangrui Song1-6/+7
Moved `Contents` and `Fixups` SmallVector storage to MCSection, enabling trivial destructors for most fragment subclasses and eliminating the need for MCFragment::destroy in ~MCSection. For appending content to the current section, use getContentsForAppending. During assembler relaxation, prefer setContents/setFixups, which may involve copying and reduce the benefits of https://reviews.llvm.org/D145791. Moving only Contents out-of-line caused a slight performance regression (Alexis Engelke's 2024 prototype). By also moving Fragments out-of-line, fragment destructors become trivial, resulting in neglgible instructions:u increase for "stage2-O0-g" and [large max-rss decrease](https://llvm-compile-time-tracker.com/compare.php?from=84e82746c3ff63ec23a8b85e9efd4f7fccf92590&to=555a28c0b2f8250a9cf86fd267a04b0460283e15&stat=max-rss&linkStats=on) for the "stage1-ReleaseLTO-g (link only)" benchmark. ( An older version using fewer inline functions: https://llvm-compile-time-tracker.com/compare.php?from=bb982e733cfcda7e4cfb0583544f68af65211ed1&to=f12d55f97c47717d438951ecddecf8ebd28c296b&linkStats=on ) Now using plain SmallVector in MCSection for storage, with potential for future allocator optimizations, such as allocating `Contents` as the trailing object of MCDataFragment. (GNU Assembler uses gnulib's obstack for fragment management.) Co-authored-by: Alexis Engelke <engelke@in.tum.de> Pull Request: https://github.com/llvm/llvm-project/pull/146307
2025-06-30CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment. NFC ↵Fangrui Song1-2/+5
(#146462) so that ~MCCVInlineLineTableFragment will become trivial when we make ~MCEncodedFragment trivial (#146307).
2025-06-30Revert "CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragment"David Spickett1-5/+0
This reverts commit e47d4010d34119c2b4a28e7609fde35449a8b437. Causing a few tests to crash on Windows buildbots.
2025-06-29CodeView: Move MCCVDefRangeFragment storage to MCContext/MCFragmentFangrui Song1-0/+5
Work toward making ~MCCVInlineLineTableFragment trivial.
2025-06-27MC: Remove unneeded MCSymbolRefExpr::VariantKind callsFangrui Song1-3/+2
2024-12-21[MC,CodeView] Postpone MCDataFragment creation to finish timeFangrui Song1-26/+11
`StrTabFragment` created due to `.cv_stringtable` is not placed directly into a section. This requires a funky ~CodeViewContext and does not fit well with the future that moves MCFragment storage out-of-line.
2024-12-21[MC] Decrease direct access to getContents()Fangrui Song1-2/+3
to make it easier to store fragment contents out-of-line. Loosely based on Alexis Engelke's prototype.
2024-09-19[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)Jay Foad1-2/+2
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
2024-07-01MCCodeView: replace the MCAsmLayout parameter with MCAssemblerFangrui Song1-14/+12
2024-07-01MCExpr::evaluateKnownAbsolute: replace the MCAsmLayout parameter with ↵Fangrui Song1-1/+2
MCAssembler and add a comment.
2024-06-22[MC] Allocate MCFragment with a bump allocatorFangrui Song1-2/+2
#95197 and 75006466296ed4b0f845cbbec4bf77c21de43b40 eliminated all raw `new MCXXXFragment`. We can now place fragments in a bump allocator. In addition, remove the dead `Kind == FragmentType(~0)` condition. ~CodeViewContext may call `StrTabFragment->destroy()` and need to be reset before `FragmentAllocator.Reset()`. Tested by llvm/test/MC/COFF/cv-compiler-info.ll using asan. Pull Request: https://github.com/llvm/llvm-project/pull/96402
2024-06-14[MC] Add MCFragment allocation helpersFangrui Song1-8/+8
`allocFragment` might be changed to a placement new when the allocation strategy changes. `allocInitialFragment` is to deduplicate the following pattern ``` auto *F = new MCDataFragment(); Result->addFragment(*F); F->setParent(Result); ``` Pull Request: https://github.com/llvm/llvm-project/pull/95197
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-1/+1
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces support::{big,little,native} with llvm::endianness::{big,little,native}.
2023-09-06Emit line numbers in CodeView for trailing (after `ret`) blocks from inlined ↵Daniel Paoliello1-36/+52
functions Issue Details: When building up line information for CodeView debug info, LLVM attempts to gather the "range" of instructions within a function as these are printed together in a single record. If there is an inlined function, then those lines are attributed to the original function to enable generating `S_INLINESITE` records. However, this thus requires there to be instructions from the inlining function after the inlined function otherwise the instruction range would not include the inlined function. Fix Details: Include any inlined functions when finding the extent of a function in `getFunctionLineEntries` Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D159226
2023-05-02[MC] Remove dead code, NFCPhoebe Wang1-2/+0
This code was added in 408b5e660300f9, but neither the return value nor `Res` was used in the following code. Differential Revision: https://reviews.llvm.org/D149584
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-1/+1
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-24[Alignment][NFC] Use Align in MCStreamer::emitValueToAlignmentGuillaume Chatelet1-2/+2
Differential Revision: https://reviews.llvm.org/D138674
2022-05-26[MC] Lower case the first letter of EmitCOFF* EmitWin* EmitCV*. NFCFangrui Song1-2/+2
2022-02-09Cleanup LLVMMC headersserge-sans-paille1-0/+1
There's a few relevant forward declarations in there that may require downstream adding explicit includes: llvm/MC/MCContext.h no longer includes llvm/BinaryFormat/ELF.h, llvm/MC/MCSubtargetInfo.h, llvm/MC/MCTargetOptions.h llvm/MC/MCObjectStreamer.h no longer include llvm/MC/MCAssembler.h llvm/MC/MCAssembler.h no longer includes llvm/MC/MCFixup.h, llvm/MC/MCFragment.h Counting preprocessed lines required to rebuild llvm-project on my setup: before: 1052436830 after: 1049293745 Which is significant and backs up the change in addition to the usual benefits of decreasing coupling between headers and compilation units. Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119244
2022-02-06[llvm] Use = default (NFC)Kazu Hirata1-1/+1
2020-12-07[CodeView] Fix inline sites that are missing code offsets.Amy Huang1-4/+1
When an inline site has a starting code offset of 0, we sometimes don't emit the starting offset. Bug: https://bugs.llvm.org/show_bug.cgi?id=48377 Differential Revision: https://reviews.llvm.org/D92590
2020-04-20[MC][NFC] Use camelCase style for functions in MCObjectStreamerShengchen Kan1-1/+1
2020-02-29[MC] Add MCStreamer::emitInt{8,16,32,64}Fangrui Song1-13/+13
Similar to AsmPrinter::emitInt{8,16,32,64}.
2020-02-14[MCStreamer] De-capitalize EmitValue EmitIntValue{,InHex}Fangrui Song1-13/+13
2020-02-14[MC] De-capitalize another set of MCStreamer::Emit* functionsFangrui Song1-10/+10
Emit{ValueTo,Code}Alignment Emit{DTP,TP,GP}* EmitSymbolValue etc
2020-02-14[MC] De-capitalize some MCStreamer::Emit* functionsFangrui Song1-2/+2
2019-05-31[codeview] Revert inline line table change of r362264Reid Kleckner1-0/+1
Testing with debuggers shows that our previous behavior was correct. The reason I thought MSVC did things differently is that MSVC prefers to use the 0xB combined code offset and code length update opcode when inline sites are discontiguous. Keep the test changes, and update the llvm-pdbutil inline line table dumper to account for this new interpretation of the opcodes. llvm-svn: 362277
2019-05-31[codeview] Fix inline line table accuracy for discontiguous segmentsReid Kleckner1-1/+0
After improving the inline line table dumper in llvm-pdbutil and looking at MSVC's inline line tables, it is clear that setting the length of the inlined code region does not update the code offset. This means that the delta to the beginning of a new discontiguous inlined code region should be calculated relative to the last code offset, excluding the length. Implementing this is a one line fix for MC: simply don't update LastLabel. While I'm updating these test cases, switch them to use llvm-objdump -d and llvm-pdbutil. This allows us to show offsets of each instruction and correlate the line table offsets to the actual code. llvm-svn: 362264
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-17[codeview] Flush labels before S_DEFRANGE* fragmentsReid Kleckner1-2/+2
This was a pre-existing bug that could be triggered with assembly like this: .p2align 2 .LtmpN: .cv_def_range "..." I noticed this when attempting to change clang to emit aligned symbol records. llvm-svn: 349403
2018-08-28[codeview] Clean up machinery for deferring .cv_loc emissionReid Kleckner1-43/+24
Now that we create the label at the point of the directive, we don't need to set the "current CV location", and then later when we emit the next instruction, create a label for it and emit it. DWARF still defers the labels used in .debug_loc until the next instruction or value, for reasons unknown. llvm-svn: 340883
2018-05-18Support: Simplify endian stream interface. NFCI.Peter Collingbourne1-1/+1
Provide some free functions to reduce verbosity of endian-writing a single value, and replace the endianness template parameter with a field. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47032 llvm-svn: 332757
2018-04-25[codeview] Ignore .cv_loc directives at the end of a functionReid Kleckner1-0/+13
If no data or instructions are emitted after a location directive, we should clear the cv_loc when we change sections, or it will be emitted at the beginning of the next section. This violates our invariant that all .cv_loc directives belong to the same section. Add clearer assertions for this. llvm-svn: 330884
2018-01-18[CodeView] Add line numbers for inlined call sitesReid Kleckner1-3/+27
We did this for inline call site line tables, but we hadn't done it for regular function line tables yet. This patch copies that logic from encodeInlineLineTable. llvm-svn: 322905
2018-01-18[CodeView] Sink complex inline functions to .cpp file, NFCReid Kleckner1-0/+45
I'm cleaning up this code before I attempt to fix a line table bug. llvm-svn: 322904
2018-01-12MC: Remove redundant `SetUsed` arguments in MCSymbol methodsSam Clegg1-1/+1
We can probably take this a step further since the only user of the isUsed flag is AsmParser it should probably be doing this explicitly. For now this is a step in the right direction though. Differential Revision: https://reviews.llvm.org/D41971 llvm-svn: 322386
2017-12-13Remove redundant includes from lib/MC.Michael Zolotukhin1-1/+0
llvm-svn: 320624
2017-09-19Re-land "Fix Bug 30978 by emitting cv file checksums."Reid Kleckner1-29/+92
This reverts r313431 and brings back r313374 with a fix to write checksums as binary data and not ASCII hex strings. llvm-svn: 313657
2017-09-16Revert "Fix Bug 30978 by emitting cv file checksums."Eric Beckmann1-90/+29
This reverts commit 6389e7aa724ea7671d096f4770f016c3d86b0d54. There is a bug in this implementation where the string value of the checksum is outputted, instead of the actual hex bytes. Therefore the checksum is incorrect, and this prevent pdbs from being loaded by visual studio. Revert this until the checksum is emitted correctly. llvm-svn: 313431
2017-09-15Fix Bug 30978 by emitting cv file checksums.Eric Beckmann1-29/+90
Summary: The checksums had already been placed in the IR, this patch allows MCCodeView to actually write it out to an MCStreamer. Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D37157 llvm-svn: 313374
2017-06-07Move Object format code to lib/BinaryFormat.Zachary Turner1-1/+1
This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
2017-05-30[CodeView] Move CodeView YAML code to ObjectYAML.Zachary Turner1-1/+1
This is the beginning of an effort to move the codeview yaml reader / writer into ObjectYAML so that it can be shared. Currently the only consumer / producer of CodeView YAML is llvm-pdbdump, but CodeView can exist outside of PDB files, and indeed is put into object files and passed to the linker to produce PDB files. Furthermore, there are subtle differences in the types of records that show up in object file CodeView vs PDB file CodeView, but they are otherwise 99% the same. By having this code in ObjectYAML, we can have llvm-pdbdump reuse this code, while teaching obj2yaml and yaml2obj to use this syntax for dealing with object files that can contain CodeView. This patch only adds support for CodeView type information to ObjectYAML. Subsequent patches will add support for CodeView symbol information. llvm-svn: 304248
2017-05-30[CodeView] Rename ModuleDebugFragment -> DebugSubsection.Zachary Turner1-3/+3
This is more concise, and matches the terminology used in other parts of the codebase more closely. llvm-svn: 304218
2017-04-29[llvm-pdbdump] Abstract some of the YAML/Raw printing code.Zachary Turner1-1/+1
There is a lot of duplicate code for printing line info between YAML and the raw output printer. This introduces a base class that can be shared between the two, and makes some minor cleanups in the process. llvm-svn: 301728