2006-09-06 21:21:41 +02:00
|
|
|
//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
|
2006-09-06 20:35:33 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-09-06 20:35:33 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines target asm properties related what form asm statements
|
|
|
|
// should take.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-06-28 15:45:57 +02:00
|
|
|
#include "llvm/Constants.h"
|
2009-01-27 23:29:24 +01:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-06-28 15:45:57 +02:00
|
|
|
#include "llvm/GlobalVariable.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Type.h"
|
2006-09-06 20:35:33 +02:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2009-03-29 19:13:49 +02:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-06-28 15:45:57 +02:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2008-02-28 00:33:50 +01:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2007-04-23 22:00:17 +02:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstring>
|
2006-09-06 20:35:33 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-06-19 02:08:39 +02:00
|
|
|
TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
|
|
|
|
: TM(tm) {
|
2008-09-25 23:00:33 +02:00
|
|
|
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 = ';';
|
2009-07-13 22:25:48 +02:00
|
|
|
CommentColumn = 60;
|
2008-09-25 23:00:33 +02:00
|
|
|
CommentString = "#";
|
|
|
|
GlobalPrefix = "";
|
|
|
|
PrivateGlobalPrefix = ".";
|
|
|
|
LessPrivateGlobalPrefix = "";
|
|
|
|
JumpTableSpecialLabelPrefix = 0;
|
|
|
|
GlobalVarAddrPrefix = "";
|
|
|
|
GlobalVarAddrSuffix = "";
|
|
|
|
FunctionAddrPrefix = "";
|
|
|
|
FunctionAddrSuffix = "";
|
|
|
|
PersonalityPrefix = "";
|
|
|
|
PersonalitySuffix = "";
|
|
|
|
NeedsIndirectEncoding = false;
|
|
|
|
InlineAsmStart = "#APP";
|
|
|
|
InlineAsmEnd = "#NO_APP";
|
|
|
|
AssemblerDialect = 0;
|
2009-06-19 01:41:35 +02:00
|
|
|
AllowQuotesInName = false;
|
2008-09-25 23:00:33 +02:00
|
|
|
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 12:01:37 +01:00
|
|
|
HasSingleParameterDotFile = true;
|
2008-09-25 23:00:33 +02: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 19:02:03 +02:00
|
|
|
DwarfUsesInlineInfoSection = false;
|
2008-12-24 09:05:17 +01:00
|
|
|
NonLocalEHFrameLabel = false;
|
2008-09-25 23:00:33 +02: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 19:02:03 +02:00
|
|
|
DwarfDebugInlineSection = ".debug_inlined";
|
2008-09-25 23:00:33 +02:00
|
|
|
DwarfStrSection = ".debug_str";
|
|
|
|
DwarfLocSection = ".debug_loc";
|
|
|
|
DwarfARangesSection = ".debug_aranges";
|
|
|
|
DwarfRangesSection = ".debug_ranges";
|
2009-06-19 01:31:37 +02:00
|
|
|
DwarfMacroInfoSection = ".debug_macinfo";
|
2008-09-25 23:00:33 +02:00
|
|
|
DwarfEHFrameSection = ".eh_frame";
|
|
|
|
DwarfExceptionSection = ".gcc_except_table";
|
|
|
|
AsmTransCBE = 0;
|
2008-09-25 00:15:21 +02:00
|
|
|
TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
|
2008-09-25 00:16:16 +02:00
|
|
|
DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
|
2006-10-13 19:50:07 +02:00
|
|
|
}
|
2006-10-05 02:35:16 +02:00
|
|
|
|
|
|
|
TargetAsmInfo::~TargetAsmInfo() {
|
|
|
|
}
|
2006-10-13 19:50:07 +02:00
|
|
|
|
|
|
|
/// Measure the specified inline asm to determine an approximation of its
|
|
|
|
/// length.
|
2007-04-23 22:00:17 +02: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 19:50:07 +02:00
|
|
|
unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
|
|
|
|
// Count the number of instructions in the asm.
|
2007-04-23 22:00:17 +02:00
|
|
|
bool atInsnStart = true;
|
|
|
|
unsigned Length = 0;
|
2006-10-13 19:50:07 +02:00
|
|
|
for (; *Str; ++Str) {
|
|
|
|
if (*Str == '\n' || *Str == SeparatorChar)
|
2007-04-23 22:00:17 +02:00
|
|
|
atInsnStart = true;
|
|
|
|
if (atInsnStart && !isspace(*Str)) {
|
|
|
|
Length += MaxInstLength;
|
|
|
|
atInsnStart = false;
|
|
|
|
}
|
|
|
|
if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
|
|
|
|
atInsnStart = false;
|
2006-10-13 19:50:07 +02:00
|
|
|
}
|
|
|
|
|
2007-04-23 22:00:17 +02:00
|
|
|
return Length;
|
2006-10-13 19:50:07 +02:00
|
|
|
}
|
2007-03-07 03:47:57 +01:00
|
|
|
|
2008-02-29 23:09:08 +01:00
|
|
|
unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
|
2008-02-28 00:33:50 +01:00
|
|
|
bool Global) const {
|
|
|
|
return dwarf::DW_EH_PE_absptr;
|
|
|
|
}
|
|
|
|
|
2008-06-28 15:45:57 +02: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-07-13 23:27:19 +02:00
|
|
|
static bool isConstantString(const Constant *C) {
|
2009-01-27 23:29:24 +01:00
|
|
|
// 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
|
2009-07-13 23:27:19 +02:00
|
|
|
if (CVA && CVA->isCString())
|
2009-01-27 23:29:24 +01:00
|
|
|
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 19:13:49 +02: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 23:29:24 +01:00
|
|
|
|
2008-06-28 15:45:57 +02: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 19:13:49 +02: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 17:27:43 +02:00
|
|
|
if (Reloc == Reloc::LocalOrGlobal)
|
|
|
|
return SectionKind::Data;
|
|
|
|
else if (Reloc == Reloc::None)
|
2009-03-29 19:13:49 +02:00
|
|
|
return SectionKind::ROData;
|
|
|
|
else {
|
|
|
|
// Ok, target wants something funny. Honour it.
|
2009-03-30 17:27:43 +02:00
|
|
|
return (C->ContainsRelocations(Reloc) ?
|
|
|
|
SectionKind::Data : SectionKind::ROData);
|
2009-03-29 19:13:49 +02:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-28 15:45:57 +02:00
|
|
|
// Check, if initializer is a null-terminated string
|
2009-07-13 23:27:19 +02:00
|
|
|
if (isConstantString(C))
|
2008-07-09 15:24:38 +02:00
|
|
|
return SectionKind::RODataMergeStr;
|
2008-06-28 15:45:57 +02:00
|
|
|
else
|
2008-07-09 15:24:38 +02:00
|
|
|
return SectionKind::RODataMergeConst;
|
2008-06-28 15:45:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-30 17:27:03 +02:00
|
|
|
// Variable either is not constant or thread-local - output to data section.
|
2009-03-30 17:27:43 +02:00
|
|
|
return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
|
2008-06-28 15:45:57 +02:00
|
|
|
}
|
2008-07-09 15:16:59 +02:00
|
|
|
|
|
|
|
unsigned
|
|
|
|
TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
|
2008-07-09 15:25:26 +02:00
|
|
|
const char* Name) const {
|
|
|
|
unsigned Flags = SectionFlags::None;
|
2008-07-09 15:16:59 +02:00
|
|
|
|
|
|
|
// Decode flags from global itself.
|
|
|
|
if (GV) {
|
2008-07-09 15:25:26 +02:00
|
|
|
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
|
|
|
switch (Kind) {
|
2008-07-09 15:16:59 +02:00
|
|
|
case SectionKind::Text:
|
2008-07-09 15:25:26 +02:00
|
|
|
Flags |= SectionFlags::Code;
|
2008-07-09 15:16:59 +02:00
|
|
|
break;
|
|
|
|
case SectionKind::ThreadData:
|
|
|
|
case SectionKind::ThreadBSS:
|
2008-07-09 15:25:26 +02:00
|
|
|
Flags |= SectionFlags::TLS;
|
2008-07-09 15:16:59 +02:00
|
|
|
// FALLS THROUGH
|
2008-07-09 15:29:44 +02:00
|
|
|
case SectionKind::Data:
|
2009-03-30 17:27:03 +02:00
|
|
|
case SectionKind::DataRel:
|
|
|
|
case SectionKind::DataRelLocal:
|
|
|
|
case SectionKind::DataRelRO:
|
|
|
|
case SectionKind::DataRelROLocal:
|
2008-07-09 15:16:59 +02:00
|
|
|
case SectionKind::BSS:
|
2008-07-09 15:29:44 +02:00
|
|
|
Flags |= SectionFlags::Writeable;
|
2008-07-09 15:16:59 +02:00
|
|
|
break;
|
|
|
|
case SectionKind::ROData:
|
|
|
|
case SectionKind::RODataMergeStr:
|
|
|
|
case SectionKind::RODataMergeConst:
|
2008-07-09 15:29:44 +02:00
|
|
|
// No additional flags here
|
2008-07-09 15:16:59 +02:00
|
|
|
break;
|
2008-07-22 19:09:59 +02:00
|
|
|
case SectionKind::SmallData:
|
|
|
|
case SectionKind::SmallBSS:
|
|
|
|
Flags |= SectionFlags::Writeable;
|
|
|
|
// FALLS THROUGH
|
|
|
|
case SectionKind::SmallROData:
|
|
|
|
Flags |= SectionFlags::Small;
|
|
|
|
break;
|
2008-07-09 15:16:59 +02:00
|
|
|
default:
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unexpected section kind!");
|
2008-07-09 15:16:59 +02: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.
llvm-svn: 66339
2009-03-07 16:45:40 +01:00
|
|
|
if (GV->isWeakForLinker())
|
2008-07-09 15:25:26 +02:00
|
|
|
Flags |= SectionFlags::Linkonce;
|
2008-07-09 15:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add flags from sections, if any.
|
2008-07-09 15:25:46 +02:00
|
|
|
if (Name && *Name) {
|
2008-07-09 15:25:26 +02: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 19:09:59 +02: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 15:25:26 +02: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 15:16:59 +02:00
|
|
|
}
|
|
|
|
|
2008-07-09 15:25:26 +02:00
|
|
|
return Flags;
|
2008-07-09 15:16:59 +02:00
|
|
|
}
|
2008-07-09 15:18:02 +02:00
|
|
|
|
2008-09-25 00:14:23 +02:00
|
|
|
const Section*
|
2008-08-08 19:56:50 +02:00
|
|
|
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
|
2008-07-09 15:28:49 +02:00
|
|
|
const Section* S;
|
2008-07-09 15:22:46 +02:00
|
|
|
// Select section name
|
|
|
|
if (GV->hasSection()) {
|
|
|
|
// Honour section already set, if any
|
2008-07-09 15:28:49 +02:00
|
|
|
unsigned Flags = SectionFlagsForGlobal(GV,
|
|
|
|
GV->getSection().c_str());
|
|
|
|
S = getNamedSection(GV->getSection().c_str(), Flags);
|
2008-07-09 15:22:46 +02:00
|
|
|
} else {
|
|
|
|
// Use default section depending on the 'type' of global
|
2008-08-08 19:56:50 +02:00
|
|
|
S = SelectSectionForGlobal(GV);
|
2008-07-09 15:22:46 +02:00
|
|
|
}
|
|
|
|
|
2008-09-25 00:14:23 +02:00
|
|
|
return S;
|
2008-07-09 15:22:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lame default implementation. Calculate the section name for global.
|
2008-08-08 19:56:50 +02:00
|
|
|
const Section*
|
|
|
|
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
|
2008-07-09 15:25:26 +02:00
|
|
|
SectionKind::Kind Kind = SectionKindForGlobal(GV);
|
2008-07-09 15:18:02 +02: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.
llvm-svn: 66339
2009-03-07 16:45:40 +01:00
|
|
|
if (GV->isWeakForLinker()) {
|
2008-07-09 15:28:49 +02:00
|
|
|
std::string Name = UniqueSectionForGlobal(GV, Kind);
|
|
|
|
unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
|
|
|
|
return getNamedSection(Name.c_str(), Flags);
|
|
|
|
} else {
|
2008-07-09 15:25:26 +02:00
|
|
|
if (Kind == SectionKind::Text)
|
2008-09-25 00:15:21 +02:00
|
|
|
return getTextSection();
|
2008-08-07 11:51:54 +02:00
|
|
|
else if (isBSS(Kind) && getBSSSection_())
|
2008-07-09 15:28:49 +02:00
|
|
|
return getBSSSection_();
|
2008-09-25 00:20:27 +02:00
|
|
|
else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
|
|
|
|
return getReadOnlySection();
|
2008-07-09 15:22:46 +02:00
|
|
|
}
|
2008-07-09 15:18:02 +02:00
|
|
|
|
2008-09-25 00:16:16 +02:00
|
|
|
return getDataSection();
|
2008-07-09 15:18:02 +02:00
|
|
|
}
|
2008-07-09 15:19:38 +02:00
|
|
|
|
2008-08-07 11:50:34 +02: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-25 00:16:16 +02:00
|
|
|
return getDataSection();
|
2008-08-07 11:50:34 +02:00
|
|
|
}
|
|
|
|
|
2008-07-09 15:19:38 +02:00
|
|
|
std::string
|
|
|
|
TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
|
2008-07-09 15:25:26 +02:00
|
|
|
SectionKind::Kind Kind) const {
|
|
|
|
switch (Kind) {
|
2008-07-09 15:19:38 +02:00
|
|
|
case SectionKind::Text:
|
2008-07-09 15:24:55 +02:00
|
|
|
return ".gnu.linkonce.t." + GV->getName();
|
2008-07-09 15:19:38 +02:00
|
|
|
case SectionKind::Data:
|
2008-07-09 15:24:55 +02:00
|
|
|
return ".gnu.linkonce.d." + GV->getName();
|
2009-03-30 17:27:03 +02: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 19:09:59 +02:00
|
|
|
case SectionKind::SmallData:
|
|
|
|
return ".gnu.linkonce.s." + GV->getName();
|
2008-07-09 15:19:38 +02:00
|
|
|
case SectionKind::BSS:
|
2008-07-09 15:24:55 +02:00
|
|
|
return ".gnu.linkonce.b." + GV->getName();
|
2008-07-22 19:09:59 +02:00
|
|
|
case SectionKind::SmallBSS:
|
|
|
|
return ".gnu.linkonce.sb." + GV->getName();
|
2008-07-09 15:19:38 +02:00
|
|
|
case SectionKind::ROData:
|
|
|
|
case SectionKind::RODataMergeConst:
|
|
|
|
case SectionKind::RODataMergeStr:
|
2008-07-09 15:24:55 +02:00
|
|
|
return ".gnu.linkonce.r." + GV->getName();
|
2008-07-22 19:09:59 +02:00
|
|
|
case SectionKind::SmallROData:
|
|
|
|
return ".gnu.linkonce.s2." + GV->getName();
|
2008-07-09 15:19:38 +02:00
|
|
|
case SectionKind::ThreadData:
|
2008-07-09 15:24:55 +02:00
|
|
|
return ".gnu.linkonce.td." + GV->getName();
|
2008-07-09 15:19:38 +02:00
|
|
|
case SectionKind::ThreadBSS:
|
2008-07-09 15:24:55 +02:00
|
|
|
return ".gnu.linkonce.tb." + GV->getName();
|
2008-07-09 15:19:38 +02:00
|
|
|
default:
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unknown section kind");
|
2008-07-09 15:19:38 +02:00
|
|
|
}
|
2009-01-05 18:31:22 +01:00
|
|
|
return NULL;
|
2008-07-09 15:19:38 +02:00
|
|
|
}
|
2008-07-09 15:28:49 +02:00
|
|
|
|
|
|
|
const Section*
|
2008-08-16 14:58:12 +02:00
|
|
|
TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
|
|
|
|
bool Override) const {
|
2008-07-09 15:28:49 +02:00
|
|
|
Section& S = Sections[Name];
|
|
|
|
|
|
|
|
// This is newly-created section, set it up properly.
|
2008-08-16 14:58:12 +02:00
|
|
|
if (S.Flags == SectionFlags::Invalid || Override) {
|
2008-07-09 15:28:49 +02:00
|
|
|
S.Flags = Flags | SectionFlags::Named;
|
|
|
|
S.Name = Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &S;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Section*
|
2008-08-16 14:58:12 +02:00
|
|
|
TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
|
|
|
|
bool Override) const {
|
2008-07-09 15:28:49 +02:00
|
|
|
Section& S = Sections[Directive];
|
|
|
|
|
|
|
|
// This is newly-created section, set it up properly.
|
2008-08-16 14:58:12 +02:00
|
|
|
if (S.Flags == SectionFlags::Invalid || Override) {
|
2008-07-09 15:28:49 +02:00
|
|
|
S.Flags = Flags & ~SectionFlags::Named;
|
|
|
|
S.Name = Directive;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &S;
|
|
|
|
}
|
2008-08-16 14:57:07 +02: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 14:57:46 +02: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;
|
|
|
|
}
|