aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCCodeView.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2017-04-27Rename some PDB classes.Zachary Turner1-3/+3
We have a lot of very similarly named classes related to dealing with module debug info. This patch has NFC, it just renames some classes to be more descriptive (albeit slightly more to type). The mapping from old to new class names is as follows: Old | New ModInfo | DbiModuleDescriptor ModuleSubstream | ModuleDebugFragment ModStream | ModuleDebugStream With the corresponding Builder classes renamed accordingly. Differential Revision: https://reviews.llvm.org/D32506 llvm-svn: 301555
2017-01-24[CodeView] Fix off-by-one error in def range gap emissionReid Kleckner1-6/+6
Also fixes a much worse bug where we emitted the wrong gap size for the def range uncovered by the test for this issue. Fixes PR31726. llvm-svn: 292949
2017-01-02Reapply "[CodeGen] Fix invalid DWARF info on Win64"Keno Fischer1-1/+1
This reapplies rL289013 (reverted in rL289014) with the fixes identified in D21731. Should hopefully pass the buildbots this time. llvm-svn: 290809
2016-12-16Resubmit "[CodeView] Hook CodeViewRecordIO for reading/writing symbols."Zachary Turner1-1/+3
The original patch was broken due to some undefined behavior as well as warnings that were triggering -Werror. llvm-svn: 290000
2016-12-16Revert "[CodeView] Hook CodeViewRecordIO for reading/writing symbols."Zachary Turner1-3/+1
This reverts commit r289978, which is failing due to some rebase/merge issues. llvm-svn: 289981
2016-12-16[CodeView] Hook CodeViewRecordIO for reading/writing symbols.Zachary Turner1-1/+3
This is the 3rd of 3 patches to get reading and writing of CodeView symbol and type records to use a single codepath. Differential Revision: https://reviews.llvm.org/D26427 llvm-svn: 289978
2016-12-08Revert "[CodeGen] Fix invalid DWARF info on Win64"Keno Fischer1-1/+1
Appears to break on build bots. Reverting pending investigation. llvm-svn: 289014
2016-12-08[CodeGen] Fix invalid DWARF info on Win64Keno Fischer1-1/+1
The relocations for `DIEEntry::EmitValue` were wrong for Win64 (emitting FK_Data_4 instead of FK_SecRel_4). This corrects that oversight so that the DWARF data is correct in Win64 COFF files. Fixes PR15393. Patch by Jameson Nash <jameson@juliacomputing.com> based on a patch by David Majnemer. Differential Revision: https://reviews.llvm.org/D21731 llvm-svn: 289013
2016-10-05[codeview] Truncate records to maximum record size near 64KBReid Kleckner1-0/+7
If we don't truncate, LLVM asserts when the label difference doesn't fit in a 16 bit field. This patch truncates two kinds of data: trailing null terminated names in symbol records, and inline line tables. The inline line table test that I have is too large (many MB), so I'm not checking it in. Hopefully fixes PR28264. llvm-svn: 283403
2016-09-15[codeview] Optimize the size of defranges with gapsReid Kleckner1-5/+43
For small, discontiguous local variable regions, CodeView can use a single defrange record with a gap, rather than having two defrange records. I expect that this optimization will only have a minor impact on debug info size. llvm-svn: 281664
2016-09-07[codeview] Add new directives to record inlined call site line infoReid Kleckner1-46/+106
Summary: Previously we were trying to represent this with the "contains" list of the .cv_inline_linetable directive, which was not enough information. Now we directly represent the chain of inlined call sites, so we know what location to emit when we encounter a .cv_loc directive of an inner inlined call site while emitting the line table of an outer function or inlined call site. Fixes PR29146. Also fixes PR29147, where we would crash when .cv_loc directives crossed sections. Now we write down the section of the first .cv_loc directive, and emit an error if any other .cv_loc directive for that function is in a different section. Also fixes issues with discontiguous inlined source locations, like in this example: volatile int unlikely_cond = 0; extern void __declspec(noreturn) abort(); __forceinline void f() { if (!unlikely_cond) abort(); } int main() { unlikely_cond = 0; f(); unlikely_cond = 0; } Previously our tables gave bad location information for the 'abort' call, and the debugger wouldn't snow the inlined stack frame for 'f'. It is important to emit good line tables for this code pattern, because it comes up whenever an asan bug occurs in an inlined function. The __asan_report* stubs are generally placed after the normal function epilogue, leading to discontiguous regions of inlined code. Reviewers: majnemer, amccarth Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D24014 llvm-svn: 280822
2016-08-26[MC] Move .cv_loc management logic out of MCContextReid Kleckner1-4/+5
MCContext already has many tasks, and separating CodeView out from it is probably a good idea. The .cv_loc tracking was modelled on the DWARF tracking which lived directly in MCContext. Removes the inclusion of MCCodeView.h from MCContext.h, so now there are only 10 build actions while I hack on CodeView support instead of 265. llvm-svn: 279847