aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2019-08-29[COFF] Add a bounds checking helper for iterating a coff_resource_dir_tableMartin Storsjo1-0/+22
Instead of blindly incrementing pointers in llvm-readobj, use this helper, which does bounds checking against the available section data. Differential Revision: https://reviews.llvm.org/D66818 llvm-svn: 370310
2019-08-29[COFF] Fix error handling in ResourceSectionRefMartin Storsjo1-3/+6
Previously, the expression (Reader.readFoo()) was expanded twice, triggering asserts as one of the Error types ends up not checked (and as it was expanded twice, the method would end up called twice if it failed first). Differential Revision: https://reviews.llvm.org/D66817 llvm-svn: 370309
2019-08-19[Object/COFF.h] - Stop returning std::error_code in a few methods. NFCI.George Rimar1-23/+0
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-08-14Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-4/+5
Expected<>" Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368826
2019-08-14Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-5/+4
Expected<>" It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 llvm-svn: 368813
2019-08-14[llvm/Object] - Convert SectionRef::getName() to return Expected<>George Rimar1-4/+5
SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368812
2019-05-14[Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song1-11/+10
Expected<ArrayRef<uint8_t>> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected<ArrayRef<uint8_t>> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef<uint8_t> as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648
2019-05-02[Object] Change getSectionName() to return Expected<StringRef>Fangrui Song1-10/+10
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-04-04[COFF] Fix delay import directory iteratorJoseph Tremoulet1-1/+1
Summary: Take the Index into account in `getDelayImportTable`, otherwise we always return the entry for the first delay DLL reference. Reviewers: ruiu Reviewed By: ruiu Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60081 llvm-svn: 357697
2019-01-27[COFF] Add new relocation types.Martin Storsjo1-0/+3
Differential Revision: https://reviews.llvm.org/D57291 llvm-svn: 352324
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
2019-01-03[llvm-readobj] [COFF] Print the symbol index for relocationsMartin Storsjo1-0/+10
There can be multiple local symbols with the same name (for e.g. comdat sections), and thus the symbol name itself isn't enough to disambiguate symbols. Differential Revision: https://reviews.llvm.org/D56140 llvm-svn: 350288
2018-12-19[llvm-objcopy] Initial COFF supportMartin Storsjo1-0/+12
This is an initial implementation of no-op passthrough copying of COFF with objcopy. Differential Revision: https://reviews.llvm.org/D54939 llvm-svn: 349605
2018-12-08[COFF] Map truncated .eh_frame section nameMartin Storsjo1-0/+6
PE/COFF sections can have section names truncated to 8 chars, in order to have the name available at runtime. (The string table, where long untruncated names are stored, isn't loaded at runtime.) This allows various llvm tools to dump the .eh_frame section from such executables. Patch by Peiyuan Song! Differential Revision: https://reviews.llvm.org/D55407 llvm-svn: 348708
2018-09-05Handle zero-length debug directory entries.Nico Weber1-4/+6
Part of https://reviews.llvm.org/D51652 (tests will be in the lld repo) llvm-svn: 341485
2018-08-27[COFF] Expose an easier helper function for getting names for relocation typesMartin Storsjo1-16/+18
The existing method is protected, and requires using DataRefImpl and SmallVector. Differential Revision: https://reviews.llvm.org/D50995 llvm-svn: 340725
2018-07-30Remove trailing spaceFangrui Song1-1/+1
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2018-07-20[COFF] Adjust how we flag weak externalsMartin Storsjo1-4/+4
This fixes PR36096. Originally based on a patch by Martell Malone. Differential Revision: https://reviews.llvm.org/D44357 llvm-svn: 337613
2018-07-11[llvm-readobj] Add -hex-dump (-x) optionPaul Semel1-0/+15
Differential Revision: https://reviews.llvm.org/D48281 llvm-svn: 336782
2018-07-04[llvm-objdump] Add --file-headers (-f) optionPaul Semel1-0/+6
llvm-svn: 336284
2018-04-17COFF: Make SectionChunk::Relocs field an ArrayRef. NFCI.Peter Collingbourne1-6/+3
Differential Revision: https://reviews.llvm.org/D45714 llvm-svn: 330172
2018-04-12[NFC] fix trivial typos in documents and commentsHiroshi Inoue1-1/+1
"is is" -> "is", "if if" -> "if", "or or" -> "or" llvm-svn: 329878
2017-12-14Fix many -Wsign-compare and -Wtautological-constant-compare warnings.Zachary Turner1-1/+1
Most of the -Wsign-compare warnings are due to the fact that enums are signed by default in the MS ABI, while the tautological comparison warnings trigger on x86 builds where sizeof(size_t) is 4 bytes, so N > numeric_limits<unsigned>::max() is always false. Differential Revision: https://reviews.llvm.org/D41256 llvm-svn: 320750
2017-10-11Convert the last uses of ErrorOr in COFF.h.Rafael Espindola1-7/+6
llvm-svn: 315480
2017-10-11Convert a couple of ErrorOr to Expected. NFC.Rafael Espindola1-8/+10
llvm-svn: 315475
2017-10-10Convert two uses of ErrorOr to Expected.Rafael Espindola1-2/+2
llvm-svn: 315354