aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MachObjectWriter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-06-30[MC] Remove the MCAsmLayout parameter from MCMachObjectTargetWriterFangrui Song1-2/+2
2024-06-30[MC] Move Mach-O specific getAtom and isSectionAtomizableBySymbols to Mach-O ↵Fangrui Song1-0/+31
files and devirtualize isSectionAtomizableBySymbols.
2024-06-29[MC] Remove an overload of isSymbolRefDifferenceFullyResolvedImplFangrui Song1-12/+0
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 Song1-11/+1
The code change from 91ea511436232c3b240d5f0a67a4639d7149dfdc (2011) can now be removed.
2024-06-10[MC] Remove getFragmentList uses. NFCFangrui Song1-5/+3
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-08-19[MC] Remove an unneeded Darwin x86_64 workaroundFangrui Song1-10/+0
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 Song1-3/+1
2022-11-24[reland][Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet1-4/+3
Differential Revision: https://reviews.llvm.org/D138653
2022-11-24Revert D138653 [Alignment][NFC] Use the Align type in MCSection"Guillaume Chatelet1-3/+4
This breaks the bolt project. This reverts commit 409f0dc4a420db1c6b259d5ae965a070c169d930.
2022-11-24[Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet1-4/+3
Differential Revision: https://reviews.llvm.org/D138653
2022-10-11[MC] .addrsig_sym: ignore unregistered symbolsFangrui Song1-0/+2
.addrsig_sym forces registering the symbol regardless whether it is otherwise registered. This creates an undefined symbol which is inconvenient/undesired: * `extern int x; void f() { (void)x; }` has inconsistent behavior whether `x` is emitted as an undefined symbol. `-O0 -faddrsig` makes `x` undefined while other -O levels and -fno-addrsig eliminate the symbol. * In ThinLTO, after a non-prevailing linkonce_odr definition is converted to available_externally, and then a declaration, the addrsig code emits a symbol while the symbol is otherwise unseen. D135427 fixed a bug that a non-prevailing `__cxx_global_var_init` was incorrectly retained. However, the IR declaration causes an undesired `.addrsig_sym __cxx_global_var_init`. This can be addressed in a way similar to D101512 (`isTransitiveUsedByMetadataOnly`) but the increased `OutStreamer->emitAddrsigSym(getSymbol(&GV));` complexity makes me nervous. Just ignoring unregistered symbols circumvents the problem. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D135642
2022-07-19[MC][MachO] Change addrsig format + ensure its size is properly setJez Ng1-15/+10
There were two problems with the previous setup: 1. We weren't setting its size, which caused problems when `__llvm_addrsig` wasn't the last section. In particular, `__debug_line` (if created) is generated and placed after `__llvm_addrsig`, and would result in an invalid object file w/ overlapping sections being emitted. 2. The symbol indices could be invalidated if e.g. `llvm-strip` ran on the object file. See discussion [here][1]. To fix both these issues, we use symbol relocations instead of encoding symbol indices directly in the section contents. The section itself doesn't contain any data. That sidesteps the layout problem in addition to solving the second issue. The corresponding LLD change to read in this new format: {D128938}. It will fix the icf-safe.ll test failure on this diff. [1]: https://discourse.llvm.org/t/problems-with-mach-o-address-significance-table-generation/63392/ Reviewed By: #lld-macho, alx32 Differential Revision: https://reviews.llvm.org/D127637
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata1-2/+2
2022-05-03Implement support for __llvm_addrsig for MachO in llvm-mcAlex Borcan1-0/+21
The __llvm_addrsig section is a section that the linker needs for safe icf. This was not yet implemented for MachO - this is the implementation. It has been tested with a safe deduplication implementation inside lld. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D123751
2022-01-13MC: Use SmallVector::clear() instead of set_size(0)Duncan P. N. Exon Smith1-1/+1
2022-01-12[MachO] Port call graph profile section and directiveLeonard Grey1-0/+17
This ports the `.cg_profile` assembly directive and call graph profile section generation to MachO from COFF/ELF. Due to MachO section naming rules, the section is called `__LLVM,__cg_profile` rather than `.llvm.call-graph-profile` as in COFF/ELF. Support for llvm-readobj is included to facilitate testing. Corresponding LLD change is D112164 Differential Revision: https://reviews.llvm.org/D112160
2021-12-24Use Optional::getValueOr (NFC)Kazu Hirata1-2/+2
2021-12-09[llvm] Use range-based for loops (NFC)Kazu Hirata1-4/+4
2021-12-07[macho] add support for emitting macho files with two build version load ↵Alex Lorenz1-32/+48
commands This patch extends LLVM IR to add metadata that can be used to emit macho files with two build version load commands. It utilizes "darwin.target_variant.triple" and "darwin.target_variant.SDK Version" metadata names for that, which will be set by a future patch in clang. MachO uses two build version load commands to represent an object file / binary that is targeting both the macOS target, and the Mac Catalyst target. At runtime, a dynamic library that supports both targets can be loaded from either a native macOS or a Mac Catalyst app on a macOS system. We want to add support to this to upstream to LLVM to be able to build compiler-rt for both targets, to finish the complete support for the Mac Catalyst platform, which is right now targetable by upstream clang, but the compiler-rt bits aren't supported because of the lack of this multiple build version support. Differential Revision: https://reviews.llvm.org/D112189
2021-11-06[llvm] Use llvm::reverse (NFC)Kazu Hirata1-1/+1
2020-04-15[MC] Rename MCSection*::getSectionName() to getName(). NFCFangrui Song1-1/+1
A pending change will merge MCSection*::getName() to MCSection::getName().
2020-02-11[MachO] Pad section data to pointer size bytesAditya Nandakumar1-2/+2
https://reviews.llvm.org/D74273 Pad macho section data to pointer size bytes, so that relocation table and symbol table following section data will be pointer size aligned. Patch by pguo.
2019-09-27[Alignment][NFC] Remove unneeded llvm:: scoping on Align typesGuillaume Chatelet1-6/+6
llvm-svn: 373081
2019-09-12[Alignment] Move OffsetToAlignment to Alignment.hGuillaume Chatelet1-4/+8
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, JDevlieghere, alexshap, rupprecht, jhenderson Subscribers: sdardis, nemanjai, hiraditya, kbarton, jakehehrlich, jrtc27, MaskRay, atanasyan, jsji, seiya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D67499 llvm-svn: 371742
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-03-06[MC][MachO] Emit an error for emitting relocations of the form -SYM + cstFrancis Visoiu Mistrih1-0/+15
Emit an error for an unsupported relocation. mach-o relocations can't encode the form -SYM + cst. Differential Revision: https://reviews.llvm.org/D58944 llvm-svn: 355527
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
2018-12-14[macho] save the SDK version stored in module metadata into the version min andAlex Lorenz1-7/+16
build version load commands in the object file This commit introduces a new metadata node called "SDK Version". It will be set by the frontend to mark the platform SDK (macOS/iOS/etc) version which was used during that particular compilation. This node is used when machine code is emitted, by either saving the SDK version into the appropriate macho load command (version min/build version), or by emitting the assembly for these load commands with the SDK version specified as well. The assembly for both load commands is extended by allowing it to contain the sdk_version X, Y [, Z] trailing directive to represent the SDK version respectively. rdar://45774000 Differential Revision: https://reviews.llvm.org/D55612 llvm-svn: 349119
2018-09-27llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song1-2/+2
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-07-30Remove trailing spaceFangrui Song1-1/+1
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2018-05-21MC: Have the object writers return the number of bytes written. NFCI.Peter Collingbourne1-2/+6
This removes the last external use of the stream. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47042 llvm-svn: 332863
2018-05-21MC: Change object writers to use endian::Writer. NFCI.Peter Collingbourne1-121/+125
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-05-14Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen1-6/+5
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
2018-04-13[MC] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang1-2/+2
Summary: r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. Reviewers: grosbach, void, ruiu Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45138 llvm-svn: 330058
2018-02-12[MC] Issue error message when data region is not terminatedGerolf Hoflehner1-1/+7
llvm-svn: 324868
2017-12-14MC: Add support for mach-o build_versionMatthias Braun1-21/+31
LC_BUILD_VERSION is a new load command superseding the previously used LC_XXX_MIN_VERSION commands. This adds an assembler directive along with encoding/streaming support. llvm-svn: 320661
2017-10-10[MC] Thread unique_ptr<MCObjectWriter> through the create.*ObjectWriterLang Hames1-2/+3
functions. This makes the ownership of the resulting MCObjectWriter clear, and allows us to remove one instance of MCObjectStreamer's bizarre "holding ownership via someone else's reference" trick. llvm-svn: 315327
2017-10-09[MC] Plumb unique_ptr<MCMachObjectTargetWriter> through createMachObjectWriterLang Hames1-4/+4
to MCObjectWriter's constructor. MCObjectWriter takes ownership of its MCMachObjectTargetWriter argument -- this patch plumbs that ownership relationship through the constructor (which previously took raw MCMachObjectTargetWriter*) and the createMachObjectWriter function. llvm-svn: 315245
2017-07-11Simplify interface now that we don't need to pass IsPCRel. NFC.Rafael Espindola1-1/+1
llvm-svn: 307734
2017-06-07Move Object format code to lib/BinaryFormat.Zachary Turner1-1/+1
This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth1-1/+1
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
2017-02-07[MC] Fix some Clang-tidy modernize and Include What You Use warnings; other ↵Eugene Zelenko1-2/+15
minor fixes (NFC). llvm-svn: 294369
2016-11-02Fix Clang-tidy readability-redundant-string-cstr warningsMalcolm Parsons1-1/+1
Reviewers: beanz, lattner, jlebar Subscribers: jholewinski, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D26235 llvm-svn: 285832
2016-10-04Misc improvements to StringTableBuilder.Rafael Espindola1-2/+2
This patch adds write methods to StringTableBuilder so that it is easier to change the underlying implementation. Using the write methods, avoid creating a temporary buffer when using mmaped output. It also uses a more compact key in the DenseMap. Overall this produces a slightly faster lld: firefox master 6.853419709 patch 6.841968912 1.00167361138x faster chromium master 4.297280174 patch 4.298712163 1.00033323147x slower chromium fast master 1.802335952 patch 1.806872459 1.00251701521x slower the gold plugin master 0.3247149 patch 0.321971644 1.00852017888x faster clang master 0.551279945 patch 0.543733194 1.01387951128x faster llvm-as master 0.032743458 patch 0.032143478 1.01866568391x faster the gold plugin fsds master 0.350814247 patch 0.348571741 1.00643341309x faster clang fsds master 0.6281672 patch 0.621130222 1.01132931187x faster llvm-as fsds master 0.030168899 patch 0.029797155 1.01247582194x faster scylla master 3.104222518 patch 3.059590248 1.01458766252x faster llvm-svn: 283266
2016-10-03Revert "Use getSize instead of data().size(). NFC."Rafael Espindola1-1/+1
This reverts commit r283125. lld needs to be updated. llvm-svn: 283127
2016-10-03Use getSize instead of data().size(). NFC.Rafael Espindola1-1/+1
Also assert isFinalized in getSize(). This just reduces the noise from another patch. llvm-svn: 283125
2016-04-26Reapply: "ARM: put correct symbol index on indirect pointers in __thread_ptr.""Tim Northover1-1/+2
A latent bug in llvm-objdump used the wrong format specifier on 32-bit targets, causing the test to fail. This fixes the issue. llvm-svn: 267582
2016-04-26Revert "ARM: put correct symbol index on indirect pointers in __thread_ptr."Renato Golin1-2/+1
This reverts commit r267488, as it broke some ARM buildbots. llvm-svn: 267541