It's a bool, so treat it like one. Fixes a MSVC warning.
[oota-llvm.git] / lib / Target / TargetLoweringObjectFile.cpp
index edc9ed3ba43e4b338c907ff0d47d4e05d7f253c1..b2ee95501fd8adb8dd9c8a9a9bc8827576d930da 100644 (file)
@@ -298,12 +298,14 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags,
   const MCSectionELF *&Entry = Map[Section];
   if (Entry) return Entry;
   
-  return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, HasCrazyBSS, 
-                                      IsExplicit, getContext());
+  return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, IsExplicit,
+                                      getContext());
 }
 
 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
                                              const TargetMachine &TM) {
+  if (UniquingMap != 0)
+    ((ELFUniqueMapTy*)UniquingMap)->clear();
   TargetLoweringObjectFile::Initialize(Ctx, TM);
 
   BSSSection = 
@@ -392,7 +394,8 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
                   MCSectionELF::SHF_ALLOC, SectionKind::getReadOnly());
   EHFrameSection =
     getELFSection(".eh_frame", MCSectionELF::SHT_PROGBITS, 
-                  MCSectionELF::SHF_ALLOC, SectionKind::getDataRel());
+                  MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
+                  SectionKind::getDataRel());
   
   // Debug Info Sections.
   DwarfAbbrevSection = 
@@ -461,13 +464,13 @@ getELFKindForNamedSection(const char *Name, SectionKind K) {
 static unsigned
 getELFSectionType(const char *Name, SectionKind K) {
 
-  if (strncmp(Name, ".init_array", 11) == 0)
+  if (strcmp(Name, ".init_array") == 0)
     return MCSectionELF::SHT_INIT_ARRAY;
 
-  if (strncmp(Name, ".fini_array", 11) == 0)
+  if (strcmp(Name, ".fini_array") == 0)
     return MCSectionELF::SHT_FINI_ARRAY;
 
-  if (strncmp(Name, ".preinit_array", 14) == 0)
+  if (strcmp(Name, ".preinit_array") == 0)
     return MCSectionELF::SHT_PREINIT_ARRAY;
 
   if (K.isBSS() || K.isThreadBSS())
@@ -484,6 +487,9 @@ getELFSectionFlags(SectionKind K) {
   if (!K.isMetadata())
     Flags |= MCSectionELF::SHF_ALLOC;
   
+  if (K.isText())
+    Flags |= MCSectionELF::SHF_EXECINSTR;
+  
   if (K.isWriteable())
     Flags |= MCSectionELF::SHF_WRITE;
   
@@ -578,11 +584,11 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
   }
   
   if (Kind.isMergeableConst()) {
-    if (Kind.isMergeableConst4())
+    if (Kind.isMergeableConst4() && MergeableConst4Section)
       return MergeableConst4Section;
-    if (Kind.isMergeableConst8())
+    if (Kind.isMergeableConst8() && MergeableConst8Section)
       return MergeableConst8Section;
-    if (Kind.isMergeableConst16())
+    if (Kind.isMergeableConst16() && MergeableConst16Section)
       return MergeableConst16Section;
     return ReadOnlySection;  // .const
   }
@@ -608,11 +614,11 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
 /// should be placed in.
 const MCSection *TargetLoweringObjectFileELF::
 getSectionForConstant(SectionKind Kind) const {
-  if (Kind.isMergeableConst4())
+  if (Kind.isMergeableConst4() && MergeableConst4Section)
     return MergeableConst4Section;
-  if (Kind.isMergeableConst8())
+  if (Kind.isMergeableConst8() && MergeableConst8Section)
     return MergeableConst8Section;
-  if (Kind.isMergeableConst16())
+  if (Kind.isMergeableConst16() && MergeableConst16Section)
     return MergeableConst16Section;
   if (Kind.isReadOnly())
     return ReadOnlySection;
@@ -649,12 +655,12 @@ getMachOSection(const StringRef &Segment, const StringRef &Section,
   
   // Form the name to look up.
   SmallString<64> Name;
-  Name.append(Segment.begin(), Segment.end());
+  Name += Segment;
   Name.push_back(',');
-  Name.append(Section.begin(), Section.end());
+  Name += Section;
   
   // Do the lookup, if we have a hit, return it.
-  const MCSectionMachO *&Entry = Map[StringRef(Name.data(), Name.size())];
+  const MCSectionMachO *&Entry = Map[Name.str()];
   if (Entry) return Entry;
 
   // Otherwise, return a new section.
@@ -665,6 +671,8 @@ getMachOSection(const StringRef &Segment, const StringRef &Section,
 
 void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
                                                const TargetMachine &TM) {
+  if (UniquingMap != 0)
+    ((MachOUniqueMapTy*)UniquingMap)->clear();
   TargetLoweringObjectFile::Initialize(Ctx, TM);
   
   TextSection // .text
@@ -945,6 +953,8 @@ getCOFFSection(const char *Name, bool isDirective, SectionKind Kind) const {
 
 void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
                                               const TargetMachine &TM) {
+  if (UniquingMap != 0)
+    ((COFFUniqueMapTy*)UniquingMap)->clear();
   TargetLoweringObjectFile::Initialize(Ctx, TM);
   TextSection = getCOFFSection("\t.text", true, SectionKind::getText());
   DataSection = getCOFFSection("\t.data", true, SectionKind::getDataRel());
@@ -953,6 +963,14 @@ void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
   StaticDtorSection =
     getCOFFSection(".dtors", false, SectionKind::getDataRel());
   
+  // FIXME: We're emitting LSDA info into a readonly section on COFF, even
+  // though it contains relocatable pointers.  In PIC mode, this is probably a
+  // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
+  // adjusted or this should be a data section.
+  LSDASection =
+    getCOFFSection(".gcc_except_table", false, SectionKind::getReadOnly());
+  EHFrameSection =
+    getCOFFSection(".eh_frame", false, SectionKind::getDataRel());
   
   // Debug info.
   // FIXME: Don't use 'directive' mode here.