aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/dsymutil/MachOUtils.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-08-20[AArch64][MachO] Add ptrauth ABI version to arm64e cpusubtype. (#104650)Ahmed Bougacha1-1/+2
In a mach_header, the cpusubtype is a 32-bit field, but it's split in 2 subfields: - the low 24 bits containing the cpu subtype proper, (e.g., CPU_SUBTYPE_ARM64E 2) - the high 8 bits containing a capability field used for additional feature flags. Notably, it's only the subtype subfield that participates in fat file slice discrimination: the caps are ignored. arm64e uses the caps subfield to encode a ptrauth ABI version: - 0x80 (CPU_SUBTYPE_PTRAUTH_ABI) denotes a versioned binary - 0x40 denotes a kernel-ABI binary - 0x00-0x0F holds the ptrauth ABI version This teaches the basic obj tools to decode that (or ignore it when unneeded). It also teaches the MachO writer to default to emitting versioned binaries, but with a version of 0 (and without the kernel ABI flag). Modern arm64e requires versioned binaries: a binary with 0x00 caps in cpusubtype is now rejected by the linker and everything after. We can live without the sophistication of specifying the version and kernel ABI for now. Co-authored-by: Francis Visoiu Mistrih <francisvm@apple.com>
2024-07-02Remove llvm/MC/MCAsmLayout.h and the unused parameter in MCAssembler::layoutFangrui Song1-3/+1
This restores 63ec52f867ada8d841dd872acf3d0cb62e2a99e8 and 46f7929879a59ec72dc75679b4201e2d314efba9, NFC changes that were unnecessarily reverted. This completes the work that merges MCAsmLayout into MCAssembler. Pull Request: https://github.com/llvm/llvm-project/pull/97449
2024-07-02Revert "MCAssembler::layout: remove the unused MCAsmLayout parameter"Davide Italiano1-1/+3
This reverts commit 63ec52f867ada8d841dd872acf3d0cb62e2a99e8.
2024-07-01MCAssembler::layout: remove the unused MCAsmLayout parameterFangrui Song1-3/+1
Almost complete the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01[MC] Move MCAsmLayout::SectionOrder to MachObjectWriter::SectionOrderFangrui Song1-5/+4
Follow-up to 2c1fb411ce3aed148a278660d215e0f88ff9b9be. SectionOrder is Mach-O specific to place zerofill sections after non-zerofill sections in the object writer.
2024-07-01[MC] Remove MCAsmLayout::{getSectionFileSize,getSectionAddressSize}Fangrui Song1-9/+10
2024-07-01[MC] Remove the MCAsmLayout parameter from ↵Fangrui Song1-1/+1
MCObjectWriter::{writeObject,writeSectionData}
2024-06-23[MC] Ensure all new sections have a MCDataFragmentFangrui Song1-3/+0
MCAssembler::layout ensures that every section has at least one fragment, which simplifies MCAsmLayout::getSectionAddressSize (see e73353c7201a3080851d99a16f5fe2c17f7697c6 from 2010). It's better to ensure the condition is satisfied at create time (COFF, GOFF, Mach-O) to simplify more fragment processing.
2024-06-22[MC] Remove pending labelsFangrui Song1-1/+0
This commit removes the complexity introduced by pending labels in https://reviews.llvm.org/D5915 by using a simpler approach. D5915 aimed to ensure padding placement before `.Ltmp0` for the following code, but at the cost of expensive per-instruction `flushPendingLabels`. ``` // similar to llvm/test/MC/X86/AlignedBundling/labeloffset.s .bundle_lock align_to_end calll .L0$pb .bundle_unlock .L0$pb: popl %eax .Ltmp0: //// padding should be inserted before this label instead of after addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax ``` (D5915 was adjusted by https://reviews.llvm.org/D8072 and https://reviews.llvm.org/D71368) This patch achieves the same goal by setting the offset of the empty MCDataFragment (`Prev`) in `layoutBundle`. This eliminates the need for pending labels and simplifies the code. llvm/test/MC/MachO/pending-labels.s (D71368): relocation symbols are changed, but the result is still supported by linkers.
2024-06-10[MC] Remove getFragmentList uses. NFCFangrui Song1-1/+1
2024-03-19[dsymutil] Remove support for obfuscated bitcode (#85713)Jonas Devlieghere1-5/+2
Remove support for obfuscated bitcode in dsymutil and the DWARF linker. We no longer support bitcode submissions and the obfuscation support has been removed from the rest of the compiler. rdar://123863918
2024-03-19Revert "[dsymutil] Remove support for obfuscated bitcode" (#85826)Andres Villegas1-2/+5
Reverts llvm/llvm-project#85713 Since it is breaking Linux x64 builds.
2024-03-19[dsymutil] Remove support for obfuscated bitcode (#85713)Jonas Devlieghere1-5/+2
Remove support for obfuscated bitcode in dsymutil and the DWARF linker. We no longer support bitcode submissions and the obfuscation support has been removed from the rest of the compiler. rdar://123863918
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-08-17[dsymutil] Use createTemporaryFile instead of TempFileJonas Devlieghere1-17/+30
Use createTemporaryFile in favor of the TempFile abstraction to ensure we have an on-disk file. This fixes an issue on Windows where the DWARF verifier would fail when trying to open the temporary file from disk.
2023-08-17[dsymutil] Fix MachOUtils formatting (NFC)Jonas Devlieghere1-3/+4
2023-03-27[dsymutil] Add the ability to generate universal binaries with a fat64 headerJonas Devlieghere1-2/+7
Add the ability to generate universal binaries with a fat64 header. rdar://107223939 Differential revision: https://reviews.llvm.org/D146879
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[tools] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+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[reland][Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet1-6/+6
Differential Revision: https://reviews.llvm.org/D138653
2022-11-24Revert D138653 [Alignment][NFC] Use the Align type in MCSection"Guillaume Chatelet1-6/+6
This breaks the bolt project. This reverts commit 409f0dc4a420db1c6b259d5ae965a070c169d930.
2022-11-24[Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet1-6/+6
Differential Revision: https://reviews.llvm.org/D138653
2022-03-17[dsymutil] Apply relocations present in Swift reflection sectionsAugusto Noronha1-3/+24
The strippable Swift reflection sections contain subtractor relocations that need to be applied. There are two situations we need to support. 1) Both symbols used in the relocation come from the .o file (for example, one symbol lives in __swift5_fieldmd and the second in __swift5_reflstr). 2) One symbol comes from th .o file and the second from the main binary (for example, __swift5_fieldmd and __swift5_typeref). Differential Revision: https://reviews.llvm.org/D120574
2022-03-11Return an error when dsymutil might produce an invalid mach-o file.Greg Clayton1-3/+8
64 bit mach-o files have sections that only have 32 bit file offsets. If dsymutil tries to produce an invalid mach-o file, then error out with a good error string. Differential Revision: https://reviews.llvm.org/D121398
2022-02-25[dsymutil] Copy symbol table regardless of LINKEDIT segmentJonas Devlieghere1-12/+7
Ensure we copy the symbol table for MH_PRELOAD Mach-Os, which don't have a LINKEDIT segment, but (can) have a symbol table. rdar://88919473 Differential revision: https://reviews.llvm.org/D120583
2022-02-09Cleanup LLVMMC headersserge-sans-paille1-0/+2
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
2021-01-12[dsymutil] Copy eh_frame content into the dSYM companion file.Jonas Devlieghere1-17/+63
Copy over the __eh_frame from the binary into the dSYM. This helps kernel developers that are working with only dSYMs (i.e. no binaries) when debugging a core file. This only kicks in when the __eh_frame exists in the linked binary. Most of the time ld64 will remove the section in favor of compact unwind info. When it is emitted, it's generally small enough and should not bloat the dSYM. rdar://69774935 Differential revision: https://reviews.llvm.org/D94460
2020-06-05[dsymutil] Don't emit N_AST symbol entries in the Mach-O companion fileJonas Devlieghere1-0/+8
Treat N_AST symbol table entries like other debug entries and don't emit them in the linked binary. Differential revision: https://reviews.llvm.org/D81205
2020-05-04[dsymutil] Thread the VFS through dsymutil (NFC)Jonas Devlieghere1-2/+3
This patch threads the virtual file system through dsymutil. Currently there is no good way to find out exactly what files are necessary in order to reproduce a dsymutil link, at least not without knowledge of how dsymutil's internals. My motivation for this change is to add lightweight "reproducers" that automatically gather the input object files through the FileCollectorFileSystem. The files together with the YAML mapping will allow us to transparently reproduce a dsymutil link, even without having to mess with the OSO path prefix. Differential revision: https://reviews.llvm.org/D79376
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-12-06[Dsymutil][NFC] Move NonRelocatableStringpool into common CodeGen folder.Alexey Lapshin1-2/+7
That refactoring moves NonRelocatableStringpool into common CodeGen folder. So that NonRelocatableStringpool could be used not only inside dsymutil. Differential Revision: https://reviews.llvm.org/D71068
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-06-05[dsymutil] Support more than 4 architecturesJonas Devlieghere1-1/+1
When running dsymutil on a fat binary, we use temporary files in a small vector of size four. When processing more than 4 architectures, this resulted in a user-after-move, because the temporary files got moved to the heap. Instead of storing an optional temp file, we now use a unique pointer, so the location of the actual temp file doesn't change. We could test this by checking in 5 binaries for 5 different architectures, but this seems wasteful, especially since the number of elements in the small vector is arbitrary. llvm-svn: 362621
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[dsymutil] Upstream unobfuscation logic.Jonas Devlieghere1-3/+3
The unobufscation support for BCSymbolMaps was the last piece of code that hasn't been upstreamed yet. This patch contains a reworked version of the existing code and relevant tests. Differential revision: https://reviews.llvm.org/D56346 llvm-svn: 350580
2018-11-13Make dsymutil more robust when parsing load commands.Adrian Prantl1-14/+19
rdar://problem/45883463 llvm-svn: 346815
2018-11-08[dsymutil] Copy the LC_BUILD_VERSION load command into the companion binary.Adrian Prantl1-14/+29
LC_BUILD_VERSION contains platform information that is useful for LLDB to match up dSYM bundles with binaries. This patch copies the load command over into the dSYM. rdar://problem/44145175 rdar://problem/45883463 Differential Revision: https://reviews.llvm.org/D54233 llvm-svn: 346412
2018-08-07[DebugInfo] Reduce debug_str_offsets section sizePavel Labath1-3/+2
Summary: The accelerator tables use the debug_str section to store their strings. However, they do not support the indirect method of access that is available for the debug_info section (DW_FORM_strx et al.). Currently our code is assuming that all strings can/will be referenced indirectly, and puts all of them into the debug_str_offsets section. This is generally true for regular (unsplit) dwarf, but in the DWO case, most of the strings in the debug_str section will only be used from the accelerator tables. Therefore the contents of the debug_str_offsets section will be largely unused and bloating the main executable. This patch rectifies this by teaching the DwarfStringPool to differentiate between strings accessed directly and indirectly. When a user inserts a string into the pool it has to declare whether that string will be referenced directly or not. If at least one user requsts indirect access, that string will be assigned an index ID and put into debug_str_offsets table. Otherwise, the offset table is skipped. This approach reduces the overall binary size (when compiled with -gdwarf-5 -gsplit-dwarf) in my tests by about 2% (debug_str_offsets is shrunk by 99%). Reviewers: probinson, dblaikie, JDevlieghere Subscribers: aprantl, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D49493 llvm-svn: 339122
2018-07-29[dsymutil] Simplify temporary file handling.Jonas Devlieghere1-13/+29
Dsymutil's update functionality was broken on Windows because we tried to rename a file while we're holding open handles to that file. TempFile provides a solution for this through its keep(Twine) method. This patch changes dsymutil to make use of that functionality. Differential revision: https://reviews.llvm.org/D49860 llvm-svn: 338216
2018-07-10[MC] Add interface to finish pending labels.Jonas Devlieghere1-1/+3
When manually finishing the object writer in dsymutil, it's possible that there are pending labels that haven't been resolved. This results in an assertion when the assembler tries to fixup a label that doesn't have an address yet. Differential revision: https://reviews.llvm.org/D49131 llvm-svn: 336688
2018-06-29[dsymutil] Make the CachedBinaryHolder the defaultJonas Devlieghere1-8/+14
Replaces all uses of the old binary holder with its cached variant. Differential revision: https://reviews.llvm.org/D48770 llvm-svn: 335991
2018-06-27[dsymutil] Move abstractions into separate files (NFC)Jonas Devlieghere1-2/+2
This patch splits off some abstractions used by dsymutil's dwarf linker and moves them into separate header and implementation files. This almost halves the number of LOC in DwarfLinker.cpp and makes it a lot easier to understand what functionality lives where. Differential revision: https://reviews.llvm.org/D48647 llvm-svn: 335749
2018-06-12Refactor ExecuteAndWait to take StringRefs.Zachary Turner1-8/+7
This simplifies some code which had StringRefs to begin with, and makes other code more complicated which had const char* to begin with. In the end, I think this makes for a more idiomatic and platform agnostic API. Not all platforms launch process with null terminated c-string arrays for the environment pointer and argv, but the api was designed that way because it allowed easy pass-through for posix-based platforms. There's a little additional overhead now since on posix based platforms we'll be takign StringRefs which were constructed from null terminated strings and then copying them to null terminate them again, but from a readability and usability standpoint of the API user, I think this API signature is strictly better. llvm-svn: 334518
2018-05-21MC: Change object writers to use endian::Writer. NFCI.Peter Collingbourne1-16/+13
Part of PR37466. Differential Revision: https://reviews.llvm.org/D47040 llvm-svn: 332861
2018-05-21MC: Change MCAssembler::writeSectionData and writeFragmentPadding to take a ↵Peter Collingbourne1-1/+1
raw_ostream. NFCI. Also clean up a couple of hacks where we were writing the section contents to another stream by setting the object writer's stream, writing and setting it back. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47038 llvm-svn: 332858
2018-04-14[Support] Add convenience functions to WithColor. NFC.Jonas Devlieghere1-5/+5
Create convenience functions for printing error, warning and note to stdout. Previously we had similar functions being used in dsymutil, but given that this pattern is so common it makes sense to make it available globally. llvm-svn: 330091
2018-03-13[dsymutil] Unify error handling outside DwarfLinker.Jonas Devlieghere1-4/+5
This is a follow-up to r327137 where we unified error handling for the DwarfLinker. This replaces calls to errs() and outs() with the appropriate ostream wrapper everywhere in dsymutil. llvm-svn: 327411
2018-02-22[dsymutil] Fix typos and formatting. NFC.Jonas Devlieghere1-14/+13
Some over-due gardening: this fixes a bunch of typos and makes the formatting consistent with LLVM's style guide. llvm-svn: 325768
2018-01-24[dsymutil] Make NonRelocatableStringPool a wrapper around ↵Jonas Devlieghere1-5/+8
DwarfStringPoolEntry. NFC This is needed in order to use our StringPool entries in the Apple accelerator tables. As this is NFC we rely on the existing tests for correctness. llvm-svn: 323339
2017-09-13Convenience/safety fix for llvm::sys::Execute(And|No)WaitAlexander Kornienko1-1/+1
Summary: Change the type of the Redirects parameter of llvm::sys::ExecuteAndWait, ExecuteNoWait and other APIs that wrap them from `const StringRef **` to `ArrayRef<Optional<StringRef>>`, which is safer and simplifies the use of these APIs (no more local StringRef variables just to get a pointer to). Corresponding clang changes will be posted as a separate patch. Reviewers: bkramer Reviewed By: bkramer Subscribers: vsk, llvm-commits Differential Revision: https://reviews.llvm.org/D37563 llvm-svn: 313155