1//===-- MipsTargetObjectFile.cpp - Mips Object Files ----------------------===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 24cl::desc(
"Small data and bss section threshold size (default=8)"),
29cl::desc(
"MIPS: Use gp_rel for object-local data."),
34cl::desc(
"MIPS: Use gp_rel for data that is not defined by the " 40cl::desc(
"MIPS: Try to allocate variables in the following" 41" sections if possible: .rodata, .sdata, .data ."),
57// A address must be loaded from a small section if its size is less than the 58// small section size threshold. Data in this section must be addressed using 61// gcc has traditionally not treated zero-sized objects as small data, so this 62// is effectively part of the ABI. 66/// Return true if this global address should be placed into small data/bss 68bool MipsTargetObjectFile::IsGlobalInSmallSection(
70// We first check the case where global is a declaration, because finding 71// section kind using getKindForGlobal() is only allowed for global 74return IsGlobalInSmallSectionImpl(GO, TM);
79/// Return true if this global address should be placed into small data/bss 81bool MipsTargetObjectFile::
84return IsGlobalInSmallSectionImpl(GO, TM) &&
85 (Kind.isData() || Kind.isBSS() || Kind.isCommon() ||
89/// Return true if this global address should be placed into small data/bss 90/// section. This method does all the work, except for checking the section 92bool MipsTargetObjectFile::
98// Return if small section is not available. 102// Only global variables, not functions. 107// If the variable has an explicit section, it is placed in that section but 108// it's addressing mode may change. 112// Explicitly placing any variable in the small data section overrides 113// the global -G value. 114if (Section ==
".sdata" || Section ==
".sbss")
117// Otherwise reject accessing it through the gp pointer. There are some 118// historic cases which GCC doesn't appear to respect any more. These 119// are .lit4, .lit8 and .srdata. For the moment reject these as well. 123// Enforce -mlocal-sdata. 127// Enforce -mextern-sdata. 132// Enforce -membedded-data. 138// It is possible that the type of the global is unsized, i.e. a declaration 139// of a extern struct. In this case don't presume it is in the small data 140// section. This happens e.g. when building the FreeBSD kernel. 150// TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*" 153// Handle Small Section classification here. 154if (Kind.isBSS() && IsGlobalInSmallSection(GO, TM, Kind))
155return SmallBSSSection;
156if (Kind.isData() && IsGlobalInSmallSection(GO, TM, Kind))
157return SmallDataSection;
158if (Kind.isReadOnly() && IsGlobalInSmallSection(GO, TM, Kind))
159return SmallDataSection;
161// Otherwise, we work the same as ELF. 165/// Return true if this constant should be placed into small data section. 170 ->useSmallSection() &&
174/// Return true if this constant should be placed into small data section. 178Align &Alignment)
const{
180return SmallDataSection;
182// Otherwise, we work the same as ELF. MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< unsigned > SSThreshold("lanai-ssection-threshold", cl::Hidden, cl::desc("Small data and bss section threshold size (default=0)"), cl::init(0))
static cl::opt< bool > ExternSData("mextern-sdata", cl::Hidden, cl::desc("MIPS: Use gp_rel for data that is not defined by the " "current object."), cl::init(true))
static cl::opt< unsigned > SSThreshold("mips-ssection-threshold", cl::Hidden, cl::desc("Small data and bss section threshold size (default=8)"), cl::init(8))
static cl::opt< bool > LocalSData("mlocal-sdata", cl::Hidden, cl::desc("MIPS: Use gp_rel for object-local data."), cl::init(true))
static bool IsInSmallSection(uint64_t Size)
static cl::opt< bool > EmbeddedData("membedded-data", cl::Hidden, cl::desc("MIPS: Try to allocate variables in the following" " sections if possible: .rodata, .sdata, .data ."), cl::init(false))
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasSection() const
Check if this global has a custom object file section.
bool hasExternalLinkage() const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasLocalLinkage() const
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
bool hasCommonLinkage() const
bool hasAvailableExternallyLinkage() const
Type * getValueType() const
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Base class for the full range of assembler expressions which are needed for parsing.
MCContext & getContext() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static const MipsMCExpr * create(MipsExprKind Kind, const MCExpr *Expr, MCContext &Ctx)
bool useSmallSection() const
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Return true if this constant should be placed into small data section.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const override
Describe a TLS variable address within debug info.
bool IsConstantInSmallSection(const DataLayout &DL, const Constant *CN, const TargetMachine &TM) const
Return true if this constant should be placed into small data section.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
SectionKind - This is a simple POD value that classifies the properties of a section.
StringRef - Represent a constant reference to a string, i.e.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Type * getType() const
All values are typed, get the type of this value.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.