DebugInfo: Ensure that all debug location scope chains from instructions within a...
[oota-llvm.git] / lib / CodeGen / TargetLoweringObjectFileImpl.cpp
index 971d0f903cd11bfcd9c62a2ec34dde28e4d0d6b0..c7570ba76e125c2033e3b8b6a07e7f3ecd2019ad 100644 (file)
@@ -358,8 +358,11 @@ TargetLoweringObjectFileELF::getSectionForConstant(SectionKind Kind,
   return DataRelROSection;
 }
 
-const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
-    unsigned Priority, const MCSymbol *KeySym) const {
+static const MCSectionELF *getStaticStructorSection(MCContext &Ctx,
+                                                    bool UseInitArray,
+                                                    bool IsCtor,
+                                                    unsigned Priority,
+                                                    const MCSymbol *KeySym) {
   std::string Name;
   unsigned Type;
   unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
@@ -370,16 +373,24 @@ const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
     Flags |= ELF::SHF_GROUP;
 
   if (UseInitArray) {
-    Name = ".init_array";
+    if (IsCtor) {
+      Type = ELF::SHT_INIT_ARRAY;
+      Name = ".init_array";
+    } else {
+      Type = ELF::SHT_FINI_ARRAY;
+      Name = ".fini_array";
+    }
     if (Priority != 65535) {
       Name += '.';
       Name += utostr(Priority);
     }
-    Type = ELF::SHT_INIT_ARRAY;
   } else {
     // The default scheme is .ctor / .dtor, so we have to invert the priority
     // numbering.
-    Name = std::string(".ctors");
+    if (IsCtor)
+      Name = ".ctors";
+    else
+      Name = ".dtors";
     if (Priority != 65535) {
       Name += '.';
       Name += utostr(65535 - Priority);
@@ -387,39 +398,19 @@ const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
     Type = ELF::SHT_PROGBITS;
   }
 
-  return getContext().getELFSection(Name, Type, Flags, Kind, 0, COMDAT);
+  return Ctx.getELFSection(Name, Type, Flags, Kind, 0, COMDAT);
 }
 
-const MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
+const MCSection *TargetLoweringObjectFileELF::getStaticCtorSection(
     unsigned Priority, const MCSymbol *KeySym) const {
-  std::string Name;
-  unsigned Type;
-  unsigned Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
-  SectionKind Kind = SectionKind::getDataRel();
-  StringRef COMDAT = KeySym ? KeySym->getName() : "";
-
-  if (KeySym)
-    Flags |= ELF::SHF_GROUP;
-
-  if (UseInitArray) {
-    Name = ".fini_array";
-    if (Priority != 65535) {
-      Name += '.';
-      Name += utostr(Priority);
-    }
-    Type = ELF::SHT_FINI_ARRAY;
-  } else {
-    // The default scheme is .ctor / .dtor, so we have to invert the priority
-    // numbering.
-    Name = ".dtors";
-    if (Priority != 65535) {
-      Name += '.';
-      Name += utostr(65535 - Priority);
-    }
-    Type = ELF::SHT_PROGBITS;
-  }
+  return getStaticStructorSection(getContext(), UseInitArray, true, Priority,
+                                  KeySym);
+}
 
-  return getContext().getELFSection(Name, Type, Flags, Kind, 0, COMDAT);
+const MCSection *TargetLoweringObjectFileELF::getStaticDtorSection(
+    unsigned Priority, const MCSymbol *KeySym) const {
+  return getStaticStructorSection(getContext(), UseInitArray, false, Priority,
+                                  KeySym);
 }
 
 void
@@ -770,7 +761,7 @@ getCOFFSectionFlags(SectionKind K) {
       COFF::IMAGE_SCN_MEM_EXECUTE |
       COFF::IMAGE_SCN_MEM_READ |
       COFF::IMAGE_SCN_CNT_CODE;
-  else if (K.isBSS ())
+  else if (K.isBSS())
     Flags |=
       COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
       COFF::IMAGE_SCN_MEM_READ |
@@ -780,7 +771,7 @@ getCOFFSectionFlags(SectionKind K) {
       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
       COFF::IMAGE_SCN_MEM_READ |
       COFF::IMAGE_SCN_MEM_WRITE;
-  else if (K.isReadOnly())
+  else if (K.isReadOnly() || K.isReadOnlyWithRel())
     Flags |=
       COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
       COFF::IMAGE_SCN_MEM_READ;
@@ -805,7 +796,7 @@ static const GlobalValue *getComdatGVForCOFF(const GlobalValue *GV) {
 
   if (ComdatGV->getComdat() != C)
     report_fatal_error("Associative COMDAT symbol '" + ComdatGVName +
-                       "' is not a key for it's COMDAT.");
+                       "' is not a key for its COMDAT.");
 
   return ComdatGV;
 }
@@ -874,9 +865,9 @@ static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
     return ".bss";
   if (Kind.isThreadLocal())
     return ".tls$";
-  if (Kind.isWriteable())
-    return ".data";
-  return ".rdata";
+  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
+    return ".rdata";
+  return ".data";
 }
 
 
@@ -924,7 +915,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
   if (Kind.isThreadLocal())
     return TLSDataSection;
 
-  if (Kind.isReadOnly())
+  if (Kind.isReadOnly() || Kind.isReadOnlyWithRel())
     return ReadOnlySection;
 
   // Note: we claim that common symbols are put in BSSSection, but they are