ARMEmulation.cpp revision f7ac0f19a1c8d0ad14bcf6456ce368b830fea886
1//===- ARMEmulation.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#include "ARM.h"
10#include <mcld/LinkerConfig.h>
11#include <mcld/LinkerScript.h>
12#include <mcld/Target/ELFEmulation.h>
13#include <mcld/Support/TargetRegistry.h>
14
15namespace mcld {
16
17static bool MCLDEmulateARMELF(LinkerScript& pScript, LinkerConfig& pConfig)
18{
19  if (!MCLDEmulateELF(pScript, pConfig))
20    return false;
21
22  // set up bitclass and endian
23  pConfig.targets().setEndian(TargetOptions::Little);
24  pConfig.targets().setBitClass(32);
25
26  // set up target-dependent constraints of attributes
27  pConfig.attribute().constraint().enableWholeArchive();
28  pConfig.attribute().constraint().enableAsNeeded();
29  pConfig.attribute().constraint().setSharedSystem();
30
31  // set up the predefined attributes
32  pConfig.attribute().predefined().unsetWholeArchive();
33  pConfig.attribute().predefined().unsetAsNeeded();
34  pConfig.attribute().predefined().setDynamic();
35
36  // set up section map
37  if (pConfig.codeGenType() != LinkerConfig::Object) {
38    bool exist = false;
39    pScript.sectionMap().append(".ARM.exidx", ".ARM.exidx", exist);
40    pScript.sectionMap().append(".ARM.extab", ".ARM.extab", exist);
41    pScript.sectionMap().append(".ARM.attributes", ".ARM.attributes", exist);
42  }
43  return true;
44}
45
46//===----------------------------------------------------------------------===//
47// emulateARMLD - the help function to emulate ARM ld
48//===----------------------------------------------------------------------===//
49bool emulateARMLD(LinkerScript& pScript, LinkerConfig& pConfig)
50{
51  if (pConfig.targets().triple().isOSDarwin()) {
52    assert(0 && "MachO linker has not supported yet");
53    return false;
54  }
55  if (pConfig.targets().triple().isOSWindows()) {
56    assert(0 && "COFF linker has not supported yet");
57    return false;
58  }
59
60  return MCLDEmulateARMELF(pScript, pConfig);
61}
62
63} // namespace of mcld
64
65//===----------------------------------------------------------------------===//
66// ARMEmulation
67//===----------------------------------------------------------------------===//
68extern "C" void MCLDInitializeARMEmulation() {
69  // Register the emulation
70  mcld::TargetRegistry::RegisterEmulation(mcld::TheARMTarget, mcld::emulateARMLD);
71  mcld::TargetRegistry::RegisterEmulation(mcld::TheThumbTarget, mcld::emulateARMLD);
72}
73
74