aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCELFStreamer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-04-06[MC] Always encode instruction into SmallVectorAlexis Engelke1-2/+1
All users of MCCodeEmitter::encodeInstruction use a raw_svector_ostream to encode the instruction into a SmallVector. The raw_ostream however incurs some overhead for the actual encoding. This change allows an MCCodeEmitter to directly emit an instruction into a SmallVector without using a raw_ostream and therefore allow for performance improvments in encoding. A default path that uses existing raw_ostream implementations is provided. Reviewed By: MaskRay, Amir Differential Revision: https://reviews.llvm.org/D145791
2022-12-12[Alignment][NFC] Use Align in MCSymbol::declareCommonGuillaume Chatelet1-1/+1
2022-12-09[Alignment] Use Align in MCStreamer::emitCommonSymbolGuillaume Chatelet1-4/+4
Next patch after D139548 and D139439. Same expectations, the change seems safe with as far as llvm goes, we cannot check downstream implementations. Differential Revision: https://reviews.llvm.org/D139614
2022-12-08[Alignment] Use Align in MCStreamer::emitTBSSSymbolGuillaume Chatelet1-1/+1
In the same vein as D139439, the patch is not NFC as there is no way to check all downstream implementations but the patch seems pretty safe. Differential Revision: https://reviews.llvm.org/D139548
2022-12-07[reland][Alignment] Use Align in MCStreamer emitZeroFill/emitLocalCommonSymbolGuillaume Chatelet1-3/+3
Before performing this change, I checked that `ByteAlignment` was never `0` inside `MCAsmStreamer:emitZeroFill` and `MCAsmStreamer::emitLocalCommonSymbol`. I believe it is NFC as `0` values are illegal in `emitZeroFill` anyways, `Log2(ByteAlignment)` would be undefined. And currently, all calls to `emitLocalCommonSymbol` are provably `>0`. Differential Revision: https://reviews.llvm.org/D139439
2022-12-07Revert D139439 "[Alignment] Use Align in MCStreamer ↵Guillaume Chatelet1-3/+3
emitZeroFill/emitLocalCommonSymbol" This breaks Windows bots with `warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)` Some shift operators are lacking a proper literal unit ('1ULL' instead of '1'). Will reland once fixed. This reverts commit c621c1a8e81856e6bf2be79714767d80466e9ede.
2022-12-07[Alignment] Use Align in MCStreamer emitZeroFill/emitLocalCommonSymbolGuillaume Chatelet1-3/+3
Before performing this change, I checked that `ByteAlignment` was never `0` inside `MCAsmStreamer:emitZeroFill` and `MCAsmStreamer::emitLocalCommonSymbol`. I believe it is NFC as `0` values are illegal in `emitZeroFill` anyways, `Log2(ByteAlignment)` would be undefined. And currently, all calls to `emitLocalCommonSymbol` are provably `>0`. Differential Revision: https://reviews.llvm.org/D139439
2022-12-04[MC] llvm::Optional => std::optionalFangrui Song1-1/+1
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-01Add assembler plumbing for sanitize_memtagMitch Phillips1-0/+4
Extends the Asm reader/writer to support reading and writing the '.memtag' directive (including allowing it on internal global variables). Also add some extra tooling support, including objdump and yaml2obj/obj2yaml. Test that the sanitize_memtag IR attribute produces the expected asm directive. Uses the new Aarch64 MemtagABI specification (https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst) to identify symbols as tagged in object files. This is done using a R_AARCH64_NONE relocation that identifies each tagged symbol, and these relocations are tagged in a special SHT_AARCH64_MEMTAG_GLOBALS_STATIC section. This signals to the linker that the global variable should be tagged. Reviewed By: fmayer, MaskRay, peter.smith Differential Revision: https://reviews.llvm.org/D128958
2022-11-28[NFC] Add helper method to ensure min alignment on MCSectionGuillaume Chatelet1-3/+2
Follow up on D138653. Differential Revision: https://reviews.llvm.org/D138686
2022-11-24[Alignment][NFC] Use Align in MCStreamer::emitValueToAlignmentGuillaume Chatelet1-5/+4
Differential Revision: https://reviews.llvm.org/D138674
2022-11-24[Alignment][NFC] Use Align in MCStreamer::emitCodeAlignmentGuillaume Chatelet1-1/+2
This patch makes code less readable but it will clean itself after all functions are converted. Differential Revision: https://reviews.llvm.org/D138665
2022-11-24[Alignment][NFC] Use Align in MCStreamer::emitBundleAlignModeGuillaume Chatelet1-5/+5
Summary: Reviewers: courbet Subscribers:
2022-11-24[reland][Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet1-1/+1
Differential Revision: https://reviews.llvm.org/D138653
2022-11-24Revert D138653 [Alignment][NFC] Use the Align type in MCSection"Guillaume Chatelet1-1/+1
This breaks the bolt project. This reverts commit 409f0dc4a420db1c6b259d5ae965a070c169d930.
2022-11-24[Alignment][NFC] Use the Align type in MCSectionGuillaume Chatelet1-1/+1
Differential Revision: https://reviews.llvm.org/D138653
2022-08-25[MC][ELF] Mark GNU ABI if ifunc are usedAdhemerval Zanella1-0/+1
Similar to D107861. Some tools required the GNU ABI mark to output the symbol is a IFUNC type correctly (for instance binutils readelf). Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D131162
2022-06-10[MC] De-capitalize SwitchSection. NFCFangrui Song1-8/+8
Add SwitchSection to return switchSection. The API will be removed soon.
2022-06-07[MC] De-capitalize MCStreamer functionsFangrui Song1-4/+4
Follow-up to c031378ce01b8485ba0ef486654bc9393c4ac024 . The class is mostly consistent now.
2022-04-28[LLVM] Add exported visibility style for XCOFFDavid Tenty1-0/+1
For the AIX linker, under default options, global or weak symbols which have no visibility bits set to zero (i.e. no visibility, similar to ELF default) are only exported if specified on an export list provided to the linker. So AIX has an additional visibility style called "exported" which indicates to the linker that the symbol should be explicitly globally exported. This change maps "dllexport" in the LLVM IR to correspond to XCOFF exported as we feel this best models the intended semantic (discussion on the discourse RFC thread: https://discourse.llvm.org/t/rfc-adding-exported-visibility-style-to-the-ir-to-model-xcoff-exported-visibility/61853) and allows us to enable writing this visibility for the AIX target in the assembly path. Reviewed By: DiggerLin Differential Revision: https://reviews.llvm.org/D123951
2021-11-24[LLVM][NFC]Inclusive language: remove occurances of sanity check/test from llvmZarko Todorovski1-3/+0
Part of work to use more inclusive language in clang/llvm. Rewording some comments and change function and variable names.
2021-10-08Move TargetRegistry.(h|cpp) from Support to MCReid Kleckner1-1/+1
This moves the registry higher in the LLVM library dependency stack. Every client of the target registry needs to link against MC anyway to actually use the target, so we might as well move this out of Support. This allows us to ensure that Support doesn't have includes from MC/*. Differential Revision: https://reviews.llvm.org/D111454
2021-10-06[llvm] Replace report_fatal_error(std::string) uses with ↵Simon Pilgrim1-2/+2
report_fatal_error(Twine) As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared.
2021-09-07[MC] Add MCSubtargetInfo to MCAlignFragmentPeter Smith1-2/+2
In preparation for passing the MCSubtargetInfo (STI) through to writeNops so that it can use the STI in operation at the time, we need to record the STI in operation when a MCAlignFragment may write nops as padding. The STI is currently unused, a further patch will pass it through to writeNops. There are many places that can create an MCAlignFragment, in most cases we can find out the STI in operation at the time. In a few places this isn't possible as we are in initialisation or finalisation, or are emitting constant pools. When possible I've tried to find the most appropriate existing fragment to obtain the STI from, when none is available use the per module STI. For constant pools we don't actually need to use EmitCodeAlign as the constant pools are data anyway so falling through into it via an executable NOP is no better than falling through into data padding. This is a prerequisite for D45962 which uses the STI to emit the appropriate NOP for the STI. Which can differ per fragment. Note that involves an interface change to InitSections. It is now called initSections and requires a SubtargetInfo as a parameter. Differential Revision: https://reviews.llvm.org/D45961
2021-08-27[MC][RISCV] Add RISCV MCObjectFileInfoPhilipp Krones1-1/+1
This makes sure, that the text section will have a 2-byte alignment, if the +c extension is enabled. Reviewed By: MaskRay, luismarques Differential Revision: https://reviews.llvm.org/D102052
2021-08-27[MC] Change ELFOSABI_NONE to ELFOSABI_GNU for STB_GNU_UNIQUEFangrui Song1-0/+1
Similar to D97976. On Linux, most GCC installations are configured with `--enable-gnu-unique-object` and such GCC emits `@gnu_unique_object` assembly. The feature is highly controversial and disliked by many folks. (On glibc DF_1_NODELETE is implicitly enabled and makes dlclose a no-op). In llvm-project STB_GNU_UNIQUE is assembly only. Clang does not use STB_GNU_UNIQUE. Use ELFOSABI_GNU to match GNU as behavior and avoid collision with other OSABI binding values. Reviewed By: jrtc27 Differential Revision: https://reviews.llvm.org/D107861
2021-06-30[MCStreamer] Move emission of attributes section into MCELFStreamerJonas Paulsson1-0/+158
Enable the emission of a GNU attributes section by reusing the code for emitting the ARM build attributes section. The GNU attributes follow the exact same section format as the ARM BuildAttributes section, so this can be factored out and reused for GNU attributes generally. The immediate motivation for this is to emit a GNU attributes section for the vector ABI on SystemZ (https://reviews.llvm.org/D105067). Review: Logan Chien, Ulrich Weigand Differential Revision: https://reviews.llvm.org/D102894
2021-06-24[MC][ELF] Change SHT_LLVM_CALL_GRAPH_PROFILE relocations from SHT_RELA to ↵Fangrui Song1-2/+3
SHT_REL ... even on targets preferring RELA. The section is only consumed by ld.lld which can handle REL. Follow-up to D104080 as I explained in the review. There are two advantages: * The D104080 code only handles RELA, so arm/i386/mips32 etc may warn for -fprofile-use=/-fprofile-sample-use= usage. * Decrease object file size for RELA targets While here, change the relocation to relocate weights, instead of 0,1,2,3,.. I failed to catch the issue during review.
2021-06-24[LLD][LLVM] CG Graph profile using relocationsAlexander Yermolovich1-12/+26
Currently when .llvm.call-graph-profile is created by llvm it explicitly encodes the symbol indices. This section is basically a black box for post processing tools. For example, if we run strip -s on the object files the symbol table changes, but indices in that section do not. In non-visible behavior indices point to wrong symbols. The visible behavior indices point outside of Symbol table: "invalid symbol index". This patch changes the format by using R_*_NONE relocations to indicate the from/to symbols. The Frequency (Weight) will still be in the .llvm.call-graph-profile, but symbol information will be in relocation section. In LLD information from both sections is used to reconstruct call graph profile. Relocations themselves will never be applied. With this approach post processing tools that handle relocations correctly work for this section also. Tools can add/remove symbols and as long as they handle relocation sections with this approach information stays correct. Doing a quick experiment with clang-13. The size went up from 107KB to 322KB, aggregate of all the input sections. Size of clang-13 binary is ~118MB. For users of -fprofile-use/-fprofile-sample-use the size of object files will go up slightly, it will not impact final binary size. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D104080
2021-03-09[MC] Change ELFOSABI_NONE to ELFOSABI_GNU for SHF_GNU_RETAINFangrui Song1-0/+2
GNU ld does not give SHF_GNU_RETAIN GC root semantics for ELFOSABI_NONE. (https://sourceware.org/pipermail/binutils/2021-March/115581.html) This allows GNU ld to interpret SHF_GNU_RETAIN and avoids a gold quirk https://sourceware.org/bugzilla/show_bug.cgi?id=27490 Because ELFObjectWriter is in an anonymous namespace, I have to place `markGnuAbi` in the parent MCObjectWriter. Differential Revision: https://reviews.llvm.org/D97976
2021-03-08[NFC] Use ranged loop iteration instead of explicit loopingserge-sans-paille1-7/+8
2021-03-06[MC] Support .symver *, *, removeFangrui Song1-4/+5
As a resolution to https://sourceware.org/bugzilla/show_bug.cgi?id=25295 , GNU as from binutils 2.35 supports the optional third argument for the .symver directive. 'remove' for a non-default version is useful: `.symver def_v1, def@v1, remove` => def_v1 is not retained in the symbol table. Previously the user has to strip the original symbol or specify a `local:` version node in a version script to localize the symbol. `.symver def, def@@v1, remove` and `.symver def, def@@@v1, remove` are supported as well, though they are identical to `.symver def, def@@@v1`. local/hidden are not useful so this patch does not implement them.
2021-02-16[MC][ELF] Support for zero flag section groupsPetr Hosek1-1/+1
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
2020-12-20[MC][ELF] Remove unneeded MCSymbol::setExternal callsFangrui Song1-11/+2
ELF code uses symbol bindings and does not call isExternal().
2020-12-20[MC] Report locations for .symver errorsFangrui Song1-1/+2
2020-11-02[MC] Make MCStreamer aware of AsmParser's StartTokLocFangrui Song1-8/+9
A SMLoc allows MCStreamer to report location-aware diagnostics, which were previously done by adding SMLoc to various methods (e.g. emit*) in an ad-hoc way. Since the file:line is most important, the column is less important and the start token location suffices in many cases, this patch reverts b7e7131af2dd7bdb03fa42a3bc1b4bc72ab95ce1 ``` // old symbol-binding-changed.s:6:8: error: local changed binding to STB_GLOBAL .globl local ^ // new symbol-binding-changed.s:6:1: error: local changed binding to STB_GLOBAL .globl local ^ ``` Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D90511
2020-10-29[MC] Add SMLoc to MCStreamer::emitSymbolAttribute and report changed binding ↵Fangrui Song1-7/+8
warnings/errors for ELF
2020-10-29[MC] Error for .globl/.local which change the symbol binding and warn for .weakFangrui Song1-0/+14
GNU as let .weak override .globl since binutils-gdb 5ca547dc2399a0a5d9f20626d4bf5547c3ccfddd (1996) while MC lets the last directive win (PR38921). This caused an issue to Linux's powerpc port which has been fixed by http://git.kernel.org/linus/968339fad422a58312f67718691b717dac45c399 Binding overriding is error-prone. This patch disallows a changed binding. (https://sourceware.org/pipermail/binutils/2020-March/000299.html ) Our behavior regarding `.globl x; .weak x` matches GNU as. Such usage is still suspicious but we issue a warning for now. We may upgrade it to an error in the future. Reviewed By: jhenderson, nickdesaulniers Differential Revision: https://reviews.llvm.org/D90108
2020-09-03[PowerPC] Fix missing TLS symbol type.Stefan Pintilie1-0/+3
Previous implementations for the TLS models General Dynamic and Initial Exec were missing the ELF::STT_TLS type on symbols that required the type. This patch adds the type. Reviewed By: sfertile, MaskRay Differential Revision: https://reviews.llvm.org/D86777
2020-04-30Clean up warnings after a2c8cd18128d3529992a86998d2bea80cceafff0Benjamin Kramer1-0/+1
2020-04-20[MC][NFC] Use camelCase style for functions in MCObjectStreamerShengchen Kan1-6/+6
2020-04-20[MC][NFC] Use camelCase style for function EmitInstToDataShengchen Kan1-1/+1
2020-02-29[MC] Add MCStreamer::emitInt{8,16,32,64}Fangrui Song1-2/+2
Similar to AsmPrinter::emitInt{8,16,32,64}.
2020-02-15[MC] De-capitalize MCStreamer::Emit{Bundle,Addrsig}* etcFangrui Song1-6/+6
So far, all non-COFF-related Emit* functions have been de-capitalized.
2020-02-14[MCStreamer] De-capitalize EmitValue EmitIntValue{,InHex}Fangrui Song1-2/+2
2020-02-14[MC] De-capitalize another set of MCStreamer::Emit* functionsFangrui Song1-9/+9
Emit{ValueTo,Code}Alignment Emit{DTP,TP,GP}* EmitSymbolValue etc
2020-02-14[MC] De-capitalize some MCStreamer::Emit* functionsFangrui Song1-10/+10
2020-02-13[AsmPrinter] De-capitalize some AsmPrinter::Emit* functionsFangrui Song1-2/+2
Similar to rL328848.
2019-12-16[MC] Delete redundant alignment update from MCELFStreamer::EmitCommonSymbol. NFCFangrui Song1-4/+0
EmitValueToAlignment() updates the maximum alignment.
2019-11-16MCObjectStreamer: assign MCSymbols in the dummy fragment to offset 0.James Y Knight1-2/+3
In MCObjectStreamer, when there is no current fragment, initially symbols are created in a "pending" state and assigned to a dummy empty fragment. Previously, they were not being assigned an offset, and thus evaluateAbsolute would fail if trying to evaluate an expression 'a - b', where both 'a' and 'b' were in this pending state. Also slightly refactored the EmitLabel overload which takes an MCFragment for clarity. Fixes: https://llvm.org/PR41825 Differential Revision: https://reviews.llvm.org/D70062