aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-30llvm-readobj: Use reportFatalUsageError (#142039)Matt Arsenault1-8/+8
2025-05-02[AArch64] Implement assembler support for new SVE SEH unwind opcodes. (#137895)Eli Friedman1-1/+54
In order to support the AArch64 ABI, Microsoft has extended the unwinder to support additional opcodes. (Updated documentation at https://learn.microsoft.com/en-us/cpp/build/arm64-exception-handling .) First in a series of patches to support SVE on Windows.
2024-09-13[llvm][tools] Strip unneeded uses of raw_string_ostream::str() (NFC)JOE19941-7/+7
Remove unnecessary layer of indirection.
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-16[AArch64][Windows] Add llvm-readobj support for ec_context unwind opcode ↵Billy Laws1-0/+8
(#69515) ARM64EC uses the same CONTEXT structure as x86_64 as opposed to the regular ARM64 context, a new unwind opcode MSFT_OP_EC_CONTEXT is added to handle this.
2023-01-22Use llvm::popcount instead of llvm::countPopulation(NFC)Kazu Hirata1-1/+1
2022-10-12[AArch64] [SEH] Rename pac_sign_return_address to pac_sign_lrMartin Storsjö1-4/+3
This new opcode was initially documented as "pac_sign_return_address" in https://github.com/MicrosoftDocs/cpp-docs/pull/4202, but was soon afterwards renamed into "pac_sign_lr" in https://github.com/MicrosoftDocs/cpp-docs/pull/4209, as the other name was unwieldy, and there were no other external references to that name anywhere. Rename our external .seh assembler directive - it hasn't been merged for very long yet, so there's probably no external use to account for. Rename all other internal references to the opcode similarly. Differential Revision: https://reviews.llvm.org/D135762
2022-10-11[llvm-readobj] Decode the new ARM64 SEH info for return address signingMartin Storsjö1-2/+19
This got documented upstream in https://github.com/MicrosoftDocs/cpp-docs/pull/4202. Differential Revision: https://reviews.llvm.org/D135275
2022-10-04[AArch64][Windows] Add llvm-readobj support for save_any_reg unwind opcode.Eli Friedman1-26/+103
This is primarily used for Arm64EC, but it could be used for other non-standard calling conventions. The testcase is based on an Arm64EC thunk generated by MSVC. The name save_any_reg comes from Microsoft documentation, but the full encoding isn't specified there; this is reverse-engineered from the behavior of the unwinder. (Thanks to Martin Storsjö for his example of how to write simple unwinder testcases by directly calling RtlVirtualUnwind.) Differential Revision: https://reviews.llvm.org/D135196
2022-09-08[llvm] Use std::size instead of llvm::array_lengthofJoe Loser1-2/+2
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Differential Revision: https://reviews.llvm.org/D133429
2022-08-05[WinEH][ARM64] Split Unwind Info for Fucntions Larger than 1MBZhaoshi Zheng1-1/+1
Create function segments and emit unwind info of them. A segment must be less than 1MB and no prolog or epilog is splitted between two segments. This patch should generate correct, though not optimal, unwind info for large functions. Currently it only generate pacted info (.pdata) only for functions that are less than 1MB (single-segment functions). This is NFC from before this patch. The next step is to enable (.pdata) only unwind info for the first segment or segments that have neither prolog or epilog in a multi-segment function. Another future work item is to further split segments that require more than 255 code words or have more than 65535 epilogs. Reference: https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling#function-fragments Differential Revision: https://reviews.llvm.org/D130049
2022-05-18[llvm-readobj] Improve printing of Windows ARM packed unwind infoMartin Storsjö1-19/+79
Fix a couple minor details in the existing logic for calculating saved registers and stack adjustment. Synthesize the corresponding prologues and epilogues and print them. (This supersedes the previous printout of one single list of stored registers; as there's lots of minor nuance differences in how registers are pushed/popped in various corner cases, it's better to print the full prologue/epilogue instead of trying to condense it into one single list.) Print the raw values of the fields Reg, R, L (LinkRegister) and C (Chaining) instead of only printing the derived values. Differential Revision: https://reviews.llvm.org/D125644
2022-05-18[llvm-readobj] Fix printing of Windows ARM unwind opcodes, add testsMartin Storsjö1-29/+51
The existing code was essentially untested; in some cases, it used too narrow variable types to fit all the bits, in some cases the bit manipulation operations were incorrect. For the "ldr lr, [sp], #x" opcode, there's nothing in the documentation that says it cannot be used in a prologue. (In practice, it would probably seldom be used there, but technically there's nothing stopping it from being used.) The documentation only specifies the operation to replay for unwinding it, but the corresponding mirror instruction to be printed for a prologue is "str lr, [sp, #-x]!". Also improve printing of register masks, by aggregating registers into ranges where possible, and make the printing of the terminating branches clearer, as "bx <reg>" and "b.w <target>". Differential Revision: https://reviews.llvm.org/D125643
2022-05-12[llvm-readobj] [COFF] Fix the printout for ARM64 packed homed parametersMartin Storsjö1-4/+4
If the function has homed parameters but the number of saved registers is odd, the homed parameters are aligned at the top of the stack (so they line up with later varargs on the stack), not tightly after the other saved registers. Differential Revision: https://reviews.llvm.org/D125462
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-2/+2
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-2/+2
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2021-10-05[llvm] Update report_fatal_error calls from raw_string_ostream to use ↵Simon Pilgrim1-12/+6
Twine(OS.str()) As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared. We can use the raw_string_ostream::str() method to perform the implicit flush() and return a reference to the std::string container that we can then wrap inside Twine().
2021-09-14[llvm-readobj] [COFF] Resolve relocations pointing at section symbols for ↵Martin Storsjö1-9/+15
arm64 too This syncs parts from the x86 implementation to the ARMWinEH implementation. Currently, neither of the compilers targeting COFF/arm64 (MSVC, LLVM) produce such relocations, but LLVM might after a later patch. Differential Revision: https://reviews.llvm.org/D109650
2021-05-04[llvm-readobj] [ARMWinEH] Try to resolve label symbols into regular onesMartin Storsjö1-0/+24
Unwind info generated by MSVC tends to have relocations pointing at static "label" symbols like "$LN4" instead of regular ones based on the actual function's name. Try to resolve such symbols to a non-label symbol if possible (ideally to an external symbol), to improve the readability. Differential Revision: https://reviews.llvm.org/D101567
2021-04-30Reapply [llvm-readobj] [ARMWinEH] Fix handling of relocations and symbol offsetsMartin Storsjö1-81/+74
When looking up data referenced from pdata/xdata structures, the referenced data can be found in two different ways: - For an unrelocated object file, it's located via a relocation - For a relocated, linked image, the data is referenced with an (image relative) absolute address For the latter case, the absolute address can optionally be described with a symbol. For the case of an object file, there's two offsets involved; one immediate offset encoded in the data location that is modified by the relocation, and a section offset in the symbol. Previously, for the ExceptionRecord field, we printed the offset from the symbol (only) but used the immediate offset ignoring the symbol's address (using only the symbol's section) for printing the exception data. Add a helper method for doing the lookup and address calculation, for simplifying the calling code and making all the cases consistent. This addresses an existing FIXME comment, fixing printing of the exception data for cases where relocations point at individual symbols in the xdata section (which is what MSVC generates) instead of all relocations pointing at the start of the xdata section (which is what LLVM generates). This also fixes printing of the function name for packed entries in linked images. Relanded with a format string fix in the formatSymbol function; one can't use %X as format string for an uint64_t. That bug has been present since this code was added in e6971cab306cd. Differential Revision: https://reviews.llvm.org/D100305
2021-04-30Revert "[llvm-readobj] [ARMWinEH] Fix handling of relocations and symbol ↵Martin Storsjö1-73/+80
offsets" This reverts commit 37789240882bfacd951767acdb4c088fcbf53385. The added test fails on at least one buildbot, by printing a reversed combination, printing "func3_xdata +0x18 (0x8)" while it's supposed to be "func3_xdata +0x8 (0x18)", see e.g. https://lab.llvm.org/buildbot/#/builders/107/builds/7269. Currently no idea how that could happen, but reverting until it can be figured out.
2021-04-29[llvm-readobj] [ARMWinEH] Fix handling of relocations and symbol offsetsMartin Storsjö1-80/+73
When looking up data referenced from pdata/xdata structures, the referenced data can be found in two different ways: - For an unrelocated object file, it's located via a relocation - For a relocated, linked image, the data is referenced with an (image relative) absolute address For the latter case, the absolute address can optionally be described with a symbol. For the case of an object file, there's two offsets involved; one immediate offset encoded in the data location that is modified by the relocation, and a section offset in the symbol. Previously, for the ExceptionRecord field, we printed the offset from the symbol (only) but used the immediate offset ignoring the symbol's address (using only the symbol's section) for printing the exception data. Add a helper method for doing the lookup and address calculation, for simplifying the calling code and making all the cases consistent. This addresses an existing FIXME comment, fixing printing of the exception data for cases where relocations point at individual symbols in the xdata section (which is what MSVC generates) instead of all relocations pointing at the start of the xdata section (which is what LLVM generates). This also fixes printing of the function name for packed entries in linked images. Differential Revision: https://reviews.llvm.org/D100305
2021-03-01[readobj] Use ListSeparator (NFC)Kazu Hirata1-25/+10
2021-01-08[llvm-readobj] [ARMWinEH] Clearly print an invalid case of packed unwind ↵Martin Storsjö1-4/+6
info as such As the actual windows unwinder doesn't support this case, don't pretend that it is supported when dumping the generated unwind info either, even if it would be possible to interpret it as something sensible. This should reduce the risk of us emitting such a case in code (although it's unlikely as long as the unwind info is generated through the SEH opcodes, as the opcodes can't describe this case). Differential Revision: https://reviews.llvm.org/D91529
2020-09-15[llvm-readobj] [ARMWinEH] Print ARM64 packed unwind infoMartin Storsjö1-2/+139
In addition to printing the individual fields, synthesize and print the corresponding prolog for the unwind info (in reverse order, to match how it's printed for non-packed unwind info). Differential Revision: https://reviews.llvm.org/D87370
2020-09-10[llvm-readobj] [ARMWinEH] Print set_fp/add_fp differently in epiloguesMartin Storsjö1-3/+8
This matches how e.g. stp/ldp and other opcodes are printed differently for epilogues. Also add a missing --strict-whitespace in an existing test that was added explicitly for testing vertical alignment, and change to using temp files for the generated object files. Differential Revision: https://reviews.llvm.org/D87363
2020-09-03[AArch64] Add asm directives for the remaining SEH unwind codesMartin Storsjö1-0/+46
Add support in llvm-readobj for displaying them and support in the asm parsser, AArch64TargetStreamer and MCWin64EH for emitting them. The directives for the remaining basic opcodes have names that match the opcode in the documentation. The directives for custom stack cases, that are named MSFT_OP_TRAP_FRAME, MSFT_OP_MACHINE_FRAME, MSFT_OP_CONTEXT and MSFT_OP_CLEAR_UNWOUND_TO_CALL, are given matching assembler directive names that fit into the rest of the opcode naming; .seh_trap_frame, .seh_context, .seh_clear_unwound_to_call The opcode MSFT_OP_MACHINE_FRAME is mapped to the existing opecode enum UOP_PushMachFrame that is used on x86_64, and also uses the corresponding existing x86_64 directive name .seh_pushframe. Differential Revision: https://reviews.llvm.org/D86889
2020-09-01[llvm-readobj] - Remove Error.cpp,.h and drop dependencies in the code.Georgii Rymar1-4/+3
We have Error.cpp/.h which contains some code for working with error codes. In fact we use Error/Expected<> almost everywhere already and we can get rid of these files. Note: a few places in the code used readobj specific error codes, e.g. `return readobj_error::unknown_symbol`. But these codes are never really used, i.e. the code checks the fact of a success/error call only. So I've changes them to `return inconvertibleErrorCode()` for now. It seems that these places probably should be converted to use `Error`/`Expected<>`. Differential revision: https://reviews.llvm.org/D86772
2020-08-26[llvm-readobj] Fix arm64 unwind opcode disassembly printingMartin Storsjö1-2/+2
Add a missing minus, fix vertical alignment of instructions for one opcode. Differential Revision: https://reviews.llvm.org/D86523
2019-12-11[llvm-readobj] Fix/improve printing WinEH unwind info for linked PE imagesMartin Storsjö1-3/+5
ARMWinEHPrinter was already designed to handle linked PE images (since d2941b43f40d), but resolving symbols didn't consistently take the image base into account (as linked images seldom have a symbol table, except for in MinGW setups). Win64EHDumper wasn't really designed to handle linked images (it would crash if executed on such a file), but a few concepts (getSymbol, taking a virtual address instead of a relocation, and getSectionContaining for finding the section containing a certain virtual address) can be borrowed from ARMWinEHPrinter. Adjust ARMWinEHPrinter to print the address of the exception handler routine as a VA instead of an RVA, consistently with other addresses in the same printout, and make Win64EHDumper print addresses similarly for image cases. Differential Revision: https://reviews.llvm.org/D71303
2019-09-20[llvm-readobj] flush output before crashYuanfang Chen1-1/+3
Otherwise the output could be lost. llvm-svn: 372372
2019-08-19[Object/COFF.h] - Stop returning std::error_code in a few methods. NFCI.George Rimar1-4/+1
There are 4 methods that return std::error_code now, though they do not have to because they are always succeed. I refactored them. This allows to simplify the code in tools a bit. llvm-svn: 369263
2019-05-02[Object] Change getSectionName() to return Expected<StringRef>Fangrui Song1-7/+7
Summary: It currently receives an output parameter and returns std::error_code. Expected<StringRef> fits for this purpose perfectly. Differential Revision: https://reviews.llvm.org/D61421 llvm-svn: 359774
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-11-11[Support] Make error banner optional in logAllUnhandledErrorsJonas Devlieghere1-7/+7
In a lot of places an empty string was passed as the ErrorBanner to logAllUnhandledErrors. This patch makes that argument optional to simplify the call sites. llvm-svn: 346604
2018-11-02[AArch64] [Windows] Misc fixes for llvm-readobj -unwind.Eli Friedman1-19/+19
Use getImageBase() helper to compute the image base. Fix various offsets/addresses/masks so they're actually correct. This allows decoding unwind info from DLLs, and unwind info from object files containing multiple functions. Differential Revision: https://reviews.llvm.org/D54015 llvm-svn: 346036
2018-10-24[ARM64][Windows] Add unwind support to llvm-readobjSanjin Sijaric1-36/+363
This patch adds support for dumping the unwind info from ARM64 COFF object files. Differential Revision: https://reviews.llvm.org/D53264 llvm-svn: 345108
2018-03-29Typo fix: epilouge->epilogue. NFC.Eric Christopher1-1/+1
llvm-svn: 328833
2016-06-24Thread Expected<...> up from libObject’s getSymbolAddress() for symbols to ↵Kevin Enderby1-10/+27
allow a good error message to be produced. This is nearly the last libObject interface that used ErrorOr and the last one that appears in llvm/include/llvm/Object/MachO.h . For Mach-O objects this is just a clean up because it’s version of getSymbolAddress() can’t return an error. I will leave it to the experts on COFF and ELF to actually add meaning full error messages in their tests if they wish. And also leave it to these experts to change the last two ErrorOr interfaces in llvm/include/llvm/Object/ObjectFile.h for createCOFFObjectFile() and createELFObjectFile() if they wish. Since there are no test cases for COFF and ELF error cases with respect to getSymbolAddress() in the test suite this is no functional change (NFC). llvm-svn: 273701
2016-05-02Thread Expected<...> up from libObject’s getType() for symbols to allow ↵Kevin Enderby1-5/+8
llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating that a symbol at a specific index has a bad section index and that bad section index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: "// TODO: Actually report errors helpfully" and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. llvm-svn: 268298
2016-04-20Thread Expected<...> up from libObject’s getName() for symbols to allow ↵Kevin Enderby1-12/+32
llvm-objdump to produce a good error message. Produce another specific error message for a malformed Mach-O file when a symbol’s string index is past the end of the string table. The existing test case in test/Object/macho-invalid.test for macho-invalid-symbol-name-past-eof now reports the error with the message indicating that a symbol at a specific index has a bad sting index and that bad string index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. There is some code for this that could be factored into a routine but I would like to leave that for the code owners post-commit to do as they want for handling an llvm::Error. An example of how this could be done is shown in the diff in lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h which had a Check() routine already for std::error_code so I added one like it for llvm::Error . Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there fixes needed to lld that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 266919
2016-03-23Fix a crash in running llvm-objdump -t with an invalid Mach-O file alreadyKevin Enderby1-1/+4
in the test suite. While this is not really an interesting tool and option to run on a Mach-O file to show the symbol table in a generic libObject format it shouldn’t crash. The reason for the crash was in MachOObjectFile::getSymbolType() when it was calling MachOObjectFile::getSymbolSection() without checking its return value for the error case. What makes this fix require a fair bit of diffs is that the method getSymbolType() is in the class ObjectFile defined without an ErrorOr<> so I needed to add that all the sub classes.  And all of the uses needed to be updated and the return value needed to be checked for the error case. The MachOObjectFile version of getSymbolType() “can” get an error in trying to come up with the libObject’s internal SymbolRef::Type when the Mach-O symbol symbol type is an N_SECT type because the code is trying to select from the SymbolRef::ST_Data or SymbolRef::ST_Function values for the SymbolRef::Type. And it needs the Mach-O section to use isData() and isBSS to determine if it will return SymbolRef::ST_Data. One other possible fix I considered is to simply return SymbolRef::ST_Other when MachOObjectFile::getSymbolSection() returned an error. But since in the past when I did such changes that “ate an error in the libObject code” I was asked instead to push the error out of the libObject code I chose not to implement the fix this way. As currently written both the COFF and ELF versions of getSymbolType() can’t get an error. But if isReservedSectionNumber() wanted to check for the two known negative values rather than allowing all negative values or the code wanted to add the same check as in getSymbolAddress() to use getSection() and check for the error then these versions of getSymbolType() could return errors. At the end of the day the error printed now is the generic “Invalid data was encountered while parsing the file” for object_error::parse_failed. In the future when we thread Lang’s new TypedError for recoverable error handling though libObject this will improve. And where the added // Diagnostic(… comment is, it would be changed to produce and error message like “bad section index (42) for symbol at index 8” for this case. llvm-svn: 264187
2016-02-18Remove uses of builtin comma operator.Richard Trieu1-11/+11
Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261270
2015-08-07Convert getSymbolSection to return an ErrorOr.Rafael Espindola1-2/+3
This function can actually fail since the symbol contains an index to the section and that can be invalid. llvm-svn: 244375
2015-07-03Return ErrorOr from getSymbolAddress.Rafael Espindola1-7/+13
It can fail trying to get the section on ELF and COFF. This makes sure the error is handled. llvm-svn: 241366
2015-07-02Return ErrorOr from SymbolRef::getName.Rafael Espindola1-10/+17
This function can really fail since the string table offset can be out of bounds. Using ErrorOr makes sure the error is checked. Hopefully a lot of the boilerplate code in tools/* can go away once we have a diagnostic manager in Object. llvm-svn: 241297
2015-06-29Don't return error_code from function that never fails.Rafael Espindola1-3/+1
llvm-svn: 241021
2015-06-26Simplify getSymbolType.Rafael Espindola1-7/+2
This is still a really odd function. Most calls are in object format specific contexts and should probably be replaced with a more direct query, but at least now this is not too obnoxious to use. llvm-svn: 240777
2015-01-14[cleanup] Re-sort all the #include lines in LLVM usingChandler Carruth1-1/+1
utils/sort_includes.py. I clearly haven't done this in a while, so more changed than usual. This even uncovered a missing include from the InstrProf library that I've added. No functionality changed here, just mechanical cleanup of the include order. llvm-svn: 225974
2014-10-08Remove bogus std::error_code returns form SectionRef.Rafael Espindola1-11/+3
There are two methods in SectionRef that can fail: * getName: The index into the string table can be invalid. * getContents: The section might point to invalid contents. Every other method will always succeed and returning and std::error_code just complicates the code. For example, a section can have an invalid alignment, but if we are able to get to the section structure at all and create a SectionRef, we will always be able to read that invalid alignment. llvm-svn: 219314