LLVM  3.7.0
Classes | 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 <MCSymbol.h>

Inheritance diagram for llvm::MCSymbol:
[legend]
Collaboration diagram for llvm::MCSymbol:
[legend]

Classes

union  NameEntryStorageTy
 The name for a symbol. More...
 

Public Member Functions

StringRef getName () const
 getName - Get the symbol name. More...
 
bool isRegistered () const
 
void setIsRegistered (bool Value) const
 
void setUsedInReloc () const
 
bool isUsedInReloc () const
 
uint32_t getIndex () const
 Get the (implementation defined) index. More...
 
void setIndex (uint32_t Value) const
 Set the (implementation defined) index. More...
 
uint64_t getOffset () const
 
void setOffset (uint64_t Value)
 
uint64_t getCommonSize () const
 Return the size of a 'common' symbol. More...
 
void setCommon (uint64_t Size, unsigned Align)
 Mark this symbol as being 'common'. More...
 
unsigned getCommonAlignment () const
 Return the alignment of a 'common' symbol. More...
 
bool declareCommon (uint64_t Size, unsigned Align)
 Declare this symbol as being 'common'. More...
 
bool isCommon () const
 Is this a 'common' symbol. More...
 
MCFragmentgetFragment () const
 
void setFragment (MCFragment *Value) const
 
bool isExternal () const
 
void setExternal (bool Value) const
 
bool isPrivateExtern () const
 
void setPrivateExtern (bool Value)
 
void print (raw_ostream &OS, const MCAsmInfo *MAI) const
 print - Print the value to the stream OS. More...
 
void dump () const
 dump - Print the value to stderr. More...
 
Accessors
bool isTemporary () const
 isTemporary - Check if this is an assembler temporary symbol. More...
 
bool isUsed () const
 isUsed - Check if this is used. More...
 
void setUsed (bool Value) const
 
bool isRedefinable () const
 Check if this symbol is redefinable. More...
 
void setRedefinable (bool Value)
 Mark this symbol as redefinable. More...
 
void redefineIfPossible ()
 Prepare this symbol to be redefined. More...
 
Associated Sections
bool isDefined () const
 isDefined - Check if this symbol is defined (i.e., it has an address). More...
 
bool isInSection () const
 isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute). More...
 
bool isUndefined () const
 isUndefined - Check if this symbol undefined (i.e., implicitly defined). More...
 
bool isAbsolute () const
 isAbsolute - Check if this is an absolute symbol. More...
 
MCSectiongetSection () const
 Get the section associated with a defined, non-absolute symbol. More...
 
void setSection (MCSection &S)
 Mark the symbol as defined in the section S. More...
 
void setUndefined ()
 Mark the symbol as undefined. More...
 
bool isELF () const
 
bool isCOFF () const
 
bool isMachO () const
 
Variable Symbols
bool isVariable () const
 isVariable - Check if this is a variable symbol. More...
 
const MCExprgetVariableValue () const
 getVariableValue() - Get the value for variable symbols. More...
 
void setVariableValue (const MCExpr *Value)
 

Protected Types

enum  SymbolKind { SymbolKindUnset, SymbolKindCOFF, SymbolKindELF, SymbolKindMachO }
 The kind of the symbol. More...
 
enum  Contents : uint8_t { SymContentsUnset, SymContentsOffset, SymContentsVariable, SymContentsCommon }
 A symbol can contain an Offset, or Value, or be Common, but never more than one of these. More...
 
enum  : unsigned { NumCommonAlignmentBits = 5 }
 The alignment of the symbol, if it is 'common', or -1. 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...
 

Protected Member Functions

 MCSymbol (SymbolKind Kind, const StringMapEntry< bool > *Name, bool isTemporary)
 
void * operator new (size_t s, const StringMapEntry< bool > *Name, MCContext &Ctx)
 
uint32_t getFlags () const
 Get the (implementation defined) symbol flags. More...
 
void setFlags (uint32_t Value) const
 Set the (implementation defined) symbol flags. More...
 
void modifyFlags (uint32_t Value, uint32_t Mask) const
 Modify the flags via a mask. More...
 

Protected Attributes

PointerIntPair< PointerUnion
< MCSection *, MCFragment * >, 1 > 
SectionOrFragmentAndHasName
 If a symbol has a Fragment, the section is implied, so we only need one pointer. More...
 
unsigned IsTemporary: 1
 IsTemporary - True if this is an assembler temporary label, which typically does not survive in the .o file's symbol table. More...
 
unsigned IsRedefinable: 1
 True if this symbol can be redefined. More...
 
unsigned IsUsed: 1
 IsUsed - True if this symbol has been used. More...
 
bool IsRegistered: 1
 
unsigned IsExternal: 1
 This symbol is visible outside this translation unit. More...
 
unsigned IsPrivateExtern: 1
 This symbol is private extern. More...
 
unsigned Kind: 2
 LLVM RTTI discriminator. More...
 
unsigned IsUsedInReloc: 1
 True if we have created a relocation that uses this symbol. More...
 
unsigned SymbolContents: 2
 This is actually a Contents enumerator, but is unsigned to avoid sign extension and achieve better bitpacking with MSVC. More...
 
unsigned CommonAlignLog2: NumCommonAlignmentBits
 
uint32_t Flags: NumFlagsBits
 
uint32_t Index = 0
 Index field, for use by the object file implementation. More...
 
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...
 
}; 
 

Static Protected Attributes

static MCSectionAbsolutePseudoSection = reinterpret_cast<MCSection *>(1)
 

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 39 of file MCSymbol.h.

Member Enumeration Documentation

anonymous enum : unsigned
protected

The alignment of the symbol, if it is 'common', or -1.

The alignment is stored as log2(align) + 1. This allows all values from 0 to 2^31 to be stored which is every power of 2 representable by an unsigned.

Enumerator
NumCommonAlignmentBits 

Definition at line 117 of file MCSymbol.h.

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 122 of file MCSymbol.h.

enum llvm::MCSymbol::Contents : uint8_t
protected

A symbol can contain an Offset, or Value, or be Common, but never more than one of these.

Enumerator
SymContentsUnset 
SymContentsOffset 
SymContentsVariable 
SymContentsCommon 

Definition at line 52 of file MCSymbol.h.

The kind of the symbol.

If it is any value other than unset then this class is actually one of the appropriate subclasses of MCSymbol.

Enumerator
SymbolKindUnset 
SymbolKindCOFF 
SymbolKindELF 
SymbolKindMachO 

Definition at line 43 of file MCSymbol.h.

Constructor & Destructor Documentation

llvm::MCSymbol::MCSymbol ( SymbolKind  Kind,
const StringMapEntry< bool > *  Name,
bool  isTemporary 
)
inlineprotected

Definition at line 152 of file MCSymbol.h.

References Offset, and SectionOrFragmentAndHasName.

Member Function Documentation

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

Declare this symbol as being 'common'.

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

Definition at line 367 of file MCSymbol.h.

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

void MCSymbol::dump ( ) const

dump - Print the value to stderr.

Definition at line 77 of file MCSymbol.cpp.

References llvm::dbgs().

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

Return the alignment of a 'common' symbol.

Definition at line 357 of file MCSymbol.h.

References CommonAlignLog2, and isCommon().

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

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

Return the size of a 'common' symbol.

Definition at line 334 of file MCSymbol.h.

References CommonSize, and isCommon().

Referenced by getSymbolValue(), and llvm::MachObjectWriter::writeNlist().

uint32_t llvm::MCSymbol::getFlags ( ) const
inlineprotected
MCFragment* llvm::MCSymbol::getFragment ( ) const
inline
uint32_t llvm::MCSymbol::getIndex ( ) const
inline

Get the (implementation defined) index.

Definition at line 310 of file MCSymbol.h.

References Index.

Referenced by writeFragment().

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

getName - Get the symbol name.

Definition at line 205 of file MCSymbol.h.

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

Referenced by llvm::MachObjectWriter::bindIndirectSymbols(), llvm::MCWinCOFFStreamer::EmitCommonSymbol(), llvm::MipsTargetAsmStreamer::emitDirectiveCpsetup(), llvm::MipsTargetAsmStreamer::emitDirectiveEnt(), llvm::EHStreamer::emitExceptionTable(), llvm::MipsAsmPrinter::EmitFunctionBodyEnd(), llvm::AsmPrinter::EmitFunctionEntryLabel(), llvm::AsmPrinter::EmitGlobalVariable(), llvm::TargetLoweringObjectFileELF::emitPersonalityValue(), EvaluateCRExpr(), GetAnonSym(), llvm::MCContext::getAssociativeCOFFSection(), llvm::MCAsmLayout::getBaseSymbol(), llvm::TargetLoweringObjectFileELF::getCFIPersonalitySymbol(), llvm::MCContext::getCOFFSection(), llvm::MCContext::getELFSection(), llvm::MCSymbolMachO::getEncodedFlags(), llvm::TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(), llvm::TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(), getLabelOffset(), GetLazyPtr(), llvm::TargetLoweringObjectFileCOFF::getSectionForJumpTable(), getStaticStructorSection(), llvm::MachObjectWriter::getSymbolAddress(), getSymbolOffsetImpl(), hasGOTReference(), llvm::HexagonMCELFStreamer::HexagonMCEmitCommonSymbol(), llvm::MCGenDwarfLabelEntry::Make(), llvm::MCExpr::print(), llvm::DIELabel::print(), llvm::DIEDelta::print(), print(), llvm::MipsAsmPrinter::printOperand(), llvm::NVPTXInstPrinter::printProtoIdent(), llvm::MCSectionELF::PrintSwitchToSection(), printSymbolOperand(), llvm::PPCInstPrinter::printTLSCall(), llvm::TargetLoweringObjectFileCOFF::SelectSectionForGlobal(), SortSymbolPair(), StartsWithGlobalOffsetTable(), and llvm::MachObjectWriter::writeObject().

uint64_t llvm::MCSymbol::getOffset ( ) const
inline
MCSection& llvm::MCSymbol::getSection ( ) const
inline
const MCExpr* llvm::MCSymbol::getVariableValue ( ) const
inline
bool llvm::MCSymbol::isAbsolute ( ) const
inline

isAbsolute - Check if this is an absolute symbol.

Definition at line 261 of file MCSymbol.h.

References AbsolutePseudoSection.

Referenced by isInSection(), and llvm::MachObjectWriter::writeNlist().

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

Definition at line 285 of file MCSymbol.h.

References Kind, and SymbolKindCOFF.

Referenced by llvm::MCSymbolCOFF::classof().

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

Definition at line 283 of file MCSymbol.h.

References Kind, and SymbolKindELF.

Referenced by llvm::MCSymbolELF::classof().

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

Definition at line 389 of file MCSymbol.h.

References IsExternal.

Referenced by getSymbolValue(), and llvm::MachObjectWriter::writeNlist().

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

Definition at line 287 of file MCSymbol.h.

References Kind, and SymbolKindMachO.

Referenced by llvm::MCSymbolMachO::classof().

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

Definition at line 392 of file MCSymbol.h.

References IsPrivateExtern.

Referenced by llvm::MachObjectWriter::writeNlist().

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

Check if this symbol is redefinable.

Definition at line 229 of file MCSymbol.h.

References IsRedefinable.

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

Definition at line 212 of file MCSymbol.h.

References IsRegistered.

Referenced by llvm::MCAssembler::registerSymbol().

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

isTemporary - Check if this is an assembler temporary symbol.

Definition at line 222 of file MCSymbol.h.

References IsTemporary.

Referenced by llvm::MCAssembler::isSymbolLinkerVisible(), llvm::MachObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(), and llvm::MCGenDwarfLabelEntry::Make().

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

isUsed - Check if this is used.

Definition at line 225 of file MCSymbol.h.

References IsUsed.

Referenced by llvm::MCParserUtils::parseAssignmentExpression().

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

Definition at line 216 of file MCSymbol.h.

References IsUsedInReloc.

Referenced by llvm::MCSymbolELF::getBinding(), and llvm::MCAssembler::isSymbolLinkerVisible().

bool llvm::MCSymbol::isVariable ( ) const
inline
void llvm::MCSymbol::modifyFlags ( uint32_t  Value,
uint32_t  Mask 
) const
inlineprotected
void * MCSymbol::operator new ( size_t  s,
const StringMapEntry< bool > *  Name,
MCContext Ctx 
)
protected

Definition at line 22 of file MCSymbol.cpp.

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

Prepare this symbol to be redefined.

Definition at line 233 of file MCSymbol.h.

References IsRedefinable, setUndefined(), SymbolContents, SymContentsUnset, and SymContentsVariable.

Referenced by llvm::AsmPrinter::EmitFunctionEntryLabel(), and llvm::AsmPrinter::EmitGlobalVariable().

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

Mark this symbol as being 'common'.

Parameters
Size- The size of the symbol.
Align- The alignment of the symbol.

Definition at line 343 of file MCSymbol.h.

References CommonAlignLog2, CommonSize, getOffset(), llvm::isPowerOf2_32(), llvm::Log2_32(), NumCommonAlignmentBits, SymbolContents, and SymContentsCommon.

Referenced by declareCommon(), and llvm::MCWinCOFFStreamer::EmitCommonSymbol().

void llvm::MCSymbol::setExternal ( bool  Value) const
inline
void llvm::MCSymbol::setFlags ( uint32_t  Value) const
inlineprotected
void llvm::MCSymbol::setFragment ( MCFragment Value) const
inline
void llvm::MCSymbol::setIndex ( uint32_t  Value) const
inline

Set the (implementation defined) index.

Definition at line 315 of file MCSymbol.h.

References Index, and Value.

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

Definition at line 213 of file MCSymbol.h.

References IsRegistered, and Value.

Referenced by llvm::MCAssembler::registerSymbol().

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

Definition at line 325 of file MCSymbol.h.

References Offset, SymbolContents, SymContentsOffset, SymContentsUnset, and Value.

Referenced by llvm::MCObjectStreamer::EmitLabel().

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

Definition at line 393 of file MCSymbol.h.

References IsPrivateExtern, and Value.

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

Mark this symbol as redefinable.

Definition at line 231 of file MCSymbol.h.

References IsRedefinable, and Value.

Referenced by llvm::MCParserUtils::parseAssignmentExpression().

void llvm::MCSymbol::setSection ( MCSection S)
inline

Mark the symbol as defined in the section S.

Definition at line 270 of file MCSymbol.h.

References isVariable(), and SectionOrFragmentAndHasName.

Referenced by llvm::MCStreamer::AssignSection().

void llvm::MCSymbol::setUndefined ( )
inline

Mark the symbol as undefined.

Definition at line 278 of file MCSymbol.h.

References SectionOrFragmentAndHasName.

Referenced by llvm::MCStreamer::AssignSection(), redefineIfPossible(), and setVariableValue().

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

Definition at line 226 of file MCSymbol.h.

References IsUsed, and Value.

Referenced by llvm::MCParserUtils::parseAssignmentExpression().

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

Definition at line 215 of file MCSymbol.h.

References IsUsedInReloc.

void MCSymbol::setVariableValue ( const MCExpr Value)

Friends And Related Function Documentation

friend class MCContext
friend

Definition at line 141 of file MCSymbol.h.

friend class MCExpr
friend

Definition at line 140 of file MCSymbol.h.

Member Data Documentation

union { ... }
MCSection * MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1)
staticprotected

Definition at line 62 of file MCSymbol.h.

Referenced by llvm::MCExpr::findAssociatedSection(), and isAbsolute().

unsigned llvm::MCSymbol::CommonAlignLog2
protected

Definition at line 118 of file MCSymbol.h.

Referenced by getCommonAlignment(), and setCommon().

uint64_t llvm::MCSymbol::CommonSize

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

Definition at line 133 of file MCSymbol.h.

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

uint32_t llvm::MCSymbol::Flags
mutableprotected

Definition at line 123 of file MCSymbol.h.

Referenced by llvm::MCSymbolMachO::getEncodedFlags(), getFlags(), modifyFlags(), and setFlags().

uint32_t llvm::MCSymbol::Index = 0
mutableprotected

Index field, for use by the object file implementation.

Definition at line 126 of file MCSymbol.h.

Referenced by getIndex(), and setIndex().

unsigned llvm::MCSymbol::IsExternal
mutableprotected

This symbol is visible outside this translation unit.

Definition at line 96 of file MCSymbol.h.

Referenced by isExternal(), and setExternal().

unsigned llvm::MCSymbol::IsPrivateExtern
mutableprotected

This symbol is private extern.

Definition at line 99 of file MCSymbol.h.

Referenced by isPrivateExtern(), and setPrivateExtern().

unsigned llvm::MCSymbol::IsRedefinable
protected

True if this symbol can be redefined.

Definition at line 88 of file MCSymbol.h.

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

bool llvm::MCSymbol::IsRegistered
mutableprotected

Definition at line 93 of file MCSymbol.h.

Referenced by isRegistered(), and setIsRegistered().

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 85 of file MCSymbol.h.

Referenced by isTemporary().

unsigned llvm::MCSymbol::IsUsed
mutableprotected

IsUsed - True if this symbol has been used.

Definition at line 91 of file MCSymbol.h.

Referenced by getVariableValue(), isUsed(), setUsed(), and setVariableValue().

unsigned llvm::MCSymbol::IsUsedInReloc
mutableprotected

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

Definition at line 106 of file MCSymbol.h.

Referenced by isUsedInReloc(), and setUsedInReloc().

unsigned llvm::MCSymbol::Kind
protected

LLVM RTTI discriminator.

This is actually a SymbolKind enumerator, but is unsigned to avoid sign extension and achieve better bitpacking with MSVC.

Definition at line 103 of file MCSymbol.h.

Referenced by isCOFF(), isELF(), and isMachO().

uint64_t llvm::MCSymbol::Offset

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

Definition at line 130 of file MCSymbol.h.

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

PointerIntPair<PointerUnion<MCSection *, MCFragment *>, 1> llvm::MCSymbol::SectionOrFragmentAndHasName
mutableprotected

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

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, and the special AbsolutePseudoSection value for absolute symbols. If this is a variable symbol, this caches the variable value's section.

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

For the 'HasName' integer, this is 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 80 of file MCSymbol.h.

Referenced by getFragment(), getName(), MCSymbol(), setFragment(), setSection(), and setUndefined().

unsigned llvm::MCSymbol::SymbolContents
protected

This is actually a Contents enumerator, but is unsigned to avoid sign extension and achieve better bitpacking with MSVC.

Definition at line 110 of file MCSymbol.h.

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

const MCExpr* llvm::MCSymbol::Value

If non-null, the value for a variable symbol.

Definition at line 136 of file MCSymbol.h.

Referenced by getVariableValue(), setExternal(), setFlags(), setIndex(), setIsRegistered(), setOffset(), setPrivateExtern(), setRedefinable(), setUsed(), and setVariableValue().


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