Home | History | Annotate | Download | only in Support
      1 //===- TargetLinkerConfigs.cpp --------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #include "alone/Config/Config.h"
     11 #include "alone/Support/TargetLinkerConfigs.h"
     12 
     13 #include <mcld/TargetOptions.h>
     14 #include <mcld/MC/InputFactory.h>
     15 #include <mcld/Fragment/Relocation.h>
     16 
     17 using namespace alone;
     18 
     19 #ifdef TARGET_BUILD
     20 static const char* gDefaultDyld = "/system/bin/linker";
     21 static const char* gDefaultSysroot = "/system";
     22 #else
     23 static const char* gDefaultDyld = "/usr/lib/ld.so.1";
     24 static const char* gDefaultSysroot = "/";
     25 #endif
     26 
     27 //===----------------------------------------------------------------------===//
     28 // ARM
     29 //===----------------------------------------------------------------------===//
     30 #if defined(PROVIDE_ARM_CODEGEN)
     31 ARMLinkerConfig::ARMLinkerConfig() : LinkerConfig(DEFAULT_ARM_TRIPLE_STRING) {
     32 
     33   // set up target-dependent options
     34   getLDConfig()->targets().setEndian(mcld::TargetOptions::Little);
     35   getLDConfig()->targets().setBitClass(32);
     36 
     37   // set up target-dependent constraints of attributes
     38   getLDConfig()->attribute().constraint().enableWholeArchive();
     39   getLDConfig()->attribute().constraint().disableAsNeeded();
     40   getLDConfig()->attribute().constraint().setSharedSystem();
     41 
     42   // set up the predefined attributes
     43   getLDConfig()->attribute().predefined().unsetWholeArchive();
     44   getLDConfig()->attribute().predefined().setDynamic();
     45 
     46   // set up target dependent options
     47   if (getLDConfig()->options().sysroot().empty()) {
     48     getLDConfig()->options().setSysroot(gDefaultSysroot);
     49   }
     50 
     51   if (!getLDConfig()->options().hasDyld()) {
     52     getLDConfig()->options().setDyld(gDefaultDyld);
     53   }
     54 
     55   // set up section map
     56   if (getLDConfig()->codeGenType() != mcld::LinkerConfig::Object) {
     57     bool exist = false;
     58     getLDConfig()->scripts().sectionMap().append(".ARM.exidx", ".ARM.exidx", exist);
     59     getLDConfig()->scripts().sectionMap().append(".ARM.extab", ".ARM.extab", exist);
     60     getLDConfig()->scripts().sectionMap().append(".ARM.attributes", ".ARM.attributes", exist);
     61   }
     62 
     63   // set up relocation factory
     64   mcld::Relocation::SetUp(*getLDConfig());
     65 }
     66 #endif // defined(PROVIDE_ARM_CODEGEN)
     67 
     68 //===----------------------------------------------------------------------===//
     69 // Mips
     70 //===----------------------------------------------------------------------===//
     71 #if defined(PROVIDE_MIPS_CODEGEN)
     72 MipsLinkerConfig::MipsLinkerConfig()
     73   : LinkerConfig(DEFAULT_MIPS_TRIPLE_STRING) {
     74 
     75   // set up target-dependent options
     76   getLDConfig()->targets().setEndian(mcld::TargetOptions::Little);
     77   getLDConfig()->targets().setBitClass(32);
     78 
     79   // set up target-dependent constraints of attibutes
     80   getLDConfig()->attribute().constraint().enableWholeArchive();
     81   getLDConfig()->attribute().constraint().disableAsNeeded();
     82   getLDConfig()->attribute().constraint().setSharedSystem();
     83 
     84   // set up the predefined attributes
     85   getLDConfig()->attribute().predefined().unsetWholeArchive();
     86   getLDConfig()->attribute().predefined().setDynamic();
     87 
     88   // set up target dependent options
     89   if (getLDConfig()->options().sysroot().empty()) {
     90     getLDConfig()->options().setSysroot(gDefaultSysroot);
     91   }
     92 
     93   if (!getLDConfig()->options().hasDyld()) {
     94     getLDConfig()->options().setDyld(gDefaultDyld);
     95   }
     96 
     97   // set up relocation factory
     98   mcld::Relocation::SetUp(*getLDConfig());
     99 }
    100 #endif // defined(PROVIDE_MIPS_CODEGEN)
    101 
    102 //===----------------------------------------------------------------------===//
    103 // X86 and X86_64
    104 //===----------------------------------------------------------------------===//
    105 #if defined(PROVIDE_X86_CODEGEN)
    106 X86FamilyLinkerConfigBase::X86FamilyLinkerConfigBase(const std::string& pTriple)
    107   : LinkerConfig(pTriple) {
    108   // set up target-dependent options
    109   getLDConfig()->targets().setEndian(mcld::TargetOptions::Little);
    110   getLDConfig()->targets().setBitClass(32);
    111 
    112   // set up target-dependent constraints of attibutes
    113   getLDConfig()->attribute().constraint().enableWholeArchive();
    114   getLDConfig()->attribute().constraint().disableAsNeeded();
    115   getLDConfig()->attribute().constraint().setSharedSystem();
    116 
    117   // set up the predefined attributes
    118   getLDConfig()->attribute().predefined().unsetWholeArchive();
    119   getLDConfig()->attribute().predefined().setDynamic();
    120 
    121   // set up target dependent options
    122   if (getLDConfig()->options().sysroot().empty()) {
    123     getLDConfig()->options().setSysroot(gDefaultSysroot);
    124   }
    125 
    126   if (!getLDConfig()->options().hasDyld()) {
    127     getLDConfig()->options().setDyld(gDefaultDyld);
    128   }
    129 
    130   // set up relocation factory
    131   mcld::Relocation::SetUp(*getLDConfig());
    132 }
    133 
    134 X86_32LinkerConfig::X86_32LinkerConfig()
    135   : X86FamilyLinkerConfigBase(DEFAULT_X86_TRIPLE_STRING) {
    136 }
    137 
    138 X86_64LinkerConfig::X86_64LinkerConfig()
    139   : X86FamilyLinkerConfigBase(DEFAULT_X86_64_TRIPLE_STRING) {
    140 }
    141 #endif // defined(PROVIDE_X86_CODEGEN)
    142 
    143 #if !defined(TARGET_BUILD)
    144 //===----------------------------------------------------------------------===//
    145 // General
    146 //===----------------------------------------------------------------------===//
    147 GeneralLinkerConfig::GeneralLinkerConfig(const std::string& pTriple)
    148   : LinkerConfig(pTriple) {
    149 
    150   // set up target-dependent options
    151   getLDConfig()->targets().setEndian(mcld::TargetOptions::Little);
    152   getLDConfig()->targets().setBitClass(32);
    153 
    154   // set up target-dependent constraints of attributes
    155   getLDConfig()->attribute().constraint().enableWholeArchive();
    156   getLDConfig()->attribute().constraint().disableAsNeeded();
    157   getLDConfig()->attribute().constraint().setSharedSystem();
    158 
    159   // set up the predefined attributes
    160   getLDConfig()->attribute().predefined().unsetWholeArchive();
    161   getLDConfig()->attribute().predefined().setDynamic();
    162 
    163   // set up section map
    164   if (llvm::Triple::arm == getLDConfig()->targets().triple().getArch() &&
    165       getLDConfig()->codeGenType() != mcld::LinkerConfig::Object) {
    166     bool exist = false;
    167     getLDConfig()->scripts().sectionMap().append(".ARM.exidx", ".ARM.exidx", exist);
    168     getLDConfig()->scripts().sectionMap().append(".ARM.extab", ".ARM.extab", exist);
    169     getLDConfig()->scripts().sectionMap().append(".ARM.attributes", ".ARM.attributes", exist);
    170   }
    171 
    172   // set up relocation factory
    173   mcld::Relocation::SetUp(*getLDConfig());
    174 }
    175 #endif // defined(TARGET_BUILD)
    176