aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-01[PseudoProbe] Support emitting to COFF object (#123870)Haohai Wen1-0/+7
RFC: https://discourse.llvm.org/t/rfc-support-pseudo-probe-for-windows-coff/83820 Support emitting pseudo probe to .pseudo_probe and .pseudo_probe_desc COFF sections.
2025-08-28[TargetLoweringObjectFile] Handle riscv BE (#155166)Djordje Todorovic1-0/+2
Add DWARF exception handling support for riscv big-endian targets. More CodeGen changes related to riscvbe are coming.
2025-08-03MCSymbolXCOFF: Migrate away from classofFangrui Song1-7/+9
The object file format specific derived classes are used in context where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSymbol::Kind in the base class.
2025-08-03MCSymbolELF: Migrate away from classofFangrui Song1-2/+3
The object file format specific derived classes are used in context where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSymbol::Kind in the base class.
2025-08-03MCSymbolELF: Migrate away from classofFangrui Song1-2/+2
The object file format specific derived classes are used in context where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSymbol::Kind in the base class.
2025-07-29[ELF][AsmPrinter] Emit trailing dot for constant pool section when it has a ↵Mingming Liu1-7/+7
hotness prefix (#150859) Currently, `TargetLoweringObjectFileELF::getSectionForConstant` produce `.<section>.hot` or `.<section>.unlikely` for a constant with non-empty section prefix. This PR changes the implementation add trailing dot when section prefix is not empty, to disambiguate `.hot` as a hotness prefix from `.hot` as a (pure C) variable name. Relevant discussions are in https://github.com/llvm/llvm-project/pull/148985#discussion_r2221141273 and https://github.com/llvm/llvm-project/pull/148985#discussion_r2233382641 and
2025-07-28[COFF] Set .llvmbc and .llvmcmd to metadata section (#150879)Haohai Wen1-1/+2
Those are metadata sections for ELF but was not properly set for COFF.
2025-07-26MCSectionXCOFF: Remove classofFangrui Song1-5/+7
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSection::SectionVariant in the base class.
2025-07-25MCSectionCOFF: Remove classofFangrui Song1-2/+2
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSection::SectionVariant in the base class.
2025-07-25MCSectionELF: Remove classofFangrui Song1-1/+1
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSection::SectionVariant in the base class.
2025-07-23[llvm] Remove unused includes (NFC) (#150265)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-15[NFC] Hoist pseudo probe desc emission code for reuse (#148756)Haohai Wen1-22/+1
This PR is part of #123870. The pseudo probe desc emission code can be reused by other target.
2025-06-26[GOFF] Add writing of section symbols (#133799)Kai Nacke1-5/+73
Unlike other formats, the GOFF object file format uses a 2 dimensional structure to define the location of data. For example, the equivalent of the ELF .text section is made up of a Section Definition (SD) and a class (Element Definition; ED). The name of the SD symbol depends on the application, while the class has the predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively. Data can be placed into this structure in 2 ways. First, the data (in a text record) can be associated with an ED symbol. To refer to data, a Label Definition (LD) is used to give an offset into the data a name. When binding, the whole data is pulled into the resulting executable, and the addresses given by the LD symbols are resolved. The alternative is to use a Part Definition (PR). In this case, the data (in a text record) is associated with the part. When binding, only the data of referenced PRs is pulled into the resulting binary. Both approaches are used. SD, ED, and PR elements are modeled by nested MCSectionGOFF instances, while LD elements are associated with MCSymbolGOFF instances. At the binary level, a record called "External Symbol Definition" (ESD) is used. The ESD has a type (SD, ED, PR, LD), and depending on the type a different subset of the fields is used.
2025-06-15RISCV: Replace RISCVMCExpr with MCSpecifierExprFangrui Song1-1/+1
2025-05-28Warn on misuse of DiagnosticInfo classes that hold Twines (#137397)Justin Bogner1-1/+1
This annotates the `Twine` passed to the constructors of the various DiagnosticInfo subclasses with `[[clang::lifetimebound]]`, which causes us to warn when we would try to print the twine after it had already been destructed. We also update `DiagnosticInfoUnsupported` to hold a `const Twine &` like all of the other DiagnosticInfo classes, since this warning allows us to clean up all of the places where it was being used incorrectly.
2025-05-07[Cygwin] Emit COMDAT name correctly for Cygwin (#138621)Tomohiro Kashiwada1-1/+1
Cygwin-gcc emits COMDAT in the same format as MinGW-gcc.
2025-04-08AsmPrinter: Remove ELF's special lowerRelativeReference for unnamed_addr ↵Fangrui Song1-18/+0
function; use lowerDSOLocalEquivalent in more cases https://reviews.llvm.org/D17938 introduced lowerRelativeReference to give ConstantExpr sub (A-B) special semantics in ELF: when `A` is an `unnamed_addr` function, create a PLT-generating relocation. This was intended for C++ relative vtables, but C++ relative vtable ended up using DSOLocalEquivalent (lowerDSOLocalEquivalent). This special treatment of `unnamed_addr` seems unusual. Let's remove it. Only COFF needs an overload to generate a @IMGREL32 relocation specifier (llvm/test/MC/COFF/cross-section-relative.ll). Pull Request: https://github.com/llvm/llvm-project/pull/134781
2025-04-01Revert "AsmPrinter: Remove ELF's special lowerRelativeReference for ↵Petr Hosek1-0/+18
unnamed_addr function" (#133935) Reverts llvm/llvm-project#132684
2025-03-31AsmPrinter: Remove ELF's special lowerRelativeReference for unnamed_addr ↵Fangrui Song1-18/+0
function https://reviews.llvm.org/D17938 introduced lowerRelativeReference to give ConstantExpr sub (A-B) special semantics in ELF: when `A` is an `unnamed_addr` function, create a PLT-generating relocation. This was intended for C++ relative vtables, but C++ relative vtable ended up using DSOLocalEquivalent (lowerDSOLocalEquivalent). This special treatment of `unnamed_addr` seems unusual. Let's remove it. Only COFF needs an overload to generate a @IMGREL32 relocation specifier (llvm/test/MC/COFF/cross-section-relative.ll). Pull Request: https://github.com/llvm/llvm-project/pull/132684
2025-03-29[CodeGen][StaticDataSplitter]Support constant pool partitioning (#129781)Mingming Liu1-0/+35
This is a follow-up patch of https://github.com/llvm/llvm-project/pull/125756 In this PR, static-data-splitter pass produces the aggregated profile counts of constants for constant pools in a global state (`StateDataProfileInfo`), and asm printer consumes the profile counts to produce `.hot` or `.unlikely` prefixes. This implementation covers both x86 and aarch64 asm printer.
2025-03-29[RISCV] Replace @plt/@gotpcrel in data directives with %pltpcrel %gotpcrelFangrui Song1-26/+51
clang -fexperimental-relative-c++-abi-vtables might generate `@plt` and `@gotpcrel` specifiers in data directives. The syntax is not used in humand-written assembly code, and is not supported by GNU assembler. Note: the `@plt` in `.word foo@plt` is different from the legacy `call func@plt` (where `@plt` is simply ignored). The `@plt` syntax was selected was simply due to a quirk of AsmParser: the syntax was supported by all targets until I updated it to be an opt-in feature in a0671758eb6e52a758bd1b096a9b421eec60204c RISC-V favors the `%specifier(expr)` syntax following MIPS and Sparc, and we should follow this convention. This PR adds support for `.word %pltpcrel(foo+offset)` and `.word %gotpcrel(foo)`, and drops `@plt` and `@gotpcrel`. * MCValue::SymA can no longer have a SymbolVariant. Add an assert similar to that of AArch64ELFObjectWriter.cpp before https://reviews.llvm.org/D81446 (see my analysis at https://maskray.me/blog/2025-03-16-relocation-generation-in-assemblers if intrigued) * `jump foo@plt, x31` now has a different diagnostic. Pull Request: https://github.com/llvm/llvm-project/pull/132569
2025-03-23AsmPrinter: Remove unneeded lowerRelativeReference overridesFangrui Song1-26/+0
The function is only called by AsmPrinter, where there is a fallback when lowerRelativeReference returns nullptr. wasm and XCOFF could use the fallback code. (lowerRelativeReference was introduced in 2016 (https://reviews.llvm.org/D17938) for C++ relative vtables, but C++ relative vtables ended up using dso_local_equivalent. llvm/test/MC/COFF/cross-section-relative.ll also uses this.)
2025-03-23[NFC]Don't use else after a return (#132644)Mingming Liu1-4/+4
A trivial code clean-up per https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
2025-03-23MCValue: Simplify code with getSubSymFangrui Song1-1/+1
MCValue::SymB is a MCSymbolRefExpr *, which might become MCSymbol * in the future. Simplify some code that uses MCValue::SymB.
2025-03-21[CodeGen] Rename PLTRelativeVariantKind. NFCFangrui Song1-2/+2
Migrate away from the deprecated MCSymbolRefExpr::VariantKind. The name "Specifier" is utilized in a few *MCExpr. > "Relocation specifier" is clear, aligns with Arm and IBM AIX's documentation, and fits the assembler's role seamlessly.
2025-03-05[MC] Remove unneeded VK_None argument from MCSymbolRefExpr::create. NFCFangrui Song1-6/+3
2025-02-14[AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (1/3) (#125687)Csanád Hajdú1-6/+10
Add support for the new SHF_AARCH64_PURECODE ELF section flag: https://github.com/ARM-software/abi-aa/pull/304 The general implementation follows the existing one for ARM targets. Generating object files with the `SHF_AARCH64_PURECODE` flag set is enabled by the `+execute-only` target feature. Related PRs: * Clang: https://github.com/llvm/llvm-project/pull/125688 * LLD: https://github.com/llvm/llvm-project/pull/125689
2025-02-12[MC] Replace MCContext::GenericSectionID with MCSection::NonUniqueID (#126202)Haohai Wen1-11/+11
They have same semantics. NonUniqueID is more friendly for isUnique implementation in MCSectionELF. History: 97837b7 added support for unique IDs in sections and added GenericSectionID. Later, 1dc16c7 added NonUniqueID.
2025-02-06[IR] Generalize Function's {set,get}SectionPrefix to GlobalObjects, the base ↵Mingming Liu1-0/+5
class of {Function, GlobalVariable, IFunc} (#125757) This is a split of https://github.com/llvm/llvm-project/pull/125756
2025-01-28[AsmPrinter][ELF] Support profile-guided section prefix for jump tables' ↵Mingming Liu1-8/+29
(read-only) data sections (#122215) https://github.com/llvm/llvm-project/pull/122183 adds a codegen pass to infer machine jump table entry's hotness from the MBB hotness. This is a follow-up PR to produce `.hot` and or `.unlikely` section prefix for jump table's (read-only) data sections in the relocatable `.o` files. When this patch is enabled, linker will see {`.rodata`, `.rodata.hot`, `.rodata.unlikely`} in input sections. It can map `.rodata.hot` and `.rodata` in the input sections to `.rodata.hot` in the executable, and map `.rodata.unlikely` into `.rodata` with a pending extension to `--keep-text-section-prefix` like https://github.com/llvm/llvm-project/commit/059e7cbb66a30ce35f3ee43197eed1a106b50c5b, or with a linker script. 1. To partition hot and jump tables, the AsmPrinter pass slices a function's jump table indices into two groups, one for hot and the other for cold jump tables. It then emits hot jump tables into a `.hot`-prefixed data section and cold ones into a `.unlikely`-prefixed data section, retaining the relative order of `LJT<N>` labels within each group. 2. [ELF only] To have data sections with _dynamic_ names (e.g., `.rodata.hot[.func]`), we implement `TargetLoweringObjectFile::getSectionForJumpTable` method that accepts a `MachineJumpTableEntry` parameter, and update `selectELFSectionForGlobal` to generate `.hot` or `.unlikely` based on MJTE's hotness. - The dynamic JT section name doesn't depend on `-ffunction-section=true` or `-funique-section-names=true`, even though it leverages the similar underlying mechanism to have a MCSection with on-demand name as `-ffunction-section` does. 3. The new code path is off by default. - Typically, `TargetOptions` conveys clang or LLVM tools' options to code generation passes. To follow the pattern, add option `EnableStaticDataPartitioning` bit in `TargetOptions` and make it readable through `TargetMachine`. - To enable the new code path in tools like `llc`, `partition-static-data-sections` option is introduced in `CodeGen/CommandFlags.h/cpp`. - A subsequent patch ([draft](https://github.com/llvm/llvm-project/commit/8f36a1374365862b3ca9be5615dd38f02a318c45)) will add a clang option to enable the new code path. --------- Co-authored-by: Ellis Hoag <ellis.sparky.hoag@gmail.com>
2025-01-26[NFC][CodeGen] Fix typos in code comments. (#124382)Alexey Bader1-2/+2
This fixes typos in `calcUniqueIDUpdateFlagsAndSize` function.
2025-01-21[TLOF][NFC] Make emitLinkerDirectives virtual and public. (#123773)Jason Eckhardt1-23/+34
Today, emitLinkerDirectives is private to TLOFCOFF-- it isolates parsing and processing of the linker options. Similar processing is also done by other TLOFs inline within emitModuleMetadata. This patch promotes emitLinkerDirectives to a virtual (public) method so that this handling is similarly isolated in the other TLOFs. This also enables downstream targets to override just this handling instead of the whole of emitModuleMetadata.
2025-01-21[clang] Implement #pragma clang section on COFF targets (#112714)Vinicius Tadeu Zein1-31/+23
This patch implements the directive #pragma clang section on COFF targets with the exact same features available on ELF and Mach-O.
2024-12-16[PAC][ELF][AArch64] Support signed personality function pointer (#119361)Daniil Kovalev1-2/+9
Re-apply #113148 after revert in #119331 If function pointer signing is enabled, sign personality function pointer stored in `.DW.ref.__gxx_personality_v0` section with IA key, 0x7EAD = `ptrauth_string_discriminator("personality")` constant discriminator and address diversity enabled.
2024-12-10Revert "[PAC][ELF][AArch64] Support signed personality function pointer" ↵Daniil Kovalev1-9/+1
(#119331) Reverts llvm/llvm-project#113148 See buildbot failure https://lab.llvm.org/buildbot/#/builders/190/builds/11048
2024-12-10[PAC][ELF][AArch64] Support signed personality function pointer (#113148)Daniil Kovalev1-1/+9
If function pointer signing is enabled, sign personality function pointer stored in `.DW.ref.__gxx_personality_v0` section with IA key, 0x7EAD = `ptrauth_string_discriminator("personality")` constant discriminator and address diversity enabled.
2024-10-15[Coverage][WebAssembly] Add initial support for WebAssembly/WASI (#111332)Yuta Saito1-1/+5
Currently, WebAssembly/WASI target does not provide direct support for code coverage. This patch set fixes several issues to unlock the feature. The main changes are: 1. Port `compiler-rt/lib/profile` to WebAssembly/WASI. 2. Adjust profile metadata sections for Wasm object file format. - [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections instead of data segments. - [lld] Align the interval space of custom sections at link time. - [llvm-cov] Copy misaligned custom section data if the start address is not aligned. - [llvm-cov] Read `__llvm_prf_names` from data segments 3. [clang] Link with profile runtime libraries if requested See each commit message for more details and rationale. This is part of the effort to add code coverage support in Wasm target of Swift toolchain.
2024-07-19CodeGen: Avoid some references to MachineFunction's getMMI (#99652)Matt Arsenault1-1/+1
MachineFunction's probably should not include a backreference to the owning MachineModuleInfo. Most of these references were used just to query the MCContext, which MachineFunction already directly stores. Other contexts are using it to query the LLVMContext, which can already be accessed through the IR function reference.
2024-06-30[MC] Move Mach-O specific getAtom and isSectionAtomizableBySymbols to Mach-O ↵Fangrui Song1-1/+2
files and devirtualize isSectionAtomizableBySymbols.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov1-3/+3
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-06-22[MC] Change Subsection parameters from const MCExpr * to uint32_tFangrui Song1-3/+2
Follow-up to 05ba5c0648ae5e80d5afce270495bf3b1eef9af4. uint32_t is preferred over const MCExpr * in the section stack uses because it should only be evaluated once. Change the paramter type to match.
2024-06-20[MC] Remove SectionKind from MCSection (#96067)aengelke1-24/+16
There are only three actual uses of the section kind in MCSection: isText(), XCOFF, and WebAssembly. Store isText() in the MCSection, and store other info in the actual section variants where required. ELF and COFF flags also encode all relevant information, so for these two section variants, remove the SectionKind parameter entirely. This allows to remove the string switch (which is unnecessary and inaccurate) from createELFSectionImpl. This was introduced in [D133456](https://reviews.llvm.org/D133456), but apparently, it was never hit for non-writable sections anyway and the resulting kind was never used.
2024-05-21[CodeGen] Assign SHT_LLVM_LTO to .llvm.lto section (#92856)Fangrui Song1-0/+2
This follows up to SHT_LLVM_LTO (https://reviews.llvm.org/D153215) and resolves the comment of the FatLTO patch https://reviews.llvm.org/D146776#4430626
2024-05-08MIPS: Use pcrel|sdata4 for eh_frame (#91291)YunQiang Su1-3/+1
Gas uses encoding DW_EH_PE_absptr for PIC, and gnu ld converts it to DW_EH_PE_sdata4|DW_EH_PE_pcrel. LLD doesn't have this workarounding, thus complains ``` relocation R_MIPS_32 cannot be used against local symbol; recompile with -fPIC relocation R_MIPS_64 cannot be used against local symbol; recompile with -fPIC ``` So, let's generates asm/obj files with `DW_EH_PE_sdata4|DW_EH_PE_pcrel` encoding. In fact, GNU ld supports such OBJs well. For N64, maybe we should use sdata8, while GNU ld doesn't support it well, and in fact sdata4 is enough now. So we just ignore the `Large` for `MCObjectFileInfo::initELFMCObjectFileInfo`. Maybe we should switch back to sdata8 once GNU LD supports it well. Fixes: #58377.
2024-05-07[Analysis, CodeGen, DebugInfo] Use StringRef::operator== instead of ↵Kazu Hirata1-1/+1
StringRef::equals (NFC) (#91304) I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 53 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-07[Clang] -fseparate-named-sections option (#91028)Petr Hosek1-3/+8
When set, the compiler will use separate unique sections for global symbols in named special sections (e.g. symbols that are annotated with __attribute__((section(...)))). Doing so enables linker GC to collect unused symbols without having to use a different section per-symbol.
2024-04-11[clang][llvm] Remove "implicit-section-name" attribute (#87906)Arthur Eubanks1-10/+1
D33412/D33413 introduced this to support a clang pragma to set section names for a symbol depending on if it would be placed in bss/data/rodata/text, which may not be known until the backend. However, for text we know that only functions will go there, so just directly set the section in clang instead of going through a completely separate attribute. Autoupgrade the "implicit-section-name" attribute to directly setting the section on a Fuction.
2024-03-15[AIX] Support per global code model. (#79202)Sean Fertile1-13/+26
Exploit the per global code model attribute on AIX. On AIX we need to update both the code sequence used to access the global (either 1 or 2 instructions for small and large code model respectively) and the storage mapping class that we emit the toc entry. --------- Co-authored-by: Amy Kwan <akwan0907@gmail.com>
2024-03-01[PowerPC] Support local-dynamic TLS relocation on AIX (#66316)Felix (Ting Wang)1-5/+18
Supports TLS local-dynamic on AIX, generates below sequence of code: ``` .tc foo[TC],foo[TL]@ld # Variable offset, ld relocation specifier .tc mh[TC],mh[TC]@ml # Module handle for the caller lwz 3,mh[TC]\(2\) $$ For 64-bit: ld 3,mh[TC]\(2\) bla .__tls_get_mod # Modifies r0,r3,r4,r5,r11,lr,cr0 #r3 = &TLS for module lwz 4,foo[TC]\(2\) $$ For 64-bit: ld 4,foo[TC]\(2\) add 5,3,4 # Compute &foo .rename mh[TC], "\_$TLSML" # Symbol for the module handle must have the name "_$TLSML" ``` --------- Co-authored-by: tingwang <tingwang@tingwangs-MBP.lan> Co-authored-by: tingwang <tingwang@tingwangs-MacBook-Pro.local>
2024-02-21[WebAssembly] Add segment RETAIN flag to support private retained data (#81539)Yuta Saito1-7/+22
In WebAssembly, we have `WASM_SYMBOL_NO_STRIP` symbol flag to mark the referenced content as retained. However, the flag is not enough to express retained data that is not referenced by any symbol. This patch adds a new segment flag`WASM_SEG_FLAG_RETAIN` to support "private" linkage data that is retained by llvm.used. This kind of data that is not referenced but must be retained is usually used with encapsulation symbols (__start/__stop). Swift runtime uses this technique and depends on the fact "all metadata sections in live objects are retained", which was not guaranteed with `--gc-sections` before this patch. This is a revised version of https://reviews.llvm.org/D126950 (has been reverted) based on @MaskRay's comments