2006-09-06 19:21:41 +00:00
|
|
|
//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
|
2006-09-06 18:35:33 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-09-06 18:35:33 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines target asm properties related what form asm statements
|
|
|
|
// should take.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-06-28 13:45:57 +00:00
|
|
|
#include "llvm/Constants.h"
|
2009-01-27 22:29:24 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-06-28 13:45:57 +00:00
|
|
|
#include "llvm/GlobalVariable.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Type.h"
|
2006-09-06 18:35:33 +00:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2009-03-29 17:13:49 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-06-28 13:45:57 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2008-02-27 23:33:50 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2007-04-23 20:00:17 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstring>
|
2006-09-06 18:35:33 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2008-09-25 21:00:33 +00:00
|
|
|
void TargetAsmInfo::fillDefaultValues() {
|
|
|
|
BSSSection = "\t.bss";
|
|
|
|
BSSSection_ = 0;
|
|
|
|
ReadOnlySection = 0;
|
|
|
|
SmallDataSection = 0;
|
|
|
|
SmallBSSSection = 0;
|
|
|
|
SmallRODataSection = 0;
|
|
|
|
TLSDataSection = 0;
|
|
|
|
TLSBSSSection = 0;
|
|
|
|
ZeroFillDirective = 0;
|
|
|
|
NonexecutableStackDirective = 0;
|
|
|
|
NeedsSet = false;
|
|
|
|
MaxInstLength = 4;
|
|
|
|
PCSymbol = "$";
|
|
|
|
SeparatorChar = ';';
|
|
|
|
CommentString = "#";
|
|
|
|
GlobalPrefix = "";
|
|
|
|
PrivateGlobalPrefix = ".";
|
|
|
|
LessPrivateGlobalPrefix = "";
|
|
|
|
JumpTableSpecialLabelPrefix = 0;
|
|
|
|
GlobalVarAddrPrefix = "";
|
|
|
|
GlobalVarAddrSuffix = "";
|
|
|
|
FunctionAddrPrefix = "";
|
|
|
|
FunctionAddrSuffix = "";
|
|
|
|
PersonalityPrefix = "";
|
|
|
|
PersonalitySuffix = "";
|
|
|
|
NeedsIndirectEncoding = false;
|
|
|
|
InlineAsmStart = "#APP";
|
|
|
|
InlineAsmEnd = "#NO_APP";
|
|
|
|
AssemblerDialect = 0;
|
|
|
|
StringConstantPrefix = ".str";
|
|
|
|
ZeroDirective = "\t.zero\t";
|
|
|
|
ZeroDirectiveSuffix = 0;
|
|
|
|
AsciiDirective = "\t.ascii\t";
|
|
|
|
AscizDirective = "\t.asciz\t";
|
|
|
|
Data8bitsDirective = "\t.byte\t";
|
|
|
|
Data16bitsDirective = "\t.short\t";
|
|
|
|
Data32bitsDirective = "\t.long\t";
|
|
|
|
Data64bitsDirective = "\t.quad\t";
|
|
|
|
AlignDirective = "\t.align\t";
|
|
|
|
AlignmentIsInBytes = true;
|
|
|
|
TextAlignFillValue = 0;
|
|
|
|
SwitchToSectionDirective = "\t.section\t";
|
|
|
|
TextSectionStartSuffix = "";
|
|
|
|
DataSectionStartSuffix = "";
|
|
|
|
SectionEndDirectiveSuffix = 0;
|
|
|
|
ConstantPoolSection = "\t.section .rodata";
|
|
|
|
JumpTableDataSection = "\t.section .rodata";
|
|
|
|
JumpTableDirective = 0;
|
|
|
|
CStringSection = 0;
|
|
|
|
CStringSection_ = 0;
|
|
|
|
// FIXME: Flags are ELFish - replace with normal section stuff.
|
|
|
|
StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
|
|
|
|
StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
|
|
|
|
GlobalDirective = "\t.globl\t";
|
|
|
|
SetDirective = 0;
|
|
|
|
LCOMMDirective = 0;
|
|
|
|
COMMDirective = "\t.comm\t";
|
|
|
|
COMMDirectiveTakesAlignment = true;
|
|
|
|
HasDotTypeDotSizeDirective = true;
|
2008-12-03 11:01:37 +00:00
|
|
|
HasSingleParameterDotFile = true;
|
2008-09-25 21:00:33 +00:00
|
|
|
UsedDirective = 0;
|
|
|
|
WeakRefDirective = 0;
|
|
|
|
WeakDefDirective = 0;
|
|
|
|
// FIXME: These are ELFish - move to ELFTAI.
|
|
|
|
HiddenDirective = "\t.hidden\t";
|
|
|
|
ProtectedDirective = "\t.protected\t";
|
|
|
|
AbsoluteDebugSectionOffsets = false;
|
|
|
|
AbsoluteEHSectionOffsets = false;
|
|
|
|
HasLEB128 = false;
|
|
|
|
HasDotLocAndDotFile = false;
|
|
|
|
SupportsDebugInformation = false;
|
|
|
|
SupportsExceptionHandling = false;
|
|
|
|
DwarfRequiresFrameSection = true;
|
2009-04-13 17:02:03 +00:00
|
|
|
DwarfUsesInlineInfoSection = false;
|
2009-01-26 22:32:51 +00:00
|
|
|
SupportsMacInfoSection = true;
|
2008-12-24 08:05:17 +00:00
|
|
|
NonLocalEHFrameLabel = false;
|
2008-09-25 21:00:33 +00:00
|
|
|
GlobalEHDirective = 0;
|
|
|
|
SupportsWeakOmittedEHFrame = true;
|
|
|
|
DwarfSectionOffsetDirective = 0;
|
|
|
|
DwarfAbbrevSection = ".debug_abbrev";
|
|
|
|
DwarfInfoSection = ".debug_info";
|
|
|
|
DwarfLineSection = ".debug_line";
|
|
|
|
DwarfFrameSection = ".debug_frame";
|
|
|
|
DwarfPubNamesSection = ".debug_pubnames";
|
|
|
|
DwarfPubTypesSection = ".debug_pubtypes";
|
2009-04-13 17:02:03 +00:00
|
|
|
DwarfDebugInlineSection = ".debug_inlined";
|
2008-09-25 21:00:33 +00:00
|
|
|
DwarfStrSection = ".debug_str";
|
|
|
|
DwarfLocSection = ".debug_loc";
|
|
|
|
DwarfARangesSection = ".debug_aranges";
|
|
|
|
DwarfRangesSection = ".debug_ranges";
|
|
|
|
DwarfMacInfoSection = ".debug_macinfo";
|
|
|
|
DwarfEHFrameSection = ".eh_frame";
|
|
|
|
DwarfExceptionSection = ".gcc_except_table";
|
|
|
|
AsmTransCBE = 0;
|
2008-09-24 22:15:21 +00:00
|
|
|
TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
|
2008-09-24 22:16:16 +00:00
|
|
|
DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
|
2006-10-13 17:50:07 +00:00
|
|
|
}
|
2006-10-05 00:35:16 +00:00
|
|
|
|
2009-03-30 15:27:03 +00:00
|
|
|
TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
|
2008-11-03 18:22:42 +00:00
|
|
|
: TM(tm) {
|
2008-09-25 21:00:33 +00:00
|
|
|
fillDefaultValues();
|
|
|
|
}
|
|
|
|
|
2006-10-05 00:35:16 +00:00
|
|
|
TargetAsmInfo::~TargetAsmInfo() {
|
|
|
|
}
|
2006-10-13 17:50:07 +00:00
|
|
|
|
|
|
|
/// Measure the specified inline asm to determine an approximation of its
|
|
|
|
/// length.
|
2007-04-23 20:00:17 +00:00
|
|
|
/// Comments (which run till the next SeparatorChar or newline) do not
|
|
|
|
/// count as an instruction.
|
|
|
|
/// Any other non-whitespace text is considered an instruction, with
|
|
|
|
/// multiple instructions separated by SeparatorChar or newlines.
|
|
|
|
/// Variable-length instructions are not handled here; this function
|
|
|
|
/// may be overloaded in the target code to do that.
|
2006-10-13 17:50:07 +00:00
|
|
|
unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
|
|
|
|
// Count the number of instructions in the asm.
|
2007-04-23 20:00:17 +00:00
|
|
|
bool atInsnStart = true;
|
|
|
|
unsigned Length = 0;
|
2006-10-13 17:50:07 +00:00
|
|
|
for (; *Str; ++Str) {
|
|
|
|
if (*Str == '\n' || *Str == SeparatorChar)
|
2007-04-23 20:00:17 +00:00
|
|
|
atInsnStart = true;
|
|
|
|
if (atInsnStart && !isspace(*Str)) {
|
|
|
|
Length += MaxInstLength;
|
|
|
|
atInsnStart = false;
|
|
|
|
}
|
|
|
|
if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
|
|
|
|
atInsnStart = false;
|
2006-10-13 17:50:07 +00:00
|
|
|
}
|
|
|
|
|
2007-04-23 20:00:17 +00:00
|
|
|
return Length;
|
2006-10-13 17:50:07 +00:00
|
|
|
}
|
2007-03-07 02:47:57 +00:00
|
|
|
|
2008-02-29 22:09:08 +00:00
|
|
|
unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
|
2008-02-27 23:33:50 +00:00
|
|
|
bool Global) const {
|
|
|
|
return dwarf::DW_EH_PE_absptr;
|
|
|
|
}
|
|
|
|
|
2008-06-28 13:45:57 +00:00
|
|
|
static bool isSuitableForBSS(const GlobalVariable *GV) {
|
|
|
|
if (!GV->hasInitializer())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Leave constant zeros in readonly constant sections, so they can be shared
|
|
|
|
Constant *C = GV->getInitializer();
|
|
|
|
return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
|
|
|
|
}
|
|
|
|
|
2009-01-27 22:29:24 +00:00
|
|
|
static bool isConstantString(const Constant *C) {
|
|
|
|
// First check: is we have constant array of i8 terminated with zero
|
|
|
|
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
|
|
|
// Check, if initializer is a null-terminated string
|
|
|
|
if (CVA && CVA->isCString())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Another possibility: [1 x i8] zeroinitializer
|
|
|
|
if (isa<ConstantAggregateZero>(C)) {
|
|
|
|
if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
|
|
|
|
return (Ty->getElementType() == Type::Int8Ty &&
|
|
|
|
Ty->getNumElements() == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-29 17:13:49 +00:00
|
|
|
unsigned TargetAsmInfo::RelocBehaviour() const {
|
|
|
|
// By default - all relocations in PIC mode would force symbol to be
|
|
|
|
// placed in r/w section.
|
|
|
|
return (TM.getRelocationModel() != Reloc::Static ?
|
|
|
|
Reloc::LocalOrGlobal : Reloc::None);
|
|
|
|
}
|
2009-01-27 22:29:24 +00:00
|
|
|
|
2008-06-28 13:45:57 +00:00
|
|
|
SectionKind::Kind
|
|
|
|
TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
|
|
|
|
// Early exit - functions should be always in text sections.
|
|
|
|
if (isa<Function>(GV))
|
|
|
|
return SectionKind::Text;
|
|
|
|
|
|
|
|
const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
|
|
|
|
bool isThreadLocal = GVar->isThreadLocal();
|
|
|
|
assert(GVar && "Invalid global value for section selection");
|
|
|
|
|
|
|
|
if (isSuitableForBSS(GVar)) {
|
|
|
|
// Variable can be easily put to BSS section.
|
|
|
|
return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
|
|
|
|
} else if (GVar->isConstant() && !isThreadLocal) {
|
|
|
|
// Now we know, that varible has initializer and it is constant. We need to
|
|
|
|
// check its initializer to decide, which section to output it into. Also
|
|
|
|
// note, there is no thread-local r/o section.
|
|
|
|
Constant *C = GVar->getInitializer();
|
2009-03-29 17:13:49 +00:00
|
|
|
if (C->ContainsRelocations(Reloc::LocalOrGlobal)) {
|
|
|
|
// Decide, whether it is still possible to put symbol into r/o section.
|
|
|
|
unsigned Reloc = RelocBehaviour();
|
|
|
|
|
|
|
|
// We already did a query for 'all' relocs, thus - early exits.
|
2009-03-30 15:27:43 +00:00
|
|
|
if (Reloc == Reloc::LocalOrGlobal)
|
|
|
|
return SectionKind::Data;
|
|
|
|
else if (Reloc == Reloc::None)
|
2009-03-29 17:13:49 +00:00
|
|
|
return SectionKind::ROData;
|
|
|
|
else {
|
|
|
|
// Ok, target wants something funny. Honour it.
|
2009-03-30 15:27:43 +00:00
|
|
|
return (C->ContainsRelocations(Reloc) ?
|
|
|
|
SectionKind::Data : SectionKind::ROData);
|
2009-03-29 17:13:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-28 13:45:57 +00:00
|
|
|
// Check, if initializer is a null-terminated string
|
2009-01-27 22:29:24 +00:00
|
|
|
if (isConstantString(C))
|
2008-07-09 13:24:38 +00:00
|
|
|
return SectionKind::RODataMergeStr;
|
2008-06-28 13:45:57 +00:00
|
|
|
else
|
2008-07-09 13:24:38 +00:00
|
|
|
return SectionKind::RODataMergeConst;
|
2008-06-28 13:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-30 15:27:03 +00:00
|
|
|
// Variable either is not constant or thread-local - output to data section.
|
2009-03-30 15:27:43 +00:00
|
|
|
return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
|
2008-06-28 13:45:57 +00:00
|
|
|
}
|
2008-07-09 13:16:59 +00:00
|
|
|
|
|
|
|
unsigned
|
|
|
|
TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
2008-07-09 13:25:26 +00:00
|
|
|
const char* Name) const {
|
|
|
|
unsigned Flags = SectionFlags::None;
|
2008-07-09 13:16:59 +00:00
|
|
|
|
|
|
|
// Decode flags from global itself.
|
|
|
|
if (GV) {
|
2008-07-09 13:25:26 +00:00
|
|
|
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
|
|
|
switch (Kind) {
|
2008-07-09 13:16:59 +00:00
|
|
|
case SectionKind::Text:
|
2008-07-09 13:25:26 +00:00
|
|
|
Flags |= SectionFlags::Code;
|
2008-07-09 13:16:59 +00:00
|
|
|
break;
|
|
|
|
case SectionKind::ThreadData:
|
|
|
|
case SectionKind::ThreadBSS:
|
2008-07-09 13:25:26 +00:00
|
|
|
Flags |= SectionFlags::TLS;
|
2008-07-09 13:16:59 +00:00
|
|
|
// FALLS THROUGH
|
2008-07-09 13:29:44 +00:00
|
|
|
case SectionKind::Data:
|
2009-03-30 15:27:03 +00:00
|
|
|
case SectionKind::DataRel:
|
|
|
|
case SectionKind::DataRelLocal:
|
|
|
|
case SectionKind::DataRelRO:
|
|
|
|
case SectionKind::DataRelROLocal:
|
2008-07-09 13:16:59 +00:00
|
|
|
case SectionKind::BSS:
|
2008-07-09 13:29:44 +00:00
|
|
|
Flags |= SectionFlags::Writeable;
|
2008-07-09 13:16:59 +00:00
|
|
|
break;
|
|
|
|
case SectionKind::ROData:
|
|
|
|
case SectionKind::RODataMergeStr:
|
|
|
|
case SectionKind::RODataMergeConst:
|
2008-07-09 13:29:44 +00:00
|
|
|
// No additional flags here
|
2008-07-09 13:16:59 +00:00
|
|
|
break;
|
2008-07-22 17:09:59 +00:00
|
|
|
case SectionKind::SmallData:
|
|
|
|
case SectionKind::SmallBSS:
|
|
|
|
Flags |= SectionFlags::Writeable;
|
|
|
|
// FALLS THROUGH
|
|
|
|
case SectionKind::SmallROData:
|
|
|
|
Flags |= SectionFlags::Small;
|
|
|
|
break;
|
2008-07-09 13:16:59 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unexpected section kind!");
|
|
|
|
}
|
|
|
|
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
if (GV->isWeakForLinker())
|
2008-07-09 13:25:26 +00:00
|
|
|
Flags |= SectionFlags::Linkonce;
|
2008-07-09 13:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add flags from sections, if any.
|
2008-07-09 13:25:46 +00:00
|
|
|
if (Name && *Name) {
|
2008-07-09 13:25:26 +00:00
|
|
|
Flags |= SectionFlags::Named;
|
|
|
|
|
|
|
|
// Some lame default implementation based on some magic section names.
|
|
|
|
if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
|
2008-07-22 17:09:59 +00:00
|
|
|
strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
|
|
|
|
strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
|
|
|
|
strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
|
2008-07-09 13:25:26 +00:00
|
|
|
Flags |= SectionFlags::BSS;
|
|
|
|
else if (strcmp(Name, ".tdata") == 0 ||
|
|
|
|
strncmp(Name, ".tdata.", 7) == 0 ||
|
|
|
|
strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
|
|
|
|
strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
|
|
|
|
Flags |= SectionFlags::TLS;
|
|
|
|
else if (strcmp(Name, ".tbss") == 0 ||
|
|
|
|
strncmp(Name, ".tbss.", 6) == 0 ||
|
|
|
|
strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
|
|
|
|
strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
|
|
|
|
Flags |= SectionFlags::BSS | SectionFlags::TLS;
|
2008-07-09 13:16:59 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 13:25:26 +00:00
|
|
|
return Flags;
|
2008-07-09 13:16:59 +00:00
|
|
|
}
|
2008-07-09 13:18:02 +00:00
|
|
|
|
2008-09-24 22:14:23 +00:00
|
|
|
const Section*
|
2008-08-08 17:56:50 +00:00
|
|
|
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
|
2008-07-09 13:28:49 +00:00
|
|
|
const Section* S;
|
2008-07-09 13:22:46 +00:00
|
|
|
// Select section name
|
|
|
|
if (GV->hasSection()) {
|
|
|
|
// Honour section already set, if any
|
2008-07-09 13:28:49 +00:00
|
|
|
unsigned Flags = SectionFlagsForGlobal(GV,
|
|
|
|
GV->getSection().c_str());
|
|
|
|
S = getNamedSection(GV->getSection().c_str(), Flags);
|
2008-07-09 13:22:46 +00:00
|
|
|
} else {
|
|
|
|
// Use default section depending on the 'type' of global
|
2008-08-08 17:56:50 +00:00
|
|
|
S = SelectSectionForGlobal(GV);
|
2008-07-09 13:22:46 +00:00
|
|
|
}
|
|
|
|
|
2008-09-24 22:14:23 +00:00
|
|
|
return S;
|
2008-07-09 13:22:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lame default implementation. Calculate the section name for global.
|
2008-08-08 17:56:50 +00:00
|
|
|
const Section*
|
|
|
|
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
2008-07-09 13:25:26 +00:00
|
|
|
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
2008-07-09 13:18:02 +00:00
|
|
|
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
if (GV->isWeakForLinker()) {
|
2008-07-09 13:28:49 +00:00
|
|
|
std::string Name = UniqueSectionForGlobal(GV, Kind);
|
|
|
|
unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
|
|
|
|
return getNamedSection(Name.c_str(), Flags);
|
|
|
|
} else {
|
2008-07-09 13:25:26 +00:00
|
|
|
if (Kind == SectionKind::Text)
|
2008-09-24 22:15:21 +00:00
|
|
|
return getTextSection();
|
2008-08-07 09:51:54 +00:00
|
|
|
else if (isBSS(Kind) && getBSSSection_())
|
2008-07-09 13:28:49 +00:00
|
|
|
return getBSSSection_();
|
2008-09-24 22:20:27 +00:00
|
|
|
else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
|
|
|
|
return getReadOnlySection();
|
2008-07-09 13:22:46 +00:00
|
|
|
}
|
2008-07-09 13:18:02 +00:00
|
|
|
|
2008-09-24 22:16:16 +00:00
|
|
|
return getDataSection();
|
2008-07-09 13:18:02 +00:00
|
|
|
}
|
2008-07-09 13:19:38 +00:00
|
|
|
|
2008-08-07 09:50:34 +00:00
|
|
|
// Lame default implementation. Calculate the section name for machine const.
|
|
|
|
const Section*
|
|
|
|
TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
|
|
|
|
// FIXME: Support data.rel stuff someday
|
2008-09-24 22:16:16 +00:00
|
|
|
return getDataSection();
|
2008-08-07 09:50:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 13:19:38 +00:00
|
|
|
std::string
|
|
|
|
TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
|
2008-07-09 13:25:26 +00:00
|
|
|
SectionKind::Kind Kind) const {
|
|
|
|
switch (Kind) {
|
2008-07-09 13:19:38 +00:00
|
|
|
case SectionKind::Text:
|
2008-07-09 13:24:55 +00:00
|
|
|
return ".gnu.linkonce.t." + GV->getName();
|
2008-07-09 13:19:38 +00:00
|
|
|
case SectionKind::Data:
|
2008-07-09 13:24:55 +00:00
|
|
|
return ".gnu.linkonce.d." + GV->getName();
|
2009-03-30 15:27:03 +00:00
|
|
|
case SectionKind::DataRel:
|
|
|
|
return ".gnu.linkonce.d.rel" + GV->getName();
|
|
|
|
case SectionKind::DataRelLocal:
|
|
|
|
return ".gnu.linkonce.d.rel.local" + GV->getName();
|
|
|
|
case SectionKind::DataRelRO:
|
|
|
|
return ".gnu.linkonce.d.rel.ro" + GV->getName();
|
|
|
|
case SectionKind::DataRelROLocal:
|
|
|
|
return ".gnu.linkonce.d.rel.ro.local" + GV->getName();
|
2008-07-22 17:09:59 +00:00
|
|
|
case SectionKind::SmallData:
|
|
|
|
return ".gnu.linkonce.s." + GV->getName();
|
2008-07-09 13:19:38 +00:00
|
|
|
case SectionKind::BSS:
|
2008-07-09 13:24:55 +00:00
|
|
|
return ".gnu.linkonce.b." + GV->getName();
|
2008-07-22 17:09:59 +00:00
|
|
|
case SectionKind::SmallBSS:
|
|
|
|
return ".gnu.linkonce.sb." + GV->getName();
|
2008-07-09 13:19:38 +00:00
|
|
|
case SectionKind::ROData:
|
|
|
|
case SectionKind::RODataMergeConst:
|
|
|
|
case SectionKind::RODataMergeStr:
|
2008-07-09 13:24:55 +00:00
|
|
|
return ".gnu.linkonce.r." + GV->getName();
|
2008-07-22 17:09:59 +00:00
|
|
|
case SectionKind::SmallROData:
|
|
|
|
return ".gnu.linkonce.s2." + GV->getName();
|
2008-07-09 13:19:38 +00:00
|
|
|
case SectionKind::ThreadData:
|
2008-07-09 13:24:55 +00:00
|
|
|
return ".gnu.linkonce.td." + GV->getName();
|
2008-07-09 13:19:38 +00:00
|
|
|
case SectionKind::ThreadBSS:
|
2008-07-09 13:24:55 +00:00
|
|
|
return ".gnu.linkonce.tb." + GV->getName();
|
2008-07-09 13:19:38 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unknown section kind");
|
|
|
|
}
|
2009-01-05 17:31:22 +00:00
|
|
|
return NULL;
|
2008-07-09 13:19:38 +00:00
|
|
|
}
|
2008-07-09 13:28:49 +00:00
|
|
|
|
|
|
|
const Section*
|
2008-08-16 12:58:12 +00:00
|
|
|
TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
|
|
|
|
bool Override) const {
|
2008-07-09 13:28:49 +00:00
|
|
|
Section& S = Sections[Name];
|
|
|
|
|
|
|
|
// This is newly-created section, set it up properly.
|
2008-08-16 12:58:12 +00:00
|
|
|
if (S.Flags == SectionFlags::Invalid || Override) {
|
2008-07-09 13:28:49 +00:00
|
|
|
S.Flags = Flags | SectionFlags::Named;
|
|
|
|
S.Name = Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &S;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Section*
|
2008-08-16 12:58:12 +00:00
|
|
|
TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
|
|
|
|
bool Override) const {
|
2008-07-09 13:28:49 +00:00
|
|
|
Section& S = Sections[Directive];
|
|
|
|
|
|
|
|
// This is newly-created section, set it up properly.
|
2008-08-16 12:58:12 +00:00
|
|
|
if (S.Flags == SectionFlags::Invalid || Override) {
|
2008-07-09 13:28:49 +00:00
|
|
|
S.Flags = Flags & ~SectionFlags::Named;
|
|
|
|
S.Name = Directive;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &S;
|
|
|
|
}
|
2008-08-16 12:57:07 +00:00
|
|
|
|
|
|
|
const std::string&
|
|
|
|
TargetAsmInfo::getSectionFlags(unsigned Flags) const {
|
|
|
|
SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
|
|
|
|
|
|
|
|
// We didn't print these flags yet, print and save them to map. This reduces
|
|
|
|
// amount of heap trashing due to std::string construction / concatenation.
|
|
|
|
if (I == FlagsStrings.end())
|
|
|
|
I = FlagsStrings.insert(std::make_pair(Flags,
|
|
|
|
printSectionFlags(Flags))).first;
|
|
|
|
|
|
|
|
return I->second;
|
|
|
|
}
|
2008-08-16 12:57:46 +00:00
|
|
|
|
|
|
|
unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
|
|
|
|
unsigned Size = 0;
|
|
|
|
do {
|
|
|
|
Value >>= 7;
|
|
|
|
Size += sizeof(int8_t);
|
|
|
|
} while (Value);
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned TargetAsmInfo::getSLEB128Size(int Value) {
|
|
|
|
unsigned Size = 0;
|
|
|
|
int Sign = Value >> (8 * sizeof(Value) - 1);
|
|
|
|
bool IsMore;
|
|
|
|
|
|
|
|
do {
|
|
|
|
unsigned Byte = Value & 0x7f;
|
|
|
|
Value >>= 7;
|
|
|
|
IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
|
|
|
|
Size += sizeof(int8_t);
|
|
|
|
} while (IsMore);
|
|
|
|
return Size;
|
|
|
|
}
|