1//===- Linker.h -----------------------------------------------------------===//
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#ifndef ALONE_LINKER_H
11#define ALONE_LINKER_H
12
13#include <string>
14
15namespace mcld {
16
17class TargetLDBackend;
18class MCLDDriver;
19class MemoryFactory;
20class MCLDInfo;
21class TreeIteratorBase;
22class Input;
23
24namespace sys { namespace fs {
25
26class Path;
27
28} } // end namespace sys::fs
29
30} // end namespace mcld
31
32namespace alone {
33
34class MemoryFactory;
35class LinkerConfig;
36
37class Linker {
38public:
39  enum ErrorCode {
40    kSuccess,
41    kDoubleConfig,
42    kCreateBackend,
43    kDelegateLDInfo,
44    kFindNameSpec,
45    kOpenNameSpec,
46    kOpenObjectFile,
47    kNotConfig,
48    kNotSetUpOutput,
49    kOpenOutput,
50    kReadSections,
51    kReadSymbols,
52    kAddAdditionalSymbols,
53    kMaxErrorCode,
54  };
55
56  static const char *GetErrorString(enum ErrorCode pErrCode);
57
58private:
59  mcld::TargetLDBackend *mBackend;
60  mcld::MCLDDriver *mDriver;
61  MemoryFactory *mMemAreaFactory;
62  mcld::MCLDInfo *mLDInfo;
63  mcld::TreeIteratorBase *mRoot;
64  bool mShared;
65  std::string mSOName;
66
67public:
68  Linker();
69
70  Linker(const LinkerConfig& pConfig);
71
72  ~Linker();
73
74  enum ErrorCode config(const LinkerConfig& pConfig);
75
76  enum ErrorCode addNameSpec(const std::string &pNameSpec);
77
78  enum ErrorCode addObject(const std::string &pObjectPath);
79
80  enum ErrorCode addObject(void* pMemory, size_t pSize);
81
82  enum ErrorCode addCode(void* pMemory, size_t pSize);
83
84  enum ErrorCode setOutput(const std::string &pPath);
85
86  enum ErrorCode setOutput(int pFileHandler);
87
88  enum ErrorCode link();
89
90private:
91  enum ErrorCode extractFiles(const LinkerConfig& pConfig);
92
93  enum ErrorCode openFile(const mcld::sys::fs::Path& pPath,
94                          enum ErrorCode pCode,
95                          mcld::Input& pInput);
96
97  void advanceRoot();
98};
99
100} // end namespace alone
101
102#endif // ALONE_LINKER_H
103