aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-readobj/COFFDumper.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-05-08[COFF] Migrate COFFObjectFile to Expected<T>Reid Kleckner1-29/+31
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-06[COFF] Dump string table size for COFF file headersReid Kleckner1-0/+1
I couldn't find this info in any other dumper, so it might as well be here.
2020-04-29[llvm-readobj] [COFF] Cope with debug directory payloads in unmapped areasMartin Storsjö1-0/+4
According to the spec, the payload for debug directories can be in parts of the binary that aren't mapped at runtime - in these cases, AddressOfRawData is just set to zero. Differential Revision: https://reviews.llvm.org/D78920
2020-03-16Implement CET Shadow Stack (Intel Controlflow Enforcement Technology) ↵Rui Ueyama1-19/+34
support on Windows Patch by Petr Penzin. Windows support for CET is limited to shadow stack, which is enabled by setting a PE bit in the linker. Docs: MSVC linker flag: https://docs.microsoft.com/en-us/cpp/build/reference/cetcompat?view=vs-2019 IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT PE bit: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#extended-dll-characteristics Differential Revision: https://reviews.llvm.org/D70606
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-08-30[COFF] Add a ResourceSectionRef method for getting resource contentsMartin Storsjo1-1/+7
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/+7
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-16/+2
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[llvm-readobj] Remove a leftover string trim operation. NFC.Martin Storsjo1-1/+0
This became unnecessary in SVN r359153. Differential Revision: https://reviews.llvm.org/D66815 llvm-svn: 370307
2019-08-22[llvm-readobj] - Remove `reportError(std::error_code EC, StringRef Input)` ↵George Rimar1-54/+66
helper. We do not need it, std::error_code is used mostly for COFF and this patch rewrites the calls to use a different overload. Having reportError(std::error_code EC, ... is excessive by itself, because API that use error codes actually needs refactoring to use Error/Expected<> instead. DIfferential revision: https://reviews.llvm.org/D66521 llvm-svn: 369630
2019-08-19[Object/COFF.h] - Stop returning std::error_code in a few methods. NFCI.George Rimar1-8/+2
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-17Recommit r369190 "[llvm-readobj/llvm-readelf] - Improve/cleanup the error ↵George Rimar1-53/+87
reporting API." Fix: Add a `consumeError` call removed by mistake to 'printStackSize', this should fix the "Expected<T> must be checked before access or destruction." reported by following bot: http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio Original commit message: Currently we have the following functions for error reporting: LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg); void reportError(Error Err, StringRef Input); void reportWarning(Twine Msg); void reportWarning(StringRef Input, Error Err); void warn(llvm::Error Err); void error(std::error_code EC); Problems are: naming is inconsistent, arguments order is inconsistent, some of the functions looks excessive. After applying this patch we have: void reportError(Error Err, StringRef Input); void reportError(std::error_code EC, StringRef Input); void reportWarning(Error Err, StringRef Input); I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it is used by COFF heavily. Test cases were updated, they show an improvement introduced. Differential revision: https://reviews.llvm.org/D66286 llvm-svn: 369194
2019-08-17Revert r369190, r369192 ([llvm-readobj/llvm-readelf] - Improve/cleanup the ↵George Rimar1-87/+53
error reporting API.) It caused multiple BB failtures: http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/9743/steps/stage%201%20check/logs/stdio http://lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/26042/steps/ninja%20check%201/logs/FAIL%3A%20LLVM%3A%3Astack-sizes.test llvm-svn: 369193
2019-08-17[llvm-readobj/llvm-readelf] - Improve/cleanup the error reporting API.George Rimar1-53/+87
urrently we have the following functions for error reporting: -- LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg); void reportError(Error Err, StringRef Input); void reportWarning(Twine Msg); void reportWarning(StringRef Input, Error Err); void warn(llvm::Error Err); void error(std::error_code EC); --- Problems are: naming is inconsistent, arguments order is inconsistent, some of the functions looks excessive. After applying this patch we have: --- LLVM_ATTRIBUTE_NORETURN void reportError(Error Err, StringRef Input); LLVM_ATTRIBUTE_NORETURN void reportError(std::error_code EC, StringRef Input); void reportWarning(Error Err, StringRef Input); --- I'd be happy to remove reportError(std::error_code EC, StringRef Input) too, but it is used by COFF heavily. Test cases were updated, they show an improvement introduced. Differential revision: https://reviews.llvm.org/D66286 llvm-svn: 369190
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-08-14Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return ↵George Rimar1-17/+17
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-17/+17
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-17/+17
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-08-13[llvm-readobj] - Remove 'error(Error EC)' helper.George Rimar1-25/+48
We do not need it. I replaced it with reportError(StringRef Input, Error Err). Differential revision: https://reviews.llvm.org/D66011 llvm-svn: 368677
2019-08-09[llvm-readobj] - Remove `error(llvm::Expected<T> &&E)`George Rimar1-3/+6
This is a bit strange method. It works like a unwrapOrError, but named error. It does not report an Input name. I removed it. Differential revision: https://reviews.llvm.org/D66000 llvm-svn: 368430
2019-08-09[llvm-readobj] - Remove deprecated unwrapOrError(Expected<T> EO).George Rimar1-12/+18
This patch changes the code to use a modern unwrapOrError(StringRef Input, Expected<T> EO) version that contains the input source name and removes the deprecated version. Differential revision: https://reviews.llvm.org/D65946 llvm-svn: 368428
2019-08-09[llvm-readobj] - Remove unwrapOrError(ErrorOr<T> EO) helper.George Rimar1-5/+11
It is outdated. Using of Expected<> is preferred, also it does not provide a way to report a file name. I updated the code to use the modern version of unwrapOrError instead. Differential revision: https://reviews.llvm.org/D65951 llvm-svn: 368410
2019-06-18[PDB] Ignore .debug$S subsections with high bit setReid Kleckner1-0/+5
Some versions of the Visual C++ 2015 runtime have line tables with the subsection kind of 0x800000F2. In cvinfo.h, 0x80000000 is documented to be DEBUG_S_IGNORE. This appears to implement the intended behavior. llvm-svn: 363724
2019-06-12[llvm-readobj] Fix output interleaving issue caused by using multiple ↵Jordan Rupprecht1-1/+1
streams at the same time. Summary: Use llvm::fouts() as the default stream for outputing. No new stream should be constructed to output at the same time. https://bugs.llvm.org/show_bug.cgi?id=42140 Reviewers: jhenderson, grimar, MaskRay, phosek, rupprecht Reviewed By: rupprecht Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63115 Patch by Yuanfang Chen! llvm-svn: 363198
2019-05-16Recommit [Object] Change object::SectionRef::getContents() to return ↵Fangrui Song1-18/+8
Expected<StringRef> r360876 didn't fix 2 call sites in clang. Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. Follow-up of D61781. llvm-svn: 360892
2019-05-16Revert r360876 "[Object] Change object::SectionRef::getContents() to return ↵Hans Wennborg1-8/+18
Expected<StringRef>" It broke the Clang build, see llvm-commits thread. > Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. > > Follow-up of D61781. llvm-svn: 360878
2019-05-16[Object] Change object::SectionRef::getContents() to return Expected<StringRef>Fangrui Song1-18/+8
Expected<ArrayRef<uint8_t>> may be better but use Expected<StringRef> for now. Follow-up of D61781. llvm-svn: 360876
2019-05-02[llvm-readobj] Delete and inline relocAddressLessFangrui Song1-1/+3
It is used only once in COFFDumper.cpp. Deleting it from the public interface seems better. llvm-svn: 359775
2019-05-02[Object] Change getSectionName() to return Expected<StringRef>Fangrui Song1-22/+14
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-26Minor formatting tweak, no behavior changeNico Weber1-4/+7
llvm-svn: 359295
2019-04-24llvm-cvtres: Make new dupe resource error a bit friendlierNico Weber1-26/+3
For well-known type IDs, include the name of the type. To not duplicate the ID->name map, make llvm-readobj call this new function as well. It has slightly different output, so this also requires updating a few tests. Differential Revision: https://reviews.llvm.org/D61086 llvm-svn: 359153
2019-04-22Use llvm::stable_sort. NFCFangrui Song1-1/+1
llvm-svn: 358897
2019-04-13[llvm-readobj] Minor style tweak for consistency sake [NFC]Philip Reames1-2/+2
llvm-svn: 358323
2019-04-13[StackMaps] Remove format version from the class name [NFC]Philip Reames1-2/+2
Motivation is to reduce silly diffs when we change the format. For instance, this causes most of D59020 to disappear. llvm-svn: 358322
2019-04-07Change some StringRef::data() reinterpret_cast to bytes_begin() or ↵Fangrui Song1-8/+6
arrayRefFromStringRef() llvm-svn: 357852
2019-02-21Fix some include order and file headers issues. NFCFangrui Song1-1/+1
llvm-svn: 354550
2019-02-07[CodeView] Fix cycles in debug info when merging Types with global hashes Alexandre Ganea1-18/+25
When type streams with forward references were merged using GHashes, cycles were introduced in the debug info. This was caused by GlobalTypeTableBuilder::insertRecordAs() not inserting the record on the second pass, thus yielding an empty ArrayRef at that record slot. Later on, upon PDB emission, TpiStreamBuilder::commit() would skip that empty record, thus offseting all indices that came after in the stream. This solution comes in two steps: 1. Fix the hash calculation, by doing a multiple-step resolution, iff there are forward references in the input stream. 2. Fix merge by resolving with multiple passes, therefore moving records with forward references at the end of the stream. This patch also adds support for llvm-readoj --codeview-ghash. Finally, fix dumpCodeViewMergedTypes() which previously could reference deleted memory. Fixes PR40221 Differential Revision: https://reviews.llvm.org/D57790 llvm-svn: 353412
2019-01-23[llvm-readelf] Don't suppress static symbol table with --dyn-symbols + --symbolsJames Henderson1-2/+2
In r287786, a bug was introduced into llvm-readelf where it didn't print the static symbol table if both --symbols and --dyn-symbols were specified, even if there was no dynamic symbol table. This is obviously incorrect. This patch fixes this issue, by delegating the decision of which symbol tables should be printed to the final dumper, rather than trying to decide in the command-line option handling layer. The decision was made to follow the approach taken in this patch because the LLVM style dumper uses a different order to the original GNU style behaviour (and GNU readelf) for ELF output. Other approaches resulted in behaviour changes for other dumpers which felt wrong. In particular, I wanted to avoid changing the order of the output for --symbols --dyn-symbols for LLVM style, keep what is emitted by --symbols unchanged for all dumpers, and avoid having different orders of .dynsym and .symtab dumping for GNU "--symbols" and "--symbols --dyn-symbols". Reviewed by: grimar, rupprecht Differential Revision: https://reviews.llvm.org/D57016 llvm-svn: 351960
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-07[CodeView] More appropriate name and type for a Microsoft precompiled ↵Alexandre Ganea1-2/+2
headers parameter. NFC llvm-svn: 350520
2019-01-03[llvm-readobj] [COFF] Print the symbol index for relocationsMartin Storsjo1-0/+4
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-11-12[llvm-readelf] Make llvm-readelf more compatible with GNU readelf.Jordan Rupprecht1-3/+3
Summary: This change adds a bunch of options that GNU readelf supports. There is one breaking change when invoked as `llvm-readobj`, and three breaking changes when invoked as `llvm-readelf`: - Add --all (implies --file-header, --program-headers, etc.) - [Breaking] -a is --all instead of --arm-attributes - Add --file-header as an alias for --file-headers - Replace --sections with --sections-headers, keeping --sections as an alias for it - Add --relocs as an alias for --relocations - Add --dynamic as an alias for --dynamic-table - Add --segments as an alias for --program-headers - Add --section-groups as an alias for --elf-section-groups - Add --dyn-syms as an alias for --dyn-symbols - Add --syms as an alias for --symbols - Add --histogram as an alias for --elf-hash-histogram - [Breaking] When invoked as `llvm-readelf`, -s is --symbols instead of --sections - [Breaking] When invoked as `llvm-readelf`, -t is no longer an alias for --symbols Reviewers: MaskRay, phosek, mcgrathr, jhenderson Reviewed By: MaskRay, jhenderson Subscribers: sbc100, aheejin, edd, jhenderson, silvas, echristo, compnerd, kristina, javed.absar, kristof.beyls, llvm-commits, Bigcheese Differential Revision: https://reviews.llvm.org/D54124 llvm-svn: 346685
2018-11-05[COFF][LLD] Add link support for Microsoft precompiled headers OBJsAlexandre Ganea1-1/+3
This change allows for link-time merging of debugging information from Microsoft precompiled types OBJs compiled with cl.exe /Z7 /Yc and /Yu. This fixes llvm.org/PR34278 Differential Revision: https://reviews.llvm.org/D45213 llvm-svn: 346154
2018-10-24[ARM64][Windows] Add unwind support to llvm-readobjSanjin Sijaric1-1/+3
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-09-27llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song1-2/+1
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits Differential Revision: https://reviews.llvm.org/D52573 llvm-svn: 343163
2018-09-11[codeview] Decode and dump FP regs from S_FRAMEPROC recordsReid Kleckner1-1/+6
Summary: There are two registers encoded in the S_FRAMEPROC flags: one for locals and one for parameters. The encoding is described by the ExpandEncodedBasePointerReg function in cvinfo.h. Two bits are used to indicate one of four possible values: 0: no register - Used when there are no variables. 1: SP / standard - Variables are stored relative to the standard SP for the ISA. 2: FP - Variables are addressed relative to the ISA frame pointer, i.e. EBP on x86. If realignment is required, parameters use this. If a dynamic alloca is used, locals will be EBP relative. 3: Alternative - Variables are stored relative to some alternative third callee-saved register. This is required to address highly aligned locals when there are dynamic stack adjustments. In this case, both the incoming SP saved in the standard FP and the current SP are at some dynamic offset from the locals. LLVM uses ESI in this case, MSVC uses EBX. Most of the changes in this patch are to pass around the CPU so that we can decode these into real, named architectural registers. Subscribers: hiraditya Differential Revision: https://reviews.llvm.org/D51894 llvm-svn: 341999
2018-09-07[codeview] Improve readobj FPO dumper and pdbutil register namesReid Kleckner1-1/+19
The improved dumping helps me investigate PR38857. llvm-svn: 341695
2018-09-05Handle zero-length debug directory entries.Nico Weber1-1/+1
Part of https://reviews.llvm.org/D51652 (tests will be in the lld repo) llvm-svn: 341485
2018-08-22MC: Teach the COFF object writer to write address-significance tables.Peter Collingbourne1-0/+45
The format is the same as in ELF: a sequence of ULEB128-encoded symbol indexes. Differential Revision: https://reviews.llvm.org/D51047 llvm-svn: 340499
2018-07-25[llvm-readobj] Generic hex-dump optionPaul Semel1-23/+0
Helpers are available to make this option file format independant. This patch adds the feature for Wasm file format. It doesn't change the behavior of the other file format handling. Differential Revision: https://reviews.llvm.org/D49545 llvm-svn: 337896