aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-06-07[MC] De-capitalize MCStreamer functionsFangrui Song1-3/+3
Follow-up to c031378ce01b8485ba0ef486654bc9393c4ac024 . The class is mostly consistent now.
2022-05-18[SystemZ][z/OS] Add the PPA1 to SystemZAsmPrinterYusra Syeda1-2/+2
Differential Revision: https://reviews.llvm.org/D125725
2022-05-05[XCOFF][AIX] Use unique section names for LSDA and EH info sections with ↵Xing Xue1-0/+14
-ffunction-sections Summary: When -ffunction-sections is on, this patch makes the compiler to generate unique LSDA and EH info sections for functions on AIX by appending the function name to the section name as a suffix. This will allow the AIX linker to garbage-collect unused function. Reviewed by: MaskRay, hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D124855
2022-04-14[OpenMP] Make offloading sections have the SHF_EXCLUDE flagJoseph Huber1-3/+11
Offloading sections can be embedded in the host during codegen via a section. This section was originally marked as metadata to prevent it from being loaded, but these sections are completely unused at runtime so the linker should automatically drop them from the final executable or shard library. This flag adds support for the SHF_EXCLUDE flag in target lowering and uses it. Reviewed By: JonChesterfield, MaskRay Differential Revision: https://reviews.llvm.org/D122987
2022-03-23Reland "Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO"Julian Lettner1-2/+10
For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121736
2022-03-23Revert "Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO"Zequan Wu1-10/+2
This reverts commit 22570bac694396514fff18dec926558951643fa6.
2022-03-17Lower `@llvm.global_dtors` using `__cxa_atexit` on MachOJulian Lettner1-2/+10
For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121736
2022-03-15Revert rG9c542a5a4e1ba36c24e48185712779df52b7f7a6 "Lower ↵Simon Pilgrim1-10/+2
`@llvm.global_dtors` using `__cxa_atexit` on MachO" Mane of the build bots are complaining: Unknown command line argument '-lower-global-dtors'
2022-03-14Lower `@llvm.global_dtors` using `__cxa_atexit` on MachOJulian Lettner1-2/+10
For MachO, lower `@llvm.global_dtors` into `@llvm_global_ctors` with `__cxa_atexit` calls to avoid emitting the deprecated `__mod_term_func`. Reuse the existing `WebAssemblyLowerGlobalDtors.cpp` to accomplish this. Enable fallback to the old behavior via Clang driver flag (`-fregister-global-dtors-with-atexit`) or llc / code generation flag (`-lower-global-dtors-via-cxa-atexit`). This escape hatch will be removed in the future. Differential Revision: https://reviews.llvm.org/D121327
2022-02-23[MC][ELF] Use SHF_SUNW_NODISCARD instead of SHF_GNU_RETAIN on SolarisRainer Orth1-9/+13
As requested in D107955 <https://reviews.llvm.org/D107955>, this patch splits off the `MC` and `CodeGen` parts and adds a testcase. Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D120318
2022-02-21[OpenMP] Ensure offloading sections do not have SHF_ALLOC flagJoseph Huber1-1/+2
We use offloading sections in the new Clang driver scheme to embed device code into the host. We later use these sections to link the device image, after which point they are completely unused and should not be loaded into memory if they are still in the executable. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D120275
2022-02-06[CodeGen] Use = default (NFC)Kazu Hirata1-1/+1
Identified with modernize-use-equals-default
2022-01-12[MachO] Port call graph profile section and directiveLeonard Grey1-0/+1
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
2022-01-07[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-6/+3
Identified with readability-redundant-member-init.
2022-01-04[ELF] Handle .init_array prefix consistentlyNikita Popov1-3/+8
Currently, the code in TargetLoweringObjectFile only assigns @init_array section type to plain .init_array sections, but not prioritized sections like .init_array.00001. This is inconsistent with the interpretation in the AsmParser (see https://github.com/llvm/llvm-project/blob/791523bae6153b13bb41ba05c9fc89e502cc4a1a/llvm/lib/MC/MCParser/ELFAsmParser.cpp#L621-L632) and upcoming expectations in LLD (see https://github.com/rust-lang/rust/issues/92181 for context). This patch assigns @init_array section type to all sections with an .init_array prefix. The same is done for .fini_array and .preinit_array as well. With that, the logic matches the AsmParser. Differential Revision: https://reviews.llvm.org/D116528
2022-01-03Revert "[llvm] Remove redundant member initialization (NFC)"Kazu Hirata1-3/+6
This reverts commit fd4808887ee47f3ec8a030e9211169ef4fb094c3. This patch causes gcc to issue a lot of warnings like: warning: base class ‘class llvm::MCParsedAsmOperand’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-01[llvm] Remove redundant member initialization (NFC)Kazu Hirata1-6/+3
Identified with readability-redundant-member-init.
2021-11-24[LLVM][NFC]Inclusive language: remove occurances of sanity check/test from llvmZarko Todorovski1-2/+2
Part of work to use more inclusive language in clang/llvm. Rewording some comments and change function and variable names.
2021-10-06[IR][NFC] Rename getBaseObject to getAliaseeObjectItay Bookstein1-8/+8
To better reflect the meaning of the now-disambiguated {GlobalValue, GlobalAlias}::getBaseObject after breaking off GlobalIFunc::getResolverFunction (D109792), the function is renamed to getAliaseeObject.
2021-09-09[APInt] Normalize naming on keep constructors / predicate methods.Chris Lattner1-1/+1
This renames the primary methods for creating a zero value to `getZero` instead of `getNullValue` and renames predicates like `isAllOnesValue` to simply `isAllOnes`. This achieves two things: 1) This starts standardizing predicates across the LLVM codebase, following (in this case) ConstantInt. The word "Value" doesn't convey anything of merit, and is missing in some of the other things. 2) Calling an integer "null" doesn't make any sense. The original sin here is mine and I've regretted it for years. This moves us to calling it "zero" instead, which is correct! APInt is widely used and I don't think anyone is keen to take massive source breakage on anything so core, at least not all in one go. As such, this doesn't actually delete any entrypoints, it "soft deprecates" them with a comment. Included in this patch are changes to a bunch of the codebase, but there are more. We should normalize SelectionDAG and other APIs as well, which would make the API change more mechanical. Differential Revision: https://reviews.llvm.org/D109483
2021-08-11[ELF] Don't emit SHF_GNU_RETAIN on SolarisRainer Orth1-4/+7
The introduction of `SHF_GNU_RETAIN` has caused massive problems on Solaris. Initially, as reported in Bug 49437, it caused dozens of testsuite failures on both sparc and x86. The objects were marked as `ELFOSABI_NONE`, but `SHF_GNU_RETAIN` is a GNU extension. In the native Solaris ABI, that flag (in the range for OS-specific values) is `SHF_SUNW_ABSENT` with a completely different semantics, which confuses Solaris `ld` very much. Later, the objects became (correctly) marked `ELFOSABI_GNU`, which Solaris `ld` doesn't support, causing it to SEGV and break the build. The linker is currently being hardened to not accept non-native OS ABIs to avoid this. The need for linker support is already documented in `clang/include/clang/Basic/AttrDocs.td`, but not currently checked. This patch avoids all this by not emitting `SHF_GNU_RETAIN` on Solaris at all. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D107747
2021-08-10[AIX] Don't crash on unimplemented lowerRelativeReferenceJinsong Ji1-1/+2
We may call lowerRelativeReference in MC to determine whether target supports this lowering. We should return nullptr instead of crashing when we haven't implemented the real lowering. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D107830
2021-08-05[PowerPC][AIX] Create multiple constant sections.Sean Fertile1-1/+14
Fixes issue where late materialized constants can be more strictly aligned then their containing csect. Differential Revision: https://reviews.llvm.org/D103103
2021-07-27[SystemZ][z/OS] Initial code to generate assembly files on z/OSAnirudh Prasad1-0/+22
- This patch consists of the bare basic code needed in order to generate some assembly for the z/OS target. - Only the .text and the .bss sections are added for now. - The relevant MCSectionGOFF/Symbol interfaces have been added. This enables us to print out the GOFF machine code sections. - This patch enables us to add simple lit tests wherever possible, and contribute to the testing coverage for the z/OS target - Further improvements and additions will be made in future patches. Reviewed By: tmatheson Differential Revision: https://reviews.llvm.org/D106380
2021-07-20[IR] Rename `comdat noduplicates` to `comdat nodeduplicate`Fangrui Song1-4/+4
In the textual format, `noduplicates` means no COMDAT/section group deduplication is performed. Therefore, if both sets of sections are retained, and they happen to define strong external symbols with the same names, there will be a duplicate definition linker error. In PE/COFF, the selection kind lowers to `IMAGE_COMDAT_SELECT_NODUPLICATES`. The name describes the corollary instead of the immediate semantics. The name can cause confusion to other binary formats (ELF, wasm) which have implemented/ want to implement the "no deduplication" selection kind. Rename it to be clearer. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D106319
2021-07-15MachO: don't emit L... private symbols in do_not_dead_strip sections.Tim Northover1-5/+4
The linker can sometimes drop the do_not_dead_strip if it can't associate the atom with a symbol (the other place to specify no dead-stripping in MachO files).
2021-06-11[ADT] Remove APInt/APSInt toString() std::string variantsSimon Pilgrim1-1/+1
<string> is currently the highest impact header in a clang+llvm build: https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html One of the most common places this is being included is the APInt.h header, which needs it for an old toString() implementation that returns std::string - an inefficient method compared to the SmallString versions that it actually wraps. This patch replaces these APInt/APSInt methods with a pair of llvm::toString() helpers inside StringExtras.h, adjusts users accordingly and removes the <string> from APInt.h - I was hoping that more of these users could be converted to use the SmallString methods, but it appears that most end up creating a std::string anyhow. I avoided trying to use the raw_ostream << operators as well as I didn't want to lose having the integer radix explicit in the code. Differential Revision: https://reviews.llvm.org/D103888
2021-06-10[AIX] Add traceback ssp canary bit supportJinsong Ji1-0/+11
We will need to set the ssp canary bit in traceback table to communicate with unwinder about the canary. Reviewed By: #powerpc, shchenz Differential Revision: https://reviews.llvm.org/D103202
2021-05-26[MC][NFCI] Factor out ELF section unique ID calculationTomas Matheson1-61/+78
Precursor to D100944. The logic for determining the unique ID had become quite difficult to reason about, so I have factored this out into a separate function. Differential Revision: https://reviews.llvm.org/D102336
2021-05-12[WebAssembly] Add TLS data segment flag: WASM_SEG_FLAG_TLSSam Clegg1-1/+4
Previously the linker was relying solely on the name of the segment to imply TLS. Differential Revision: https://reviews.llvm.org/D102202
2021-05-10Reland: "[lld][WebAssembly] Initial support merging string data"Sam Clegg1-4/+17
This change was originally landed in: 5000a1b4b9edeb9e994f2a5b36da8d48599bea49 It was reverted in: 061e071d8c9b98526f35cad55a918a4f1615afd4 This change adds support for a new WASM_SEG_FLAG_STRINGS flag in the object format which works in a similar fashion to SHF_STRINGS in the ELF world. Unlike the ELF linker this support is currently limited: - No support for SHF_MERGE (non-string merging) - Always do full tail merging ("lo" can be merged with "hello") - Only support single byte strings (p2align 0) Like the ELF linker merging is only performed at `-O1` and above. This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828, although crucially it doesn't not currently support debug sections because they are not represented by data segments (they are custom sections) Differential Revision: https://reviews.llvm.org/D97657
2021-05-10Revert "[lld][WebAssembly] Initial support merging string data"Nico Weber1-17/+4
This reverts commit 5000a1b4b9edeb9e994f2a5b36da8d48599bea49. Breaks tests, see https://reviews.llvm.org/D97657#2749151 Easily repros locally with `ninja check-llvm-mc-webassembly`.
2021-05-10[lld][WebAssembly] Initial support merging string dataSam Clegg1-4/+17
This change adds support for a new WASM_SEG_FLAG_STRINGS flag in the object format which works in a similar fashion to SHF_STRINGS in the ELF world. Unlike the ELF linker this support is currently limited: - No support for SHF_MERGE (non-string merging) - Always do full tail merging ("lo" can be merged with "hello") - Only support single byte strings (p2align 0) Like the ELF linker merging is only performed at `-O1` and above. This fixes part of https://bugs.llvm.org/show_bug.cgi?id=48828, although crucially it doesn't not currently support debug sections because they are not represented by data segments (they are custom sections) Differential Revision: https://reviews.llvm.org/D97657
2021-05-10[X86] Fix position-independent TType encodingHarald van Dijk1-1/+1
The logic for x86_64 position-independent TType encodings was backwards, using 8 bytes where 4 were wanted and 4 where 8 were wanted. For regular x86_64, this was mostly harmless, exception tables are allowed to use 8-byte encodings even when it is not needed. For the large code model, and for X32, however, the generated exception tables were wrong. For the large code model, we cannot assume that the address will fit in 4 bytes. For X32, we cannot use 64-bit relocations. Fixes PR50148. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D102132
2021-05-05[MC] Untangle MCContext and MCObjectFileInfoPhilipp Krones1-9/+11
This untangles the MCContext and the MCObjectFileInfo. There is a circular dependency between MCContext and MCObjectFileInfo. Currently this dependency also exists during construction: You can't contruct a MOFI without a MCContext without constructing the MCContext with a dummy version of that MOFI first. This removes this dependency during construction. In a perfect world, MCObjectFileInfo wouldn't depend on MCContext at all, but only be stored in the MCContext, like other MC information. This is future work. This also shifts/adds more information to the MCContext making it more available to the different targets. Namely: - TargetTriple - ObjectFileType - SubtargetInfo Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D101462
2021-04-30[XCOFF][AIX] Add Global Variables Directly to TOC for 32 bit AIXSidharth Baveja1-0/+25
Summary: This patch implements the backend implementation of adding global variables directly to the table of contents (TOC), rather than adding the address of the variable to the TOC. Currently, this patch will look for the "toc-data" attribute on symbols in the IR, and then add those symbols to the TOC. ATM, this is implemented for 32 bit AIX. Reviewers: sfertile Differential Revision: https://reviews.llvm.org/D101178
2021-04-29[XCOFF] Handle the case when personality routine is an aliasjasonliu1-2/+3
Summary: Personality routine could be an alias to another personality routine. Fix the situation when we compile the file that contains the personality routine and the file also have functions that need to refer to the personality routine. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D101401
2021-04-29Basic block sections for functions with implicit-section-name attributeSriraman Tallam1-20/+40
Functions can have section names set via #pragma or section attributes, basic block sections should be correctly named for such functions. With #pragma, the expectation is that all functions in that file are placed in the same section in the final binary. Basic block sections should be correctly named with the unique flag set so that the final binary has all the basic blocks of the function in that named section. This patch fixes the bug by calling getExplictSectionGlobal when implicit-section-name attribute is set to make sure the function's basic blocks get the correct section name. Differential Revision: https://reviews.llvm.org/D101311
2021-04-21[MC] Use COMDAT for LSDA only if IR comdat type is anyPetr Hosek1-1/+3
This fixed issue introduced in 16af97393346ad636298605930a8b503a55eb40a and 796feb61637c407aefcc0d462f24a1cc41f350d8. Differential Revision: https://reviews.llvm.org/D100909
2021-03-02[AIX][TLS] Generate TLS variables in assembly filesVictor Huang1-8/+29
This patch allows generating TLS variables in assembly files on AIX. Initialized and external uninitialized variables are generated with the .csect pseudo-op and local uninitialized variables are generated with the .comm/.lcomm pseudo-ops. The patch also adds a check to explicitly say that TLS is not yet supported on AIX. Reviewed by: daltenty, jasonliu, lei, nemanjai, sfertile Originally patched by: bsaleil Commandeered by: NeHuang Differential Revision: https://reviews.llvm.org/D96184
2021-02-26ELF: Create unique SHF_GNU_RETAIN sections for llvm.used global objectsFangrui Song1-8/+28
If a global object is listed in `@llvm.used`, place it in a unique section with the `SHF_GNU_RETAIN` flag. The section is a GC root under `ld --gc-sections` with LLD>=13 or GNU ld>=2.36. For front ends which do not expect to see multiple sections of the same name, consider emitting `@llvm.compiler.used` instead of `@llvm.used`. SHF_GNU_RETAIN is restricted to ELFOSABI_GNU and ELFOSABI_FREEBSD in binutils. We don't do the restriction - see the rationale in D95749. The integrated assembler has supported SHF_GNU_RETAIN since D95730. GNU as>=2.36 supports section flag 'R'. We don't need to worry about GNU ld support because older GNU ld just ignores the unknown SHF_GNU_RETAIN. With this change, `__attribute__((retain))` functions/variables emitted by clang will get the SHF_GNU_RETAIN flag. Differential Revision: https://reviews.llvm.org/D97448
2021-02-25Support `#pragma clang section` directives on MachO targetsJon Roelofs1-11/+16
rdar://59560986 Differential Revision: https://reviews.llvm.org/D97233
2021-02-24Revert "[InstrProfiling] Use nobits as __llvm_prf_cnts section type in ELF"Petr Hosek1-4/+0
This reverts commit 6b286d93f7ec8518c685a302269e44b06a0a24f3 because in some cases when the optimizer evaluates the global initializer, __llvm_prf_cnts may not be entirely zero initialized.
2021-02-20[InstrProfiling] Use nobits as __llvm_prf_cnts section type in ELFPetr Hosek1-0/+4
This can reduce the binary size because counters will no longer occupy space in the binary, instead they will be allocated by dynamic linker. Differential Revision: https://reviews.llvm.org/D97110
2021-02-20[CodeGen] Fix two dots between text section name and symbol namePan, Tao1-1/+4
There is a trailing dot in text section name if it has prefix, don't add repeated dot when connect text section name and symbol name. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D96327
2021-02-18[MC][ELF] Fix unused variable warning (NFC)Yang Fan1-2/+0
GCC warning: ``` /llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp: In member function ‘virtual llvm::MCSection* llvm::TargetLoweringObjectFileELF::getSectionForLSDA(const llvm::Function&, const llvm::MCSymbol&, const llvm::TargetMachine&) const’: /llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:871:8: warning: variable ‘IsComdat’ set but not used [-Wunused-but-set-variable] 871 | bool IsComdat = false; | ^~~~~~~~ ```
2021-02-17[XCOFF][NFC] make csect properties optional for getXCOFFSectionChen Zheng1-21/+31
We are going to support debug sections for XCOFF. So the csect properties are not necessary. This patch makes these properties optional. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D95931
2021-02-16Basic block sections should enable function sections implicitly.Sriraman Tallam1-11/+27
Basic block sections enables function sections implicitly, this is not needed and is inefficient with "=list" option. We had basic block sections enable function sections implicitly in clang. This is particularly inefficient with "=list" option as it places functions that do not have any basic block sections in separate sections. This causes unnecessary object file overhead for large applications. This patch disables this implicit behavior. It only creates function sections for those functions that require basic block sections. Further, there was an inconistent behavior with llc as llc was not turning on function sections by default. This patch makes llc and clang consistent and tests are added to check the new behavior. This is the first of two patches and this adds functionality in LLVM to create a new section for the entry block if function sections is not enabled. Differential Revision: https://reviews.llvm.org/D93876
2021-02-16[MC][ELF] Support for zero flag section groupsPetr Hosek1-16/+26
This change introduces support for zero flag ELF section groups to LLVM. LLVM already supports COMDAT sections, which in ELF are a special type of ELF section groups. These are generally useful to enable linker GC where you want a group of sections to always travel together, that is to be either retained or discarded as a whole, but without the COMDAT semantics. Other ELF assemblers already support zero flag ELF section groups and this change helps us reach feature parity. Differential Revision: https://reviews.llvm.org/D95851
2021-02-05.gcc_except_table: Set SHF_LINK_ORDER if binutils>=2.36, and drop unneeded ↵Fangrui Song1-20/+15
unique ID for -fno-unique-section-names GNU ld>=2.36 supports mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER sections in an output section, so we can set SHF_LINK_ORDER if -fbinutils-version=2.36 or above. If -fno-function-sections or older binutils, drop unique ID for -fno-unique-section-names. The users can just specify -fbinutils-version=2.36 or above to allow GC with both GNU ld and LLD. (LLD does not support garbage collection of non-group non-SHF_LINK_ORDER .gcc_except_table sections.)