1//===- AArch64Emulation.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 "AArch64.h"
10#include "mcld/LinkerConfig.h"
11#include "mcld/LinkerScript.h"
12#include "mcld/Support/TargetRegistry.h"
13#include "mcld/Target/ELFEmulation.h"
14
15namespace mcld {
16
17static bool MCLDEmulateAArch64ELF(LinkerScript& pScript,
18                                  LinkerConfig& pConfig) {
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(64);
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.options().getScriptList().empty() &&
38      pConfig.codeGenType() != LinkerConfig::Object) {
39    pScript.sectionMap().insert(".ARM.attributes*", ".ARM.attributes");
40  }
41  return true;
42}
43
44//===----------------------------------------------------------------------===//
45// emulateAArch64LD - the help function to emulate AArch64 ld
46//===----------------------------------------------------------------------===//
47bool emulateAArch64LD(LinkerScript& pScript, LinkerConfig& pConfig) {
48  if (pConfig.targets().triple().isOSDarwin()) {
49    assert(0 && "MachO linker has not supported yet");
50    return false;
51  }
52  if (pConfig.targets().triple().isOSWindows()) {
53    assert(0 && "COFF linker has not supported yet");
54    return false;
55  }
56
57  return MCLDEmulateAArch64ELF(pScript, pConfig);
58}
59
60}  // namespace mcld
61
62//===----------------------------------------------------------------------===//
63// AArch64Emulation
64//===----------------------------------------------------------------------===//
65extern "C" void MCLDInitializeAArch64Emulation() {
66  // Register the emulation
67  mcld::TargetRegistry::RegisterEmulation(mcld::TheAArch64Target,
68                                          mcld::emulateAArch64LD);
69}
70