summaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MachObjectWriter.cpp
AgeCommit message (Collapse)Author
2025-07-03MCAsmBackend: Replace FKF_IsPCRel with isPCRel()Fangrui Song
2025-07-01MC: Store fragment content and fixups out-of-lineFangrui Song
Moved `Contents` and `Fixups` SmallVector storage to MCSection, enabling trivial destructors for most fragment subclasses and eliminating the need for MCFragment::destroy in ~MCSection. For appending content to the current section, use getContentsForAppending. During assembler relaxation, prefer setContents/setFixups, which may involve copying and reduce the benefits of https://reviews.llvm.org/D145791. Moving only Contents out-of-line caused a slight performance regression (Alexis Engelke's 2024 prototype). By also moving Fragments out-of-line, fragment destructors become trivial, resulting in neglgible instructions:u increase for "stage2-O0-g" and [large max-rss decrease](https://llvm-compile-time-tracker.com/compare.php?from=84e82746c3ff63ec23a8b85e9efd4f7fccf92590&to=555a28c0b2f8250a9cf86fd267a04b0460283e15&stat=max-rss&linkStats=on) for the "stage1-ReleaseLTO-g (link only)" benchmark. ( An older version using fewer inline functions: https://llvm-compile-time-tracker.com/compare.php?from=bb982e733cfcda7e4cfb0583544f68af65211ed1&to=f12d55f97c47717d438951ecddecf8ebd28c296b&linkStats=on ) Now using plain SmallVector in MCSection for storage, with potential for future allocator optimizations, such as allocating `Contents` as the trailing object of MCDataFragment. (GNU Assembler uses gnulib's obstack for fragment management.) Co-authored-by: Alexis Engelke <engelke@in.tum.de> Pull Request: https://github.com/llvm/llvm-project/pull/146307
2025-06-30MC: Merge MCFragment.h into MCSection.hFangrui Song
... due to their close relationship. MCSection's inline functions (e.g. iterator) access MCFragment, and we want MCFragment's inline functions to access MCSection similarly (#146307). Pull Request: https://github.com/llvm/llvm-project/pull/146315
2025-05-25MachObjectWriter: Simplify Asm.getContext().reportErrorFangrui Song
Similar to b65760bc7fcdee8179bf1e57fce3786737528dd8 for ELF.
2025-05-25MachObjectWriter: Remove the MCAssembler argument from getSymbolAddressFangrui Song
2025-05-24MCObjectWriter: Remove the MCAssembler argument from writeObjectFangrui Song
2025-05-24MC: Simplify recordRelocationFangrui Song
* Remove the MCAssembler * argument. Change subclasses to use MCAssembler *MCObjectWriter::Asm. * Remove pure specifier and add an empty implementation * Change MCFragment * to MCFragment &
2025-05-24MCObjectwriter: Add getContext and simplify codeFangrui Song
2025-05-24MCObjectwriter: Add member variable MCAssembler * and simplify codeFangrui Song
2025-04-18MCFixup: Make FixupKindInfo smaller and change getFixupKindInfo to return valueFangrui Song
We will increase the use of raw relocation types and eliminate fixup kinds that correspond to relocation types. The getFixupKindInfo functions will return an rvalue instead. Let's update the return type from a const reference to a value type.
2025-04-06[MC,MachO] Replace SectionAddrMap workaround with cleaner variable handlingFangrui Song
Mach-O's ARM and X86 writers use MCExpr's `SectionAddrMap *Addrs` argument to compute label differences, which was a bit of a hack. The AArch64MachObjectWriter does this better by using `getSymbolAddress` in its `recordRelocation` function. This commit: 1. Moves the `SectionAddrMap` logic into the Mach-O code, removing the workaround. 2. Fixes a bug in `MachObjectWriter::getSymbolAddress` where it failed to subtract the `SymB` value. This bug has been present since commit b200f93125eb019d69c220fa447faea4f5d4eb8a (2011).
2025-04-05[MC] Replace getSymA()->getSymbol() with getAddSym. NFCFangrui Song
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol. This change reduces dependence on MCSymbolRefExpr.
2025-04-05[MC] Replace getSymA()->getSymbol() with getAddSym. NFCFangrui Song
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol. This change reduces dependence on MCSymbolRefExpr.
2025-03-23MCValue: Simplify code with getSubSymFangrui Song
MCValue::SymB is a MCSymbolRefExpr *, which might become MCSymbol * in the future. Simplify some code that uses MCValue::SymB.
2025-03-15[MC] evaluateAsRelocatableImpl: remove the Fixup argumentFangrui Song
Follow-up to d6fbffa23c84e622735b3e880fd800985c1c0072 . This commit updates all call sites and removes the argument from the function.
2024-11-15[MC] Remove unused includes (NFC) (#116317)Kazu Hirata
Identified with misc-include-cleaner.
2024-08-20[AArch64][MachO] Add ptrauth ABI version to arm64e cpusubtype. (#104650)Ahmed Bougacha
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-24MC: Inline createMachObjectWriter into MCAsmBackendFangrui Song
We could do the same to COFF once WinCOFFObjectWriter is cleaned up (#100303).
2024-07-22MCAssembler: Move SubsectionsViaSymbols; to MCObjectWriterFangrui Song
2024-07-22MCAssembler: Move LinkerOptions to MachObjectWriterFangrui Song
2024-07-22MCAssembler: Move CGProfile to MCObjectWriterFangrui Song
2024-07-21[MC] Move VersionInfo to MachObjectWriterFangrui Song
2024-07-21[MC] Move LOHContainer to MachObjectwriterFangrui Song
2024-07-21[MC] Move isPrivateExtern to MCSymbolMachOFangrui Song
2024-07-17[MachO] Detect overflow in section offset. (#98685)Eli Friedman
The section offset field is only 32 bits; if the computed section offset is larger, make sure we don't emit a corrupt object file.
2024-07-05MCAssembler: Remove unneeded non-const iterators for Sections and misleading ↵Fangrui Song
size() The pointers cannot be mutated even if the dereferenced MCSection can.
2024-07-04[MC] Move MCAssembler::DataRegions to MachObjectWriterFangrui Song
and make some cleanup.
2024-07-04[MC] Move MCAssembler::IndirectSymbols to MachObjectWriterFangrui Song
2024-07-04[MC,MachO] Simplify IndirectSybolsFangrui Song
2024-07-03[MC] Move MCAssembler::isSymbolLinkerVisible to MCSymbolMachOFangrui Song
2024-07-02Move MCSection::LayoutOrder to MCSectionMachOFangrui Song
This variable is similar to `Ordinal` but only used for Mach-O to place zerofill sections ("virtual sections" in MC term) after non-zerofill ones. Follow-up to 7840c0066837797cdeb62aab63044b964aa7f372. Pull Request: https://github.com/llvm/llvm-project/pull/97474
2024-07-01MachObjectWriter: replace the MCAsmLayout parameter with MCAssemblerFangrui Song
2024-07-01MCExpr::evaluateAsRelocatable: replace the MCAsmLayout parameter with ↵Fangrui Song
MCAssembler Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01MachObjectWrite::reset: clear SectionAddress and SectionOrderFangrui Song
Otherwise llvm/test/MC/MachO/empty-twice.ll might fail. Fixes: 7840c0066837797cdeb62aab63044b964aa7f372 ("[MC] Move MCAsmLayout::SectionOrder to MachObjectWriter::SectionOrder")
2024-07-01[MC] Move MCAsmLayout::SectionOrder to MachObjectWriter::SectionOrderFangrui Song
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::{getSymbolOffset,getBaseSymbol}Fangrui Song
The MCAsmLayout::* forwarders added by 67957a45ee1ec42ae1671cdbfa0d73127346cc95 have all been removed.
2024-07-01[MC] Remove MCAsmLayout::{getSectionFileSize,getSectionAddressSize}Fangrui Song
2024-07-01[MC] Remove MCAsmLayout::getFragmentAddressFangrui Song
2024-07-01[MC] Remove the MCAsmLayout parameter from ↵Fangrui Song
MCObjectWriter::executePostLayoutBinding
2024-07-01[MC] Remove the MCAsmLayout parameter from ↵Fangrui Song
MCObjectWriter::{writeObject,writeSectionData}
2024-06-30[MC] Remove the MCAsmLayout parameter from MCObjectWriter::recordRelocationFangrui Song
2024-06-30[MC] Remove the MCAsmLayout parameter from MCMachObjectTargetWriterFangrui Song
2024-06-30[MC] Move Mach-O specific getAtom and isSectionAtomizableBySymbols to Mach-O ↵Fangrui Song
files and devirtualize isSectionAtomizableBySymbols.
2024-06-29[MC] Remove an overload of isSymbolRefDifferenceFullyResolvedImplFangrui Song
e3a20f57d927e422874a8e7730bb7590515b586d (2015) overloaded isSymbolRefDifferenceFullyResolvedImpl with the IsPCRel parameter. The overload without IsPCRel is only customized by Mach-O to dsiable `.long L_var4 - L_var3` folding in darwin-x86_64-diff-reloc-assign-2.s, but that seems unnecessary.
2024-06-29[MC,MachO] Remove unneeded condition from isSymbolRefDifferenceFullyResolvedImplFangrui Song
The code change from 91ea511436232c3b240d5f0a67a4639d7149dfdc (2011) can now be removed.
2024-06-10[MC] Remove getFragmentList uses. NFCFangrui Song
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata
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-08-19[MC] Remove an unneeded Darwin x86_64 workaroundFangrui Song
The workaround (relocation suppression) from 7b46bb8e327d45598eb794e14fc87e8c2a55f65e (2011) has been unneeded after bfd0f01dd75f299bb521a2a31f270b3687be2cee (2014) removed `if (!A_base) return false;` and `if (!B_base) return false;`
2023-05-04[MC] registerSymbol: change an output paramter to return valueFangrui Song
2022-11-24[reland][Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet
Differential Revision: https://reviews.llvm.org/D138653