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