Add support for mergeable sections back into the XCore backend.
[oota-llvm.git] / lib / Target / XCore / XCoreTargetObjectFile.cpp
index 89880c29f45d10a2c5fd850eea944d32bba268fa..c1990d6d0fcbbc702af07787de3388ac900119b7 100644 (file)
@@ -8,25 +8,67 @@
 //===----------------------------------------------------------------------===//
 
 #include "XCoreTargetObjectFile.h"
+#include "XCoreSubtarget.h"
+#include "MCSectionXCore.h"
+#include "llvm/Target/TargetMachine.h"
 using namespace llvm;
 
 
-XCoreTargetObjectFile::XCoreTargetObjectFile(bool isXS1A) {
-  TextSection = getOrCreateSection("\t.text", true, SectionKind::Text);
-  DataSection = getOrCreateSection("\t.dp.data", false, SectionKind::DataRel);
-  BSSSection_ = getOrCreateSection("\t.dp.bss", false, SectionKind::BSS);
+void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
+  TargetLoweringObjectFileELF::Initialize(Ctx, TM);
+
+  DataSection =
+    MCSectionXCore::Create(".dp.data", MCSectionELF::SHT_PROGBITS, 
+                           MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE |
+                           MCSectionXCore::SHF_DP_SECTION,
+                           SectionKind::getDataRel(), false, getContext());
+  BSSSection =
+    MCSectionXCore::Create(".dp.bss", MCSectionELF::SHT_NOBITS,
+                           MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE |
+                           MCSectionXCore::SHF_DP_SECTION,
+                           SectionKind::getBSS(), false, getContext());
+  
+  MergeableConst4Section = 
+    MCSectionXCore::Create(".cp.rodata.cst4", MCSectionELF::SHT_PROGBITS,
+                           MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE |
+                           MCSectionXCore::SHF_CP_SECTION,
+                           SectionKind::getMergeableConst4(), false,
+                           getContext());
+  MergeableConst8Section = 
+    MCSectionXCore::Create(".cp.rodata.cst8", MCSectionELF::SHT_PROGBITS,
+                           MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE |
+                           MCSectionXCore::SHF_CP_SECTION,
+                           SectionKind::getMergeableConst8(), false,
+                           getContext());
+  MergeableConst16Section = 
+    MCSectionXCore::Create(".cp.rodata.cst16", MCSectionELF::SHT_PROGBITS,
+                           MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE |
+                           MCSectionXCore::SHF_CP_SECTION,
+                           SectionKind::getMergeableConst16(), false,
+                           getContext());
   
   // TLS globals are lowered in the backend to arrays indexed by the current
   // thread id. After lowering they require no special handling by the linker
   // and can be placed in the standard data / bss sections.
   TLSDataSection = DataSection;
-  TLSBSSSection = BSSSection_;
+  TLSBSSSection = BSSSection;
   
-  if (isXS1A)
-    // FIXME: Why is this writable ("datarel")???
-    ReadOnlySection = getOrCreateSection("\t.dp.rodata", false,
-                                         SectionKind::DataRel);
+  if (TM.getSubtarget<XCoreSubtarget>().isXS1A())
+    ReadOnlySection =   // FIXME: Why is this a writable section for XS1A?
+      MCSectionXCore::Create(".dp.rodata", MCSectionELF::SHT_PROGBITS,
+                             MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE |
+                             MCSectionXCore::SHF_DP_SECTION,
+                             SectionKind::getDataRel(), false, getContext());
   else
-    ReadOnlySection = getOrCreateSection("\t.cp.rodata", false,
-                                         SectionKind::ReadOnly);
-}
\ No newline at end of file
+    ReadOnlySection = 
+      MCSectionXCore::Create(".cp.rodata", MCSectionELF::SHT_PROGBITS,
+                             MCSectionELF::SHF_ALLOC |
+                             MCSectionXCore::SHF_CP_SECTION,
+                             SectionKind::getReadOnlyWithRel(), false,
+                             getContext());
+
+  // Dynamic linking is not supported. Data with relocations is placed in the
+  // same section as data without relocations.
+  DataRelSection = DataRelLocalSection = DataSection;
+  DataRelROSection = DataRelROLocalSection = ReadOnlySection;
+}