aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-11-01[yaml2obj][obj2yaml][objdump] Handle MIPS COFF files (#112591)Hervé Poussineau1-0/+2
- handle IMAGE_FILE_MACHINE_R4000 machine type - handle MIPS COFF relocations llvm-objdump can now parse MIPS COFF files.
2024-10-15[COFF] Add MIPS relocation types (#107814)hpoussin1-0/+21
Add the MIPS COFF relocation types. They will be needed to add support for MIPS Windows object file. This is an extract of PR https://github.com/llvm/llvm-project/pull/107744.
2024-09-23[Object][COFF] Fix CHPE metadata offset check (#109591)Jacek Caban1-1/+1
2024-08-27[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#106190)Kazu Hirata1-1/+1
S.substr(N, M) is simpler than S.slice(N, N + M). Also, substr is probably better recognizable than slice thanks to std::string_view::substr.
2024-08-09[llvm-readobj][COFF] Dump hybrid objects for ARM64X files. (#102245)Jacek Caban1-0/+48
2024-08-07Fix MSVC "result of 32-bit shift implicitly converted to 64 bits" warning. NFC.Simon Pilgrim1-1/+1
2024-08-07Remove unnecessary break to fix static analysis warning.Simon Pilgrim1-1/+0
2024-08-07Fix MSVC "not all control paths return a value" warning. NFC.Simon Pilgrim1-0/+1
2024-08-06[Object][COFF] Use uintptr_t for getRvaPtr call in Arm64XRelocRef::validate.Jacek Caban1-1/+1
Fixes #97229.
2024-08-06[Object][COFF][llvm-readobj] Add support for ARM64X dynamic relocations. ↵Jacek Caban1-0/+340
(#97229)
2024-05-15[nfc] Allow forwarding `Error` returns from `Expected` callers (#92208)Mircea Trofin1-3/+3
On a few compilers (clang 11/12 for example [1]), the following does not result in a copy elision, and since `Error`'s copy dtor is elided, results in a compile error: ``` Expect<Something> foobar() { ... if (Error E = aCallReturningError()) return E; ... } ``` Moving `E` would, conversely, result in the pessimizing-move warning on more recent clangs ("moving a local object in a return statement prevents copy elision") We just need to make the `Expected` ctor taking an `Error` take it as a r-value reference. [1] https://lab.llvm.org/buildbot/#/builders/54/builds/10505
2024-04-03[Object][COFF][NFC] Introduce getMachineArchType helper. (#87370)Jacek Caban1-30/+12
It's a common pattern that we have a machine type, but we don't care which ARM64* platform we're dealing with. We already have isAnyArm64 for that, but it does not fit cases where we use a switch statement. With this helper, it's easy to simplify such cases by using Triple::ArchType instead of machine type.
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-3/+3
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-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-06-30[llvm-readobj] Add support for dumping CHPE metadata.Jacek Caban1-0/+48
CHPE metadata is used by ARM64EC/ARM64X PE files to provide metadata for emulator/loader. Most of this metadata will need to be generated by LLD. Differential Revision: https://reviews.llvm.org/D149089
2023-04-21[llvm-lib] [llvm-readobj] [llvm-cvtres] Add Support for ARM64X object files.Jacek Caban1-0/+5
Similar to D125411, but for ARM64X. ARM64X PE binaries are hybrids containing both ARM64EC and pure ARM64 variants in one file. They are usually linked by passing separate ARM64EC and ARM64 object files to linker. Linked binaries use ARM64 machine and contain additional CHPE metadata in their load config. CHPE metadata support is not part of this patch, I plan to send that later. Using ARM64X as a machine type of object files themselves is somewhat ambiguous, but such files are allowed by MSVC. It treats them as ARM64 or ARM64EC object, depending on the context. Such objects can be produced with cvtres.exe -machine:arm64x. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148517
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille1-2/+2
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-09Revert D139098 "[Alignment] Use Align for ObjectFile::getSectionAlignment"Guillaume Chatelet1-2/+2
This breaks lld. This reverts commit 10c47465e2505ddfee4e62a2ab2e535abea3ec56.
2022-12-09[Alignment] Use Align for ObjectFile::getSectionAlignmentGuillaume Chatelet1-2/+2
Differential Revision: https://reviews.llvm.org/D139098
2022-09-05[ARM64EC 1/?] Add parsing support to llvm-objdump/llvm-readobj.Eli Friedman1-0/+5
This is the first patch of a patchset to add initial support for ARM64EC. Basic documentation is available at https://docs.microsoft.com/en-us/windows/uwp/porting/arm64ec-abi . (Discourse post: https://discourse.llvm.org/t/initial-patches-for-arm64ec-windows-11-now-posted/62449 .) The file format for ARM64EC is basically identical to normal ARM64. There are a few extra sections, but the existing code for reading ARM64 object files just works. Differential Revision: https://reviews.llvm.org/D125411
2022-06-16[Object][COFF] Improve section name parsingPengxuan Zheng1-8/+2
Inspired by discussions on D127369, we probably can further improve LLVM's COFF section name parsing. Hopefully, this makes the logic simpler and handles some edge cases more elegantly. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D127902
2022-06-15[COFF] Don't reject executables with data directories pointing outside of ↵Martin Storsjö1-10/+4
provided data Before bb94611d6545c2c5271f5bb01de1aa4228a37250, we didn't check that the sections in the COFF executable actually contained enough raw data, when looking up what section contains tables pointed to by the data directories. That commit added checking, to avoid setting a pointer that points out of bounds - by rejecting such executables. It turns out that some binaries (e.g.g a "helper.exe" provided by NSIS) contains a base relocation table data directory that points into the wrong section. It points inside the virtual address space allocated for that section, but the section contains much less raw data, and the table points outside of the provided raw data. No longer reject such binaries (to let tools operate on them and inspect them), but don't set the table pointers (so that when printing e.g. base relocations, we don't print anything). This should fix the regression pointed out in https://reviews.llvm.org/D126898#3565834. Differential Revision: https://reviews.llvm.org/D127345
2022-06-09[Object][COFF] Fix section name parsing error when the name field is not ↵Pengxuan Zheng1-1/+1
null-padded Some object files produced by Mirosoft tools contain sections whose name field is not fully null-padded at the end. Microsoft's dumpbin is able to print the section name correctly, but this causes parsing errors with LLVM tools. So far, this issue only seems to happen when the section name is longer than 8 bytes. In this case, the section name field contains a slash (/) followed by the offset into the string table, but the name field is not fully null-padded at the end. Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D127369
2022-06-03[COFF] Fix -Wredundant-moveBenjamin Kramer1-1/+1
2022-06-03[COFF] Check table ptr more thoroughly and ignore empty sectionsAlvin Wong1-7/+50
When loading split debug files for PE/COFF executables (produced with `objcopy --only-keep-debug`), the tables or directories in such files may point to data inside sections that may have been stripped. COFFObjectFile shall detect and gracefully handle this, to allow the object file be loaded without considering these tables or directories. This is required for LLDB to load these files for use as debug symbols. COFFObjectFile shall also check these pointers more carefully to account for cases in which the section contains less raw data than the size given by VirtualSize, to prevent going out of bounds. This commit also changes COFFDump in llvm-objdump to reuse the pointers that are already range-checked in COFFObjectFile. This fixes a crash when trying to dump the TLS directory from a stripped file. Fixes https://github.com/mstorsjo/llvm-mingw/issues/284 Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D126898
2022-03-02[Object] [COFF] Improve error messagesMartin Storsjö1-36/+64
This aids debugging when working with possibly broken files, instead of just flat out erroring out without telling what's wrong. Differential Revision: https://reviews.llvm.org/D120679
2022-02-10Cleanup LLVMObject headersserge-sans-paille1-1/+1
Most notably, llvm/Object/Binary.h no longer includes llvm/Support/MemoryBuffer.h llvm/Object/MachOUniversal*.h no longer include llvm/Object/Archive.h llvm/Object/TapiUniversal.h no longer includes llvm/Object/TapiFile.h llvm-project preprocessed size: before: 1068185081 after: 1068324320 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119457
2021-05-26[NFC][object] Change the input parameter of the method isDebugSection.Esme-Yi1-1/+8
Summary: This is a NFC patch to change the input parameter of the method SectionRef::isDebugSection(), by replacing the StringRef SectionName with DataRefImpl Sec. This allows us to determine if a section is debug type in more ways than just by section name. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D102601
2021-01-17[llvm] Use llvm::sort (NFC)Kazu Hirata1-4/+3
2020-12-22Replace `T(x)` with `reinterpret_cast<T>(x)` everywhere it means ↵Arthur O'Dwyer1-10/+14
reinterpret_cast. NFC. Differential Revision: https://reviews.llvm.org/D76572
2020-10-18Fix various format specifier mismatchesHubert Tong1-2/+2
Format specifiers of incorrect length are replaced with format specifier macros from `<cinttypes>` matching the typedefs used to declare the type of the value being printed. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D89637
2020-10-08[llvm-readobj] Add --coff-tls-directory flag to print TLS Directory & test.Luqman Aden1-2/+39
Akin to dumpbin's /TLS option, this will print out the TLS directory, if present, in the image. Example output: ``` > llvm-readobj --coff-tls-directory test.exe File: test.exe Format: COFF-x86-64 Arch: x86_64 AddressSize: 64bit TLSDirectory { StartAddressOfRawData: 0x140004000 EndAddressOfRawData: 0x140004040 AddressOfIndex: 0x140002000 AddressOfCallBacks: 0x0 SizeOfZeroFill: 0x0 Characteristics [ (0x0) ] } ``` Reviewed By: jhenderson, grimar Differential Revision: https://reviews.llvm.org/D88635
2020-06-11Re-land "Migrate the rest of COFFObjectFile to Error"Reid Kleckner1-204/+200
This reverts commit 101fbc01382edd89ea7b671104c68b30b2446cc0. Remove leftover debugging attribute. Update LLDB as well, which was missed before.
2020-06-05Revert "Migrate the rest of COFFObjectFile to Error"Nico Weber1-201/+205
This reverts commit b5289656b865d2a73cf90819e20a96fb8414ab0b. __attribute__((optnone)) doesn't build with msvc, see http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/16326
2020-06-05Migrate the rest of COFFObjectFile to ErrorReid Kleckner1-205/+201
2020-06-05Re-land "Migrate Binary::checkOffset from error_code to Error, NFC"Reid Kleckner1-8/+10
This reverts commit 38f3ba591e3a64fa5bbe684b3171c7bda6c5b527. Fix the XCOFF error handling. Unlike std::error_code, Error must be consumed or handled.
2020-06-05Revert "Migrate Binary::checkOffset from error_code to Error, NFC"Nico Weber1-10/+8
This reverts commit 74bd98829d82312676a60c5c2d142e20691b2f13. Breaks LLVM::section-headers.test everywhere, see e.g. http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/29940/steps/test-check-all/logs/FAIL%3A%20LLVM%3A%3Asection-headers.test
2020-06-05Migrate Binary::checkOffset from error_code to Error, NFCReid Kleckner1-8/+10
In my use case, this saved 100ms of time doing one-time-initialization for std::error_code().
2020-05-28SymbolicFile.h - removed unused FileSystem.h include. NFC.Simon Pilgrim1-0/+1
Exposes a number of implicit dependencies that needs fixing in source files and XCOFFObjectFile.h.
2020-05-08[COFF] Use Expected in COFFObjectFile creationReid Kleckner1-30/+34
The constructor error out parameter was a bit awkward. Wrap it in a factory method which can return an error. Make the constructor private.
2020-05-08[COFF] Migrate COFFObjectFile to Expected<T>Reid Kleckner1-64/+36
I noticed that std::error_code() does one-time initialization. Avoid that overhead with Expected<T> and llvm::Error. Also, it is consistent with the virtual interface and ELF, and generally cleaner. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D79643
2020-05-02[Object] Change ObjectFile::getSymbolValue() return type to Expected<uint64_t>Xing GUO1-1/+1
Summary: In D77860, we have changed `getSymbolFlags()` return type to `Expected<uint32_t>`. This change helps bubble the error further up the stack. Reviewers: jhenderson, grimar, JDevlieghere, MaskRay Reviewed By: jhenderson Subscribers: hiraditya, MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79075
2020-04-18[Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> ↵vgxbj1-1/+1
getSymbolFlags(). This change enables getSymbolFlags() to return errors which benefit error reporting in clients. Differential Revision: https://reviews.llvm.org/D77860
2020-04-02[Object] Add the method for checking if a section is a debug sectionDjordje Todorovic1-0/+6
Different file formats have different naming style for the debug sections. The method is implemented for ELF, COFF and Mach-O formats. Differential Revision: https://reviews.llvm.org/D76276
2020-02-24[NFC] Fix typo in error messageserge-sans-paille1-1/+1
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-4/+4
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-4/+4
2019-08-30[COFF] Add a ResourceSectionRef method for getting resource contentsMartin Storsjo1-0/+117
This allows llvm-readobj to print the contents of each resource when printing resources from an object file or executable, like it already does for plain .res files. This requires providing the whole COFFObjectFile to ResourceSectionRef. This supports both object files and executables. For executables, the DataRVA field is used as is to look up the right section. For object files, ideally we would need to complete linking of them and fix up all relocations to know what the DataRVA field would end up being. In practice, the only thing that makes sense for an RVA field is an ADDR32NB relocation. Thus, find a relocation pointing at this field, verify that it has the expected type, locate the symbol it points at, look up the section the symbol points at, and read from the right offset in that section. This works both for GNU windres object files (which use one single .rsrc section, with all relocations against the base of the .rsrc section, with the original value of the DataRVA field being the offset of the data from the beginning of the .rsrc section) and cvtres object files (with two separate .rsrc$01 and .rsrc$02 sections, and one symbol per data entry, with the original pre-relocated DataRVA field being set to zero). Differential Revision: https://reviews.llvm.org/D66820 llvm-svn: 370433
2019-08-29[COFF] Add a ResourceSectionRef method for getting the data entry, print it ↵Martin Storsjo1-0/+18
in llvm-readobj Differential Revision: https://reviews.llvm.org/D66819 llvm-svn: 370311