#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Triple.h"
using namespace llvm;
using namespace dwarf;
bool EmitUniquedSection;
if (Kind.isText())
EmitUniquedSection = TM.getFunctionSections();
- else
+ else
EmitUniquedSection = TM.getDataSections();
// If this global is linkonce/weak and the target handles this by emitting it
IsFunctionEHSymbolGlobal = true;
IsFunctionEHFrameSymbolPrivate = false;
SupportsWeakOmittedEHFrame = false;
-
+
+ Triple T(((LLVMTargetMachine&)TM).getTargetTriple());
+ if (T.getOS() == Triple::Darwin) {
+ switch (T.getDarwinMajorNumber()) {
+ case 7: // 10.3 Panther.
+ case 8: // 10.4 Tiger.
+ CommDirectiveSupportsAlignment = false;
+ break;
+ case 9: // 10.5 Leopard.
+ case 10: // 10.6 SnowLeopard.
+ break;
+ }
+ }
+
TargetLoweringObjectFile::Initialize(Ctx, TM);
TextSection // .text
= getContext().getMachOSection("__DATA", "__data", 0,
SectionKind::getDataRel());
+ TLSDataSection // .tdata
+ = getContext().getMachOSection("__DATA", "__thread_data",
+ MCSectionMachO::S_THREAD_LOCAL_REGULAR,
+ SectionKind::getDataRel());
+ TLSBSSSection // .tbss
+ = getContext().getMachOSection("__DATA", "__thread_bss",
+ MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
+ SectionKind::getThreadBSS());
+
+ // TODO: Verify datarel below.
+ TLSTLVSection // .tlv
+ = getContext().getMachOSection("__DATA", "__thread_vars",
+ MCSectionMachO::S_THREAD_LOCAL_VARIABLES,
+ SectionKind::getDataRel());
+
+ TLSThreadInitSection
+ = getContext().getMachOSection("__DATA", "__thread_init",
+ MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
+ SectionKind::getDataRel());
+
CStringSection // .cstring
- = getContext().getMachOSection("__TEXT", "__cstring",
+ = getContext().getMachOSection("__TEXT", "__cstring",
MCSectionMachO::S_CSTRING_LITERALS,
SectionKind::getMergeable1ByteCString());
UStringSection
MCSectionMachO::S_4BYTE_LITERALS,
SectionKind::getMergeableConst4());
EightByteConstantSection // .literal8
- = getContext().getMachOSection("__TEXT", "__literal8",
+ = getContext().getMachOSection("__TEXT", "__literal8",
MCSectionMachO::S_8BYTE_LITERALS,
SectionKind::getMergeableConst8());
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
SectionKind::getText());
ConstTextCoalSection
- = getContext().getMachOSection("__TEXT", "__const_coal",
- MCSectionMachO::S_COALESCED,
- SectionKind::getText());
- ConstDataCoalSection
- = getContext().getMachOSection("__DATA","__const_coal",
+ = getContext().getMachOSection("__TEXT", "__const_coal",
MCSectionMachO::S_COALESCED,
- SectionKind::getText());
+ SectionKind::getReadOnly());
ConstDataSection // .const_data
= getContext().getMachOSection("__DATA", "__const", 0,
SectionKind::getReadOnlyWithRel());
DataCoalSection
- = getContext().getMachOSection("__DATA","__datacoal_nt",
+ = getContext().getMachOSection("__DATA","__datacoal_nt",
MCSectionMachO::S_COALESCED,
SectionKind::getDataRel());
DataCommonSection
DataBSSSection
= getContext().getMachOSection("__DATA","__bss", MCSectionMachO::S_ZEROFILL,
SectionKind::getBSS());
-
+
LazySymbolPointerSection
= getContext().getMachOSection("__DATA", "__la_symbol_ptr",
// Debug Information.
DwarfAbbrevSection =
- getContext().getMachOSection("__DWARF", "__debug_abbrev",
+ getContext().getMachOSection("__DWARF", "__debug_abbrev",
MCSectionMachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfInfoSection =
getContext().getMachOSection("__DWARF", "__debug_inlined",
MCSectionMachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
+
+ TLSExtraDataSection = TLSTLVSection;
}
const MCSection *TargetLoweringObjectFileMachO::
const MCSection *TargetLoweringObjectFileMachO::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
- assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS");
+
+ // Handle thread local data.
+ if (Kind.isThreadBSS()) return TLSBSSSection;
+ if (Kind.isThreadData()) return TLSDataSection;
if (Kind.isText())
return GV->isWeakForLinker() ? TextCoalSection : TextSection;
if (Kind.isMergeable1ByteCString() &&
TM.getTargetData()->getPreferredAlignment(cast<GlobalVariable>(GV)) < 32)
return CStringSection;
-
+
// Do not put 16-bit arrays in the UString section if they have an
// externally visible label, this runs into issues with certain linker
// versions.
// with the .zerofill directive (aka .lcomm).
if (Kind.isBSSLocal())
return DataBSSSection;
-
+
// Otherwise, just drop the variable in the normal data section.
return DataSection;
}
TargetLoweringObjectFile::Initialize(Ctx, TM);
TextSection =
getContext().getCOFFSection(".text",
- MCSectionCOFF::IMAGE_SCN_CNT_CODE |
- MCSectionCOFF::IMAGE_SCN_MEM_EXECUTE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_CNT_CODE |
+ COFF::IMAGE_SCN_MEM_EXECUTE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getText());
DataSection =
getContext().getCOFFSection(".data",
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ |
- MCSectionCOFF::IMAGE_SCN_MEM_WRITE,
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
ReadOnlySection =
getContext().getCOFFSection(".rdata",
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
StaticCtorSection =
getContext().getCOFFSection(".ctors",
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ |
- MCSectionCOFF::IMAGE_SCN_MEM_WRITE,
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
StaticDtorSection =
getContext().getCOFFSection(".dtors",
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ |
- MCSectionCOFF::IMAGE_SCN_MEM_WRITE,
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
// FIXME: We're emitting LSDA info into a readonly section on COFF, even
// adjusted or this should be a data section.
LSDASection =
getContext().getCOFFSection(".gcc_except_table",
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
EHFrameSection =
getContext().getCOFFSection(".eh_frame",
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ |
- MCSectionCOFF::IMAGE_SCN_MEM_WRITE,
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
// Debug info.
DwarfAbbrevSection =
getContext().getCOFFSection(".debug_abbrev",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfInfoSection =
getContext().getCOFFSection(".debug_info",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfLineSection =
getContext().getCOFFSection(".debug_line",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfFrameSection =
getContext().getCOFFSection(".debug_frame",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfPubNamesSection =
getContext().getCOFFSection(".debug_pubnames",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfPubTypesSection =
getContext().getCOFFSection(".debug_pubtypes",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfStrSection =
getContext().getCOFFSection(".debug_str",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfLocSection =
getContext().getCOFFSection(".debug_loc",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfARangesSection =
getContext().getCOFFSection(".debug_aranges",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfRangesSection =
getContext().getCOFFSection(".debug_ranges",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfMacroInfoSection =
getContext().getCOFFSection(".debug_macinfo",
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE |
- MCSectionCOFF::IMAGE_SCN_MEM_READ,
+ COFF::IMAGE_SCN_MEM_DISCARDABLE |
+ COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DrectveSection =
getContext().getCOFFSection(".drectve",
- MCSectionCOFF::IMAGE_SCN_LNK_INFO,
+ COFF::IMAGE_SCN_LNK_INFO,
SectionKind::getMetadata());
}
getCOFFSectionFlags(SectionKind K) {
unsigned Flags = 0;
- if (!K.isMetadata())
+ if (K.isMetadata())
Flags |=
- MCSectionCOFF::IMAGE_SCN_MEM_DISCARDABLE;
+ COFF::IMAGE_SCN_MEM_DISCARDABLE;
else if (K.isText())
Flags |=
- MCSectionCOFF::IMAGE_SCN_MEM_EXECUTE |
- MCSectionCOFF::IMAGE_SCN_CNT_CODE;
+ COFF::IMAGE_SCN_MEM_EXECUTE |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_CNT_CODE;
else if (K.isBSS ())
Flags |=
- MCSectionCOFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ |
- MCSectionCOFF::IMAGE_SCN_MEM_WRITE;
+ COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_MEM_WRITE;
else if (K.isReadOnly())
Flags |=
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ;
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ;
else if (K.isWriteable())
Flags |=
- MCSectionCOFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- MCSectionCOFF::IMAGE_SCN_MEM_READ |
- MCSectionCOFF::IMAGE_SCN_MEM_WRITE;
+ COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ |
+ COFF::IMAGE_SCN_MEM_WRITE;
return Flags;
}
static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
if (Kind.isText())
- return ".text$linkonce";
+ return ".text$";
if (Kind.isBSS ())
- return ".bss$linkonce";
+ return ".bss$";
if (Kind.isWriteable())
- return ".data$linkonce";
- return ".rdata$linkonce";
+ return ".data$";
+ return ".rdata$";
}
const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind);
SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
MCSymbol *Sym = Mang->getSymbol(GV);
- Name.append(Sym->getName().begin(), Sym->getName().end());
+ Name.append(Sym->getName().begin() + 1, Sym->getName().end());
unsigned Characteristics = getCOFFSectionFlags(Kind);
- Characteristics |= MCSectionCOFF::IMAGE_SCN_LNK_COMDAT;
+ Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
return getContext().getCOFFSection(Name.str(), Characteristics,
- MCSectionCOFF::IMAGE_COMDAT_SELECT_EXACT_MATCH, Kind);
+ COFF::IMAGE_COMDAT_SELECT_ANY, Kind);
}
if (Kind.isText())