summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
AgeCommit message (Collapse)Author
2020-11-13[CGProfile] allows bitcast in metadata node storing function pointersYuanfang Chen
For example, during RAUW in IRMover, the `Function` ValueAsMetadata in "CG Profile" could become bitcast. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D88433
2020-11-09[XCOFF] Enable explicit sections on AIXjasonliu
Implement mechanism to allow explicit sections to be generated on AIX. Reviewed By: DiggerLin Differential Revision: https://reviews.llvm.org/D88615
2020-11-03[CodeGen] Fix regression from D83655Jessica Clarke
Arm EHABI has a null LSDASection as it does its own thing, so we should continue to return null in that case rather than try and cast it.
2020-11-02[AsmPrinter] Split up .gcc_except_tableFangrui Song
MC currently produces monolithic .gcc_except_table section. GCC can split up .gcc_except_table: * if comdat: `.section .gcc_except_table._Z6comdatv,"aG",@progbits,_Z6comdatv,comdat` * otherwise, if -ffunction-sections: `.section .gcc_except_table._Z3fooi,"a",@progbits` This ensures that (a) non-prevailing copies are discarded and (b) .gcc_except_table associated to discarded text sections can be discarded by a .gcc_except_table-aware linker (GNU ld, but not gold or LLD) This patches matches the GCC behavior. If -fno-unique-section-names is specified, we don't append the suffix. If -ffunction-sections is additionally specified, use `.section ...,unique`. Note, if clang driver communicates that the linker is LLD and we know it is new (11.0.0 or later) we can use SHF_LINK_ORDER to avoid string table costs, at least in the -fno-unique-section-names case. We cannot use it on GNU ld because as of binutils 2.35 it does not support mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER components in an output section https://sourceware.org/bugzilla/show_bug.cgi?id=26256 For RISC-V -mrelax, this patch additionally fixes an assembler-linker interaction problem: because a section is shrinkable, the length of a call-site code range is not a constant. Relocations referencing the associated text section (STT_SECTION) are needed. However, a STB_LOCAL relocation referencing a discarded section group member from outside the group is disallowed by the ELF specification (PR46675): ``` // a.cc inline int comdat() { try { throw 1; } catch (int) { return 1; } return 0; } int main() { return comdat(); } // b.cc inline int comdat() { try { throw 1; } catch (int) { return 1; } return 0; } int foo() { return comdat(); } clang++ -target riscv64-linux -c a.cc b.cc -fPIC -mno-relax ld.lld -shared a.o b.o => ld.lld: error: relocation refers to a symbol in a discarded section: ``` -fbasic-block-sections= is similar to RISC-V -mrelax: there are outstanding relocations. Reviewed By: jrtc27, rahmanl Differential Revision: https://reviews.llvm.org/D83655
2020-10-14[llvm] Set the default for -bbsections-cold-text-prefix to .text.split.Snehasish Kumar
After using this for a while, we find that it is generally useful to have it set to .text.split. by default, removing the need for an additional -mllvm option. Differential Revision: https://reviews.llvm.org/D88997
2020-10-02[XCOFF] Enable -fdata-sections on AIXjasonliu
Summary: Some design decision worth noting about: I've noticed a recent mailing discussing about why string literal is not affected by -fdata-sections for ELF target: http://lists.llvm.org/pipermail/llvm-dev/2020-September/145121.html But on AIX, our linker could not split the mergeable string like other target. So I think it would make more sense for us to emit separate csect for every mergeable string in -fdata-sections mode, as there might not be other ways for linker to do garbage collection on unused mergeable string. Reviewed By: daltenty, hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D88339
2020-09-29[CodeGen] emit CG profile for COFF object fileZequan Wu
Differential Revision: https://reviews.llvm.org/D87811
2020-09-27Revert "Reland [CodeGen] emit CG profile for COFF object file"Arthur Eubanks
This reverts commit 506b6170cb513f1cb6e93a3b690c758f9ded18ac. This still causes link errors, see https://crbug.com/1130780.
2020-09-24[llvm] Add -bbsections-cold-text-prefix to emit cold clusters to a different ↵Snehasish Kumar
section. This change adds an option to basic block sections to allow cold clusters to be assigned a custom text prefix. With a custom prefix such as ".text.split." (D87840), lld can place them in a separate output section. The benefits are - * Empirically shown to improve icache and itlb metrics by 3-5% (absolute) compared to placing split parts in .text.unlikely. * Mitigates against poor profiles, eg samplePGO profiles used with the machine function splitter. Optimizations such as hugepage remapping can make different decisions at the section granularity. * Enables section granularity hotness monitoring (checking on the decisions made during compilation vs sample data from production). Differential Revision: https://reviews.llvm.org/D87813
2020-09-24Reland [CodeGen] emit CG profile for COFF object fileZequan Wu
This reverts commit 90242caca2074dab5a9b76e5bc36d9fafd2179a7. Error fixed at f5435399e823746bbe1737b95c853d77a42e1ac3 Differential Revision: https://reviews.llvm.org/D87811
2020-09-22Revert "[CodeGen] emit CG profile for COFF object file"Reid Kleckner
This reverts commit 91aed9bf975f1e4346cc8f4bdefc98436386ced2, it is causing link errors.
2020-09-18[COFF] Move per-global .drective emission from AsmPrinter to TLOFCOFFReid Kleckner
This changes the order of output sections and the output assembly, but is otherwise NFC. It simplifies the TLOF interface by removing two COFF-only methods.
2020-09-18[CodeGen] emit CG profile for COFF object fileZequan Wu
I forgot to add emission of CG profile for COFF object file, when adding the support (https://reviews.llvm.org/D81775) Differential Revision: https://reviews.llvm.org/D87811
2020-08-25[TargetLoweringObjectFileImpl] Make .llvmbc and .llvmcmd non-SHF_ALLOCFangrui Song
There are two ways .llvmbc can be produced: * clang -c -fembed-bitcode=all (which also produces .llvmcmd) * LTO backend: ld.lld -mllvm -lto-embed-bitcode or -plugin-opt=-lto-embed-bitcode .llvmbc and .llvmcmd have the SHF_ALLOC flag, so they can be dropped by --gc-sections. This patch sets SectionKind::Metadata to drop the SHF_ALLOC flag. This is conceptually correct: the two sections are not part of the process image, so SHF_ALLOC is not appropriate. `test/LTO/X86/embed-bitcode.ll`: changed `llvm-objcopy -O binary --only-section` to `llvm-objcopy --dump-section`. `-O binary` does not dump non-SHF_ALLOC sections. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D86374
2020-08-11[AIX][XCOFF] change the operand of branch instruction from symbol name to ↵diggerlin
qualified symbol name for function declarations SUMMARY: 1. in the patch , remove setting storageclass in function .getXCOFFSection and construct function of class MCSectionXCOFF there are XCOFF::StorageMappingClass MappingClass; XCOFF::SymbolType Type; XCOFF::StorageClass StorageClass; in the MCSectionXCOFF class, these attribute only used in the XCOFFObjectWriter, (asm path do not need the StorageClass) we need get the value of StorageClass, Type,MappingClass before we invoke the getXCOFFSection every time. actually , we can get the StorageClass of the MCSectionXCOFF from it's delegated symbol. 2. we also change the oprand of branch instruction from symbol name to qualify symbol name. for example change bl .foo extern .foo to bl .foo[PR] extern .foo[PR] 3. and if there is reference indirect call a function bar. we also add extern .bar[PR] Reviewers: Jason liu, Xiangling Liao Differential Revision: https://reviews.llvm.org/D84765
2020-08-10[XCOFF][AIX] Use TE storage mapping class when large code model is enabledjasonliu
Summary: Use TE SMC instead of TC SMC in large code model mode, so that large code model TOC entries could get placed after all the small code model TOC entries, which reduces the chance of TOC overflow. Reviewed By: Xiangling_L Differential Revision: https://reviews.llvm.org/D85455
2020-08-10[AIX] Static init frontend recovery and backend supportXiangling Liao
On the frontend side, this patch recovers AIX static init implementation to use the linkage type and function names Clang chooses for sinit related function. On the backend side, this patch sets correct linkage and function names on aliases created for sinit/sterm functions. Differential Revision: https://reviews.llvm.org/D84534
2020-08-06[XCOFF][AIX] Put each jump table in an independent section if ↵jasonliu
-ffunction-sections is specified If a function is in a unique section, putting all jump tables in .rodata will prevent functions that have a jump table to get garbage collect by the linker. Therefore, we need to put jump table into a unique section as well. Reviewed By: Xiangling_L Differential Revision: https://reviews.llvm.org/D84761
2020-08-03[MC] Set sh_link to 0 if the associated symbol is undefinedFangrui Song
Part of https://bugs.llvm.org/show_bug.cgi?id=41734 LTO can drop externally available definitions. Such AssociatedSymbol is not associated with a symbol. ELFWriter::writeSection() will assert. Allow a SHF_LINK_ORDER section to have sh_link=0. We need to give sh_link a syntax, a literal zero in the linked-to symbol position, e.g. `.section name,"ao",@progbits,0` Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D72899
2020-07-30[XCOFF][AIX] Enable -ffunction-sectionsjasonliu
Summary: This patch implements -ffunction-sections on AIX. This patch focuses on assembly generation. Follow-on patch needs to handle: 1. -ffunction-sections implication for jump table. 2. Object file generation path and associated testing. Differential Revision: https://reviews.llvm.org/D83875
2020-07-23Fix -Wparentheses warning - add missing brackets around the entire assertion ↵Simon Pilgrim
condition
2020-07-22[XCOFF] Enable symbol alias for AIXjasonliu
Summary: AIX assembly's .set directive is not usable for aliasing purpose. We need to use extra-label-at-defintion strategy to generate symbol aliasing on AIX. Reviewed By: DiggerLin, Xiangling_L Differential Revision: https://reviews.llvm.org/D83252
2020-07-09[SVE] Remove calls to VectorType::getNumElements from CodeGenChristopher Tetreault
Reviewers: efriedma, fpetrogalli, sdesmalen, RKSimon, arsenm Reviewed By: RKSimon Subscribers: wdng, tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82210
2020-07-06[XCOFF][AIX] Give symbol an internal name when desired symbol name contains ↵jasonliu
invalid character(s) Summary: When a desired symbol name contains invalid character that the system assembler could not process, we need to emit .rename directive in assembly path in order for that desired symbol name to appear in the symbol table. Reviewed By: hubert.reinterpretcast, DiggerLin, daltenty, Xiangling_L Differential Revision: https://reviews.llvm.org/D82481
2020-06-29[Alignment][NFC] migrate DataLayout::getPreferredAlignmentGuillaume Chatelet
This 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 Differential Revision: https://reviews.llvm.org/D82752
2020-06-02Options for Basic Block Sections, enabled in D68063 and D73674.Sriraman Tallam
This patch adds clang options: -fbasic-block-sections={all,<filename>,labels,none} and -funique-basic-block-section-names. LLVM Support for basic block sections is already enabled. + -fbasic-block-sections={all, <file>, labels, none} : Enables/Disables basic block sections for all or a subset of basic blocks. "labels" only enables basic block symbols. + -funique-basic-block-section-names: Enables unique section names for basic block sections, disabled by default. Differential Revision: https://reviews.llvm.org/D68049
2020-05-29[AIX] Emit AvailableExternally Linkage on AIXXiangling Liao
Since on AIX, our strategy is to not use -u to suppress any undefined symbols, we need to emit .extern for the symbols with AvailableExternally linkage. Differential Revision: https://reviews.llvm.org/D80642
2020-05-27[NFC][XCOFF][AIX] Return function entry point symbol with dedicate functionjasonliu
Use getFunctionEntryPointSymbol whenever possible to enclose the implementation detail and reduce duplicate logic. Differential Revision: https://reviews.llvm.org/D80402
2020-05-24[TargetLoweringObjectFileImpl] Use llvm::transformOrivej Desh
Fixes a build issue with libc++ configured with _LIBCPP_RAW_ITERATORS (ADL not effective) ``` llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1602:3: error: no matching function for call to 'transform' transform(HexString.begin(), HexString.end(), HexString.begin(), tolower); ^~~~~~~~~ ``` Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D80475
2020-05-21[Target] Use Align in TargetLoweringObjectFile::getSectionForConstant.Craig Topper
Differential Revision: https://reviews.llvm.org/D80363
2020-05-12[TargetLoweringObjectFileImpl] Produce .text.hot. instead of .text.hot for ↵Fangrui Song
-fno-unique-section-names GNU ld's internal linker script uses (https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=add44f8d5c5c05e08b11e033127a744d61c26aee) .text : { *(.text.unlikely .text.*_unlikely .text.unlikely.*) *(.text.exit .text.exit.*) *(.text.startup .text.startup.*) *(.text.hot .text.hot.*) *(SORT(.text.sorted.*)) *(.text .stub .text.* .gnu.linkonce.t.*) /* .gnu.warning sections are handled specially by elf.em. */ *(.gnu.warning) } Because `*(.text.exit .text.exit.*)` is ordered before `*(.text .text.*)`, in a -ffunction-sections build, the C library function `exit` will be placed before other functions. gold's `-z keep-text-section-prefix` has the same problem. In lld, `-z keep-text-section-prefix` recognizes `.text.{exit,hot,startup,unlikely,unknown}.*`, but not `.text.{exit,hot,startup,unlikely,unknown}`, to avoid the strange placement problem. In -fno-function-sections or -fno-unique-section-names mode, a function whose `function_section_prefix` is set to `.exit"` will go to the output section `.text` instead of `.text.exit` when linked by lld. To address the problem, append a dot to become `.text.exit.` Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D79600
2020-04-30[AIX] emit .extern and .weak directive linkagediggerlin
SUMMARY: emit .extern and .weak directive linkage Reviewers: hubert.reinterpretcast, Jason Liu Subscribers: wuzish, nemanjai, hiraditya Differential Revision: https://reviews.llvm.org/D76932
2020-04-24Use .text.unlikely and .text.eh prefixes for MachineBasicBlock sections.Snehasish Kumar
Summary: Instead of adding a ".unlikely" or ".eh" suffix for machine basic blocks, this change updates the behaviour to use an appropriate prefix instead. This allows lld to group basic block sections together when -z,keep-text-section-prefix is specified and matches the behaviour observed in gcc. Reviewers: tmsriram, mtrofin, efriedma Reviewed By: tmsriram, efriedma Subscribers: eli.friedman, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78742
2020-04-17[XCOFF][AIX] Fix getSymbol to return the correct qualname when necessaryjasonliu
Summary: AIX symbol have qualname and unqualified name. The stock getSymbol could only return unqualified name, which leads us to patch many caller side(lowerConstant, getMCSymbolForTOCPseudoMO). So we should try to address this problem in the callee side(getSymbol) and clean up the caller side instead. Note: this is a "mostly" NFC patch, with a fix for the original lowerConstant behavior. Differential Revision: https://reviews.llvm.org/D78045
2020-04-16[MC][ELF] Put explicit section name symbols into entry size compatible sectionsbd1976llvm
Ensure that symbols explicitly* assigned a section name are placed into a section with a compatible entry size. This is done by creating multiple sections with the same name** if incompatible symbols are explicitly given the name of an incompatible section, whilst: - Avoiding using uniqued sections where possible (for readability and to maximize compatibly with assemblers). - Creating as few SHF_MERGE sections as possible (for efficiency). Given that each symbol is assigned to a section in a single pass, we must decide which section each symbol is assigned to without seeing the properties of all symbols. A stable and easy to understand assignment is desirable. The following rules facilitate this: The "generic" section for a given section name will be mergeable if the name is a mergeable "default" section name (such as .debug_str), a mergeable "implicit" section name (such as .rodata.str2.2), or MC has already created a mergeable "generic" section for the given section name (e.g. in response to a section directive in inline assembly). Otherwise, the "generic" section for a given name is non-mergeable; and, non-mergeable symbols are assigned to the "generic" section, while mergeable symbols are assigned to uniqued sections. Terminology: "default" sections are those always created by MC initially, e.g. .text or .debug_str. "implicit" sections are those created normally by MC in response to the symbols that it encounters, i.e. in the absence of an explicit section name assignment on the symbol, e.g. a function foo might be placed into a .text.foo section. "generic" sections are those that are referred to when a unique section ID is not supplied, e.g. if there are multiple unique .bob sections then ".quad .bob" will reference the generic .bob section. Typically, the generic section is just the first section of a given name to be created. Default sections are always generic. * Typically, section names might be explicitly assigned in source code using a language extension e.g. a section attribute: _attribute_ ((section ("section-name"))) - https://clang.llvm.org/docs/AttributeReference.html ** I refer to such sections as unique/uniqued sections. In assembly the ", unique," assembly syntax is used to express such sections. Fixes https://bugs.llvm.org/show_bug.cgi?id=43457. See https://reviews.llvm.org/D68101 for previous discussions leading to this patch. Some minor fixes were required to LLVM's tests, for tests had been using the old behavior - which allowed for explicitly assigning globals with incompatible entry sizes to a section. This fix relies on the ",unique ," assembly feature. This feature is not available until bintuils version 2.35 (https://sourceware.org/bugzilla/show_bug.cgi?id=25380). If the integrated assembler is not being used then we avoid using this feature for compatibility and instead try to place mergeable symbols into non-mergeable sections or issue an error otherwise. Differential Revision: https://reviews.llvm.org/D72194
2020-04-15[MC] Rename MCSection*::getSectionName() to getName(). NFCFangrui Song
A pending change will merge MCSection*::getName() to MCSection::getName().
2020-04-15[NFC] correct "thier" to "their"Josh Stone
2020-04-14[WebAssembly] Emit .llvmcmd and .llvmbc as custom sectionsSam Clegg
Fixes: https://bugs.llvm.org/show_bug.cgi?id=45362 Differential Revision: https://reviews.llvm.org/D77115
2020-04-13Extend BasicBlock sections to allow specifying clusters of basic blocks in ↵Rahman Lavaee
the same section. Differential Revision: https://reviews.llvm.org/D76954
2020-04-13Revert "Extend BasicBlock sections to allow specifying clusters of basic blocks"Rahman Lavaee
This reverts commit 0d4ec16d3db3a92514e14101f635e8536c208c4f Because tests were not added to the commit.
2020-04-13Extend BasicBlock sections to allow specifying clusters of basic blocksRahman Lavaee
in the same section. This allows specifying BasicBlock clusters like the following example: !foo !!0 1 2 !!4 This places basic blocks 0, 1, and 2 in one section in this order, and places basic block #4 in a single section of its own.
2020-04-10Clean up usages of asserting vector getters in TypeChristopher Tetreault
Summary: Remove usages of asserting vector getters in Type in preparation for the VectorType refactor. The existence of these functions complicates the refactor while adding little value. Reviewers: stoklund, sdesmalen, efriedma Reviewed By: sdesmalen Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77272
2020-03-26[AIX] discard the label in the csect of function description and use ↵diggerlin
qualname for linkage SUMMARY: SUMMARY for a source file "test.c" void foo() {}; llc will generate assembly code as (assembly patch) .globl foo .globl .foo .csect foo[DS] foo: .long .foo .long TOC[TC0] .long 0 and symbol table as (xcoff object file) [4] m 0x00000004 .data 1 unamex foo [5] a4 0x0000000c 0 0 SD DS 0 0 [6] m 0x00000004 .data 1 extern foo [7] a4 0x00000004 0 0 LD DS 0 0 After first patch, the assembly will be as .globl foo[DS] # -- Begin function foo .globl .foo .align 2 .csect foo[DS] .long .foo .long TOC[TC0] .long 0 and symbol table will as [6] m 0x00000004 .data 1 extern foo [7] a4 0x00000004 0 0 DS DS 0 0 Change the code for the assembly path and xcoff objectfile patch for llc. Reviewers: Jason Liu Subscribers: wuzish, nemanjai, hiraditya Differential Revision: https://reviews.llvm.org/D76162
2020-03-20[X86] Reland D71360 Clean up UseInitArray initialization for ↵Fangrui Song
X86ELFTargetObjectFile -fuse-init-array is now the CC1 default but TargetLoweringObjectFileELF::UseInitArray still defaults to false. The following two unknown OS target triples continue using .ctors/.dtors because InitializeELF is not called. clang -target i386 -c a.c clang -target x86_64 -c a.c This cleanup fixes this as a bonus. X86SpeculativeLoadHardeningPass::tracePredStateThroughCall can call MCContext::createTempSymbol before TargetLoweringObjectFileELF::Initialize(). We need to call TargetLoweringObjectFileELF::Initialize() ealier. test/CodeGen/X86/speculative-load-hardening-indirect.ll Differential Revision: https://reviews.llvm.org/D71360
2020-03-20Temporarily Revert "[X86] Reland D71360 Clean up UseInitArray initialization ↵Eric Christopher
for X86ELFTargetObjectFile" as it's causing msan failures. This reverts commit 7899fe9da8d8df6f19ddcbbb877ea124d711c54b.
2020-03-20[X86] Reland D71360 Clean up UseInitArray initialization for ↵Fangrui Song
X86ELFTargetObjectFile UseInitArray is now the CC1 default but TargetLoweringObjectFileELF::UseInitArray still defaults to false. The following two unknown OS target triples continue using .ctors/.dtors because InitializeELF is not called. clang -target i386 -c a.c clang -target x86_64 -c a.c This cleanup fixes this as a bonus. Differential Revision: https://reviews.llvm.org/D71360
2020-03-16Basic Block Sections support in LLVM.Sriraman Tallam
This is the second patch in a series of patches to enable basic block sections support. This patch adds support for: * Creating direct jumps at the end of basic blocks that have fall through instructions. * New pass, bbsections-prepare, that analyzes placement of basic blocks in sections. * Actual placing of a basic block in a unique section with special handling of exception handling blocks. * Supports placing a subset of basic blocks in a unique section. * Support for MIR serialization and deserialization with basic block sections. Parent patch : D68063 Differential Revision: https://reviews.llvm.org/D73674
2020-03-11Fix conflict value for metadata "Objective-C Garbage Collection" in the mix ↵Jin Lin
of swift and Objective-C bitcode Summary: The change is to fix conflict value for metadata "Objective-C Garbage Collection" in the mix of swift and Objective-C bitcode. The purpose is to provide the support of LTO for swift and Objective-C mixed project. Reviewers: rjmccall, ahatanak, steven_wu Reviewed By: rjmccall, steven_wu Subscribers: manmanren, mehdi_amini, hiraditya, dexonsmith, llvm-commits, jinlin Tags: #llvm Differential Revision: https://reviews.llvm.org/D71219
2020-03-06[AIX] Handle LinkOnceODRLinkage and AppendingLinkage for static init gloabl ↵Xiangling Liao
arrays Handle LinkOnceODRLinkage; Handle AppendingLinkage type for llvm.global_ctors/dtors static init global arrays; Differential Revision: https://reviews.llvm.org/D75305
2020-02-29[MC] Add MCStreamer::emitInt{8,16,32,64}Fangrui Song
Similar to AsmPrinter::emitInt{8,16,32,64}.