LLVM 22.0.0git
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
llvm::MCSymbol Class Reference

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created and uniqued by the MCContext class. More...

#include "llvm/MC/MCSymbol.h"

Inheritance diagram for llvm::MCSymbol:
[legend]

Public Member Functions

StringRef getName () const
 getName - Get the symbol name.
 
bool isRegistered () const
 
void setIsRegistered (bool Value) const
 
void setUsedInReloc () const
 
bool isUsedInReloc () const
 
uint32_t getIndex () const
 Get the (implementation defined) index.
 
void setIndex (uint32_t Value) const
 Set the (implementation defined) index.
 
uint64_t getOffset () const
 
void setOffset (uint64_t Value)
 
uint64_t getCommonSize () const
 Return the size of a 'common' symbol.
 
void setCommon (uint64_t Size, Align Alignment)
 Mark this symbol as being 'common'.
 
MaybeAlign getCommonAlignment () const
 Return the alignment of a 'common' symbol.
 
bool declareCommon (uint64_t Size, Align Alignment)
 Declare this symbol as being 'common'.
 
bool isCommon () const
 Is this a 'common' symbol.
 
MCFragmentgetFragment () const
 
bool isWeakExternal () const
 
LLVM_ABI void print (raw_ostream &OS, const MCAsmInfo *MAI) const
 print - Print the value to the stream OS.
 
LLVM_ABI void dump () const
 dump - Print the value to stderr.
 
Accessors
bool isTemporary () const
 isTemporary - Check if this is an assembler temporary symbol.
 
bool isRedefinable () const
 Check if this symbol is redefinable.
 
void setRedefinable (bool Value)
 Mark this symbol as redefinable.
 
void redefineIfPossible ()
 Prepare this symbol to be redefined.
 
bool isResolving () const
 
void setIsResolving (bool V)
 
Associated Sections
bool isDefined () const
 isDefined - Check if this symbol is defined (i.e., it has an address).
 
bool isInSection () const
 isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
 
bool isUndefined () const
 isUndefined - Check if this symbol undefined (i.e., implicitly defined).
 
bool isAbsolute () const
 isAbsolute - Check if this is an absolute symbol.
 
MCSectiongetSection () const
 Get the section associated with a defined, non-absolute symbol.
 
void setFragment (MCFragment *F) const
 Mark the symbol as defined in the fragment F.
 
Variable Symbols
bool isVariable () const
 isVariable - Check if this is a variable symbol.
 
const MCExprgetVariableValue () const
 Get the expression of the variable symbol.
 
LLVM_ABI void setVariableValue (const MCExpr *Value)
 

Protected Types

enum  Kind : uint8_t { Regular , Equated , Common }
 
enum  : unsigned { NumCommonAlignmentBits = 5 }
 The alignment of the symbol if it is 'common'. More...
 
enum  : unsigned { NumFlagsBits = 16 }
 The Flags field is used by object file implementations to store additional per symbol information which is not easily classified. More...
 
using NameEntryStorageTy = union { const MCSymbolTableEntry *NameEntry
 The name for a symbol.
 

Protected Member Functions

 MCSymbol (const MCSymbolTableEntry *Name, bool isTemporary)
 
 MCSymbol (const MCSymbol &)=default
 
MCSymboloperator= (const MCSymbol &)=delete
 
LLVM_ABI void * operator new (size_t s, const MCSymbolTableEntry *Name, MCContext &Ctx)
 
uint32_t getFlags () const
 Get the (implementation defined) symbol flags.
 
void setFlags (uint32_t Value) const
 Set the (implementation defined) symbol flags.
 
void modifyFlags (uint32_t Value, uint32_t Mask) const
 Modify the flags via a mask.
 

Protected Attributes

MCFragmentFragment = nullptr
 If a symbol has a Fragment, the section is implied, so we only need one pointer.
 
unsigned kind: 2
 The symbol kind.
 
unsigned HasName: 1
 True if this symbol is named.
 
unsigned IsTemporary: 1
 IsTemporary - True if this is an assembler temporary label, which typically does not survive in the .o file's symbol table.
 
unsigned IsRedefinable: 1
 True if this symbol can be redefined.
 
unsigned IsRegistered: 1
 
unsigned IsExternal: 1
 True if this symbol is visible outside this translation unit.
 
unsigned IsPrivateExtern: 1
 Mach-O specific: This symbol is private extern.
 
unsigned IsWeakExternal: 1
 This symbol is weak external.
 
unsigned IsUsedInReloc: 1
 True if we have created a relocation that uses this symbol.
 
unsigned IsResolving: 1
 Used to detect cyclic dependency like a = a + 1 and a = b; b = a.
 
unsigned CommonAlignLog2: NumCommonAlignmentBits
 
uint32_t Flags: NumFlagsBits
 
uint32_t Index = 0
 Index field, for use by the object file implementation.
 
union {
   uint64_t   Offset
 The offset to apply to the fragment address to form this symbol's value. More...
 
   uint64_t   CommonSize
 The size of the symbol, if it is 'common'. More...
 
   const MCExpr *   Value
 If non-null, the value for a variable symbol. More...
 
}; 
 
uint64_t AlignmentPadding
 

Static Protected Attributes

static LLVM_ABI MCFragmentAbsolutePseudoFragment = &SentinelFragment
 

Friends

class MCExpr
 
class MCContext
 

Detailed Description

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created and uniqued by the MCContext class.

MCSymbols should only be constructed with valid names for the object file.

If the symbol is defined/emitted into the current translation unit, the Section member is set to indicate what section it lives in. Otherwise, if it is a reference to an external entity, it has a null section.

Definition at line 42 of file MCSymbol.h.

Member Typedef Documentation

◆ NameEntryStorageTy

using llvm::MCSymbol::NameEntryStorageTy = union { const MCSymbolTableEntry *NameEntry
protected

The name for a symbol.

MCSymbol contains a uint64_t so is probably aligned to 8. On a 32-bit system, the name is a pointer so isn't going to satisfy the 8 byte alignment of uint64_t. Account for that here.

Definition at line 141 of file MCSymbol.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : unsigned
protected

The alignment of the symbol if it is 'common'.

Internally, this is stored as log2(align) + 1. We reserve 5 bits to encode this value which allows the following values 0b00000 -> unset 0b00001 -> 1ULL << 0 = 1 0b00010 -> 1ULL << 1 = 2 0b00011 -> 1ULL << 2 = 4 ... 0b11111 -> 1ULL << 30 = 1 GiB

Enumerator
NumCommonAlignmentBits 

Definition at line 111 of file MCSymbol.h.

◆ anonymous enum

anonymous enum : unsigned
protected

The Flags field is used by object file implementations to store additional per symbol information which is not easily classified.

Enumerator
NumFlagsBits 

Definition at line 116 of file MCSymbol.h.

◆ Kind

enum llvm::MCSymbol::Kind : uint8_t
protected
Enumerator
Regular 
Equated 
Common 

Definition at line 45 of file MCSymbol.h.

Constructor & Destructor Documentation

◆ MCSymbol() [1/2]

llvm::MCSymbol::MCSymbol ( const MCSymbolTableEntry Name,
bool  isTemporary 
)
inlineprotected

Definition at line 146 of file MCSymbol.h.

References HasName, Name, and Offset.

◆ MCSymbol() [2/2]

llvm::MCSymbol::MCSymbol ( const MCSymbol )
protecteddefault

Member Function Documentation

◆ declareCommon()

bool llvm::MCSymbol::declareCommon ( uint64_t  Size,
Align  Alignment 
)
inline

Declare this symbol as being 'common'.

Parameters
Size- The size of the symbol.
Alignment- The alignment of the symbol.
Returns
True if symbol was already declared as a different type

Definition at line 333 of file MCSymbol.h.

References assert(), CommonSize, getCommonAlignment(), getOffset(), isCommon(), setCommon(), and Size.

◆ dump()

LLVM_DUMP_METHOD void MCSymbol::dump ( ) const

dump - Print the value to stderr.

Definition at line 87 of file MCSymbol.cpp.

References llvm::dbgs().

◆ getCommonAlignment()

MaybeAlign llvm::MCSymbol::getCommonAlignment ( ) const
inline

Return the alignment of a 'common' symbol.

Definition at line 323 of file MCSymbol.h.

References assert(), CommonAlignLog2, llvm::decodeMaybeAlign(), and isCommon().

Referenced by declareCommon(), and llvm::MCSymbolMachO::getEncodedFlags().

◆ getCommonSize()

uint64_t llvm::MCSymbol::getCommonSize ( ) const
inline

Return the size of a 'common' symbol.

Definition at line 301 of file MCSymbol.h.

References assert(), CommonSize, and isCommon().

◆ getFlags()

uint32_t llvm::MCSymbol::getFlags ( ) const
inlineprotected

◆ getFragment()

MCFragment * llvm::MCSymbol::getFragment ( ) const
inline

◆ getIndex()

uint32_t llvm::MCSymbol::getIndex ( ) const
inline

Get the (implementation defined) index.

Definition at line 280 of file MCSymbol.h.

References Index.

Referenced by writeFragment(), and llvm::WinCOFFWriter::writeObject().

◆ getName()

StringRef llvm::MCSymbol::getName ( ) const
inline

getName - Get the symbol name.

Definition at line 188 of file MCSymbol.h.

References llvm::StringMapEntry< ValueTy >::first(), and HasName.

Referenced by llvm::MCResourceInfo::createTotalNumSGPRs(), llvm::MCResourceInfo::createTotalNumVGPRs(), llvm::SystemZTargetHLASMStreamer::createWordDiffExpr(), llvm::AsmPrinter::doFinalization(), llvm::AsmPrinter::emitCOFFReplaceableFunctionData(), llvm::EHStreamer::emitExceptionTable(), llvm::MipsAsmPrinter::emitFunctionBodyEnd(), llvm::ARMAsmPrinter::emitFunctionEntryLabel(), llvm::AsmPrinter::emitGlobalVariable(), llvm::AMDGPUAsmPrinter::emitGlobalVariable(), llvm::XtensaTargetAsmStreamer::emitLiteral(), llvm::XtensaAsmPrinter::emitMachineConstantPoolValue(), llvm::NVPTXTargetStreamer::emitValue(), llvm::MCStreamer::emitWinCFIBeginEpilogue(), llvm::MCStreamer::emitWinCFIEndEpilogue(), llvm::MCStreamer::emitWinCFIUnwindV2Start(), llvm::MCStreamer::emitWinCFIUnwindVersion(), EvaluateCRExpr(), llvm::RecordStreamer::flushSymverDirectives(), llvm::MCResourceInfo::gatherResourceInfo(), llvm::MCContext::getAssociativeCOFFSection(), getAuthPtrSlotSymbolHelper(), llvm::MCAssembler::getBaseSymbol(), llvm::TargetLoweringObjectFileELF::getCFIPersonalitySymbol(), llvm::MCContext::getCOFFSection(), llvm::MCContext::getELFSection(), llvm::MCSymbolMachO::getEncodedFlags(), llvm::AArch64MCInstLower::GetGlobalValueSymbol(), llvm::MCSymbolWasm::getImportName(), getLabelOffset(), llvm::NVPTXTargetLowering::getParamName(), llvm::TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(), getStaticStructorSection(), llvm::MachObjectWriter::getSymbolAddress(), getSymbolOffsetImpl(), llvm::MCSymbolXCOFF::getUnqualifiedName(), llvm::MCContext::getWasmSection(), hasGOTReference(), llvm::DIELabel::print(), llvm::DIEDelta::print(), print(), llvm::WebAssemblyInstPrinter::printCatchList(), llvm::MipsAsmPrinter::printOperand(), llvm::SystemZInstPrinterCommon::printPCRelTLSOperand(), llvm::PPCInstPrinter::printTLSCall(), llvm::AMDGPUAsmPrinter::runOnMachineFunction(), smallData(), llvm::stableHashValue(), startsWithGlobalOffsetTable(), and llvm::WinCOFFWriter::writeObject().

◆ getOffset()

uint64_t llvm::MCSymbol::getOffset ( ) const
inline

◆ getSection()

MCSection & llvm::MCSymbol::getSection ( ) const
inline

◆ getVariableValue()

const MCExpr * llvm::MCSymbol::getVariableValue ( ) const
inline

◆ isAbsolute()

bool llvm::MCSymbol::isAbsolute ( ) const
inline

isAbsolute - Check if this is an absolute symbol.

Definition at line 246 of file MCSymbol.h.

References AbsolutePseudoFragment, and getFragment().

◆ isCommon()

bool llvm::MCSymbol::isCommon ( ) const
inline

Is this a 'common' symbol.

Definition at line 344 of file MCSymbol.h.

References Common, and kind.

Referenced by declareCommon(), llvm::MCAssembler::getBaseSymbol(), getCommonAlignment(), getCommonSize(), and llvm::MCSymbolMachO::getEncodedFlags().

◆ isDefined()

bool llvm::MCSymbol::isDefined ( ) const
inline

isDefined - Check if this symbol is defined (i.e., it has an address).

Defined symbols are either absolute or in some section.

Definition at line 233 of file MCSymbol.h.

References isUndefined().

Referenced by llvm::DwarfCompileUnit::attachLowHighPC(), llvm::EHStreamer::computePadMap(), llvm::AsmPrinter::emitGlobalVariable(), llvm::AMDGPUAsmPrinter::emitGlobalVariable(), llvm::MCSymbolELF::getBinding(), and llvm::MCContext::getCOFFSection().

◆ isInSection()

bool llvm::MCSymbol::isInSection ( ) const
inline

◆ isRedefinable()

bool llvm::MCSymbol::isRedefinable ( ) const
inline

Check if this symbol is redefinable.

Definition at line 208 of file MCSymbol.h.

References IsRedefinable.

◆ isRegistered()

bool llvm::MCSymbol::isRegistered ( ) const
inline

Definition at line 195 of file MCSymbol.h.

References IsRegistered.

Referenced by llvm::WinCOFFWriter::writeObject().

◆ isResolving()

bool llvm::MCSymbol::isResolving ( ) const
inline

Definition at line 223 of file MCSymbol.h.

References IsResolving.

◆ isTemporary()

bool llvm::MCSymbol::isTemporary ( ) const
inline

◆ isUndefined()

bool llvm::MCSymbol::isUndefined ( ) const
inline

isUndefined - Check if this symbol undefined (i.e., implicitly defined).

Definition at line 243 of file MCSymbol.h.

References getFragment().

Referenced by attemptToFoldSymbolOffsetDifference(), llvm::MachObjectWriter::doesSymbolRequireExternRelocation(), isDefined(), and llvm::MCObjectWriter::isSymbolRefDifferenceFullyResolved().

◆ isUsedInReloc()

bool llvm::MCSymbol::isUsedInReloc ( ) const
inline

◆ isVariable()

bool llvm::MCSymbol::isVariable ( ) const
inline

◆ isWeakExternal()

bool llvm::MCSymbol::isWeakExternal ( ) const
inline

Definition at line 356 of file MCSymbol.h.

References IsWeakExternal.

Referenced by getFragment().

◆ modifyFlags()

void llvm::MCSymbol::modifyFlags ( uint32_t  Value,
uint32_t  Mask 
) const
inlineprotected

◆ operator new()

void * MCSymbol::operator new ( size_t  s,
const MCSymbolTableEntry Name,
MCContext Ctx 
)
protected

Definition at line 33 of file MCSymbol.cpp.

References End, Name, and Size.

◆ operator=()

MCSymbol & llvm::MCSymbol::operator= ( const MCSymbol )
protecteddelete

References llvm_unreachable.

◆ print()

void MCSymbol::print ( raw_ostream OS,
const MCAsmInfo MAI 
) const

◆ redefineIfPossible()

void llvm::MCSymbol::redefineIfPossible ( )
inline

◆ setCommon()

void llvm::MCSymbol::setCommon ( uint64_t  Size,
Align  Alignment 
)
inline

Mark this symbol as being 'common'.

Parameters
Size- The size of the symbol.
Alignment- The alignment of the symbol.
Target- Is the symbol a target-specific common-like symbol.

Definition at line 311 of file MCSymbol.h.

References assert(), Common, CommonAlignLog2, CommonSize, llvm::encode(), getOffset(), kind, NumCommonAlignmentBits, and Size.

Referenced by declareCommon().

◆ setFlags()

void llvm::MCSymbol::setFlags ( uint32_t  Value) const
inlineprotected

◆ setFragment()

void llvm::MCSymbol::setFragment ( MCFragment F) const
inline

Mark the symbol as defined in the fragment F.

Definition at line 257 of file MCSymbol.h.

References assert(), F, Fragment, and isVariable().

Referenced by llvm::MCXCOFFStreamer::changeSection(), and llvm::MCContext::getCOFFSection().

◆ setIndex()

void llvm::MCSymbol::setIndex ( uint32_t  Value) const
inline

Set the (implementation defined) index.

Definition at line 285 of file MCSymbol.h.

References Index, and Value.

◆ setIsRegistered()

void llvm::MCSymbol::setIsRegistered ( bool  Value) const
inline

Definition at line 196 of file MCSymbol.h.

References IsRegistered, and Value.

Referenced by llvm::MCContext::cloneSymbol().

◆ setIsResolving()

void llvm::MCSymbol::setIsResolving ( bool  V)
inline

Definition at line 224 of file MCSymbol.h.

References IsResolving.

◆ setOffset()

void llvm::MCSymbol::setOffset ( uint64_t  Value)
inline

Definition at line 294 of file MCSymbol.h.

References assert(), kind, Offset, Regular, and Value.

◆ setRedefinable()

void llvm::MCSymbol::setRedefinable ( bool  Value)
inline

Mark this symbol as redefinable.

Definition at line 210 of file MCSymbol.h.

References IsRedefinable, and Value.

◆ setUsedInReloc()

void llvm::MCSymbol::setUsedInReloc ( ) const
inline

Definition at line 198 of file MCSymbol.h.

References IsUsedInReloc.

◆ setVariableValue()

void MCSymbol::setVariableValue ( const MCExpr Value)

Friends And Related Function Documentation

◆ MCContext

friend class MCContext
friend

Definition at line 135 of file MCSymbol.h.

◆ MCExpr

friend class MCExpr
friend

Definition at line 134 of file MCSymbol.h.

Member Data Documentation

◆ 

union { ... } llvm::MCSymbol::@363

◆ AbsolutePseudoFragment

MCFragment * MCSymbol::AbsolutePseudoFragment = &SentinelFragment
staticprotected

Definition at line 52 of file MCSymbol.h.

Referenced by llvm::MCExpr::findAssociatedFragment(), isAbsolute(), and isInSection().

◆ AlignmentPadding

uint64_t llvm::MCSymbol::AlignmentPadding
protected

Definition at line 143 of file MCSymbol.h.

◆ CommonAlignLog2

unsigned llvm::MCSymbol::CommonAlignLog2
protected

Definition at line 112 of file MCSymbol.h.

Referenced by getCommonAlignment(), and setCommon().

◆ CommonSize

uint64_t llvm::MCSymbol::CommonSize

The size of the symbol, if it is 'common'.

Definition at line 127 of file MCSymbol.h.

Referenced by declareCommon(), getCommonSize(), and setCommon().

◆ Flags

uint32_t llvm::MCSymbol::Flags
mutableprotected

◆ Fragment

MCFragment* llvm::MCSymbol::Fragment = nullptr
mutableprotected

If a symbol has a Fragment, the section is implied, so we only need one pointer.

The special AbsolutePseudoFragment value is for absolute symbols. If this is a variable symbol, this caches the variable value's fragment. FIXME: We might be able to simplify this by having the asm streamer create dummy fragments. If this is a section, then it gives the symbol is defined in. This is null for undefined symbols.

If this is a fragment, then it gives the fragment this symbol's value is relative to, if any.

Definition at line 65 of file MCSymbol.h.

Referenced by getFragment(), redefineIfPossible(), setFragment(), and setVariableValue().

◆ HasName

unsigned llvm::MCSymbol::HasName
protected

True if this symbol is named.

A named symbol will have a pointer to the name allocated in the bytes immediately prior to the MCSymbol.

Definition at line 73 of file MCSymbol.h.

Referenced by getName(), and MCSymbol().

◆ Index

uint32_t llvm::MCSymbol::Index = 0
mutableprotected

Index field, for use by the object file implementation.

Definition at line 120 of file MCSymbol.h.

Referenced by getIndex(), and setIndex().

◆ IsExternal

unsigned llvm::MCSymbol::IsExternal
mutableprotected

◆ IsPrivateExtern

unsigned llvm::MCSymbol::IsPrivateExtern
mutableprotected

Mach-O specific: This symbol is private extern.

Definition at line 90 of file MCSymbol.h.

Referenced by llvm::MCSymbolMachO::isPrivateExtern(), and llvm::MCSymbolMachO::setPrivateExtern().

◆ IsRedefinable

unsigned llvm::MCSymbol::IsRedefinable
protected

True if this symbol can be redefined.

Definition at line 81 of file MCSymbol.h.

Referenced by isRedefinable(), redefineIfPossible(), and setRedefinable().

◆ IsRegistered

unsigned llvm::MCSymbol::IsRegistered
mutableprotected

Definition at line 83 of file MCSymbol.h.

Referenced by isRegistered(), and setIsRegistered().

◆ IsResolving

unsigned llvm::MCSymbol::IsResolving
protected

Used to detect cyclic dependency like a = a + 1 and a = b; b = a.

Definition at line 99 of file MCSymbol.h.

Referenced by isResolving(), and setIsResolving().

◆ IsTemporary

unsigned llvm::MCSymbol::IsTemporary
protected

IsTemporary - True if this is an assembler temporary label, which typically does not survive in the .o file's symbol table.

Usually "Lfoo" or ".foo".

Definition at line 78 of file MCSymbol.h.

Referenced by isTemporary().

◆ IsUsedInReloc

unsigned llvm::MCSymbol::IsUsedInReloc
mutableprotected

True if we have created a relocation that uses this symbol.

Definition at line 96 of file MCSymbol.h.

Referenced by isUsedInReloc(), and setUsedInReloc().

◆ IsWeakExternal

unsigned llvm::MCSymbol::IsWeakExternal
mutableprotected

This symbol is weak external.

Definition at line 93 of file MCSymbol.h.

Referenced by isWeakExternal(), and llvm::MCSymbolCOFF::setIsWeakExternal().

◆ kind

unsigned llvm::MCSymbol::kind
protected

The symbol kind.

Use an unsigned bitfield to achieve better bitpacking with MSVC.

Definition at line 69 of file MCSymbol.h.

Referenced by getOffset(), isCommon(), isVariable(), redefineIfPossible(), setCommon(), setOffset(), and setVariableValue().

◆ Offset

uint64_t llvm::MCSymbol::Offset

The offset to apply to the fragment address to form this symbol's value.

Definition at line 124 of file MCSymbol.h.

Referenced by getOffset(), MCSymbol(), and setOffset().

◆ Value

const MCExpr* llvm::MCSymbol::Value

The documentation for this class was generated from the following files: