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#ifndef BCC_LINKER_H
18#define BCC_LINKER_H
19
20#include <string>
21
22namespace mcld {
23
24class Module;
25class IRBuilder;
26class LinkerConfig;
27class Linker;
28class Input;
29class MemoryArea;
30
31namespace sys { namespace fs {
32
33class Path;
34
35} } // end namespace sys::fs
36
37} // end namespace mcld
38
39namespace bcc {
40
41class LinkerConfig;
42
43class Linker {
44public:
45  enum ErrorCode {
46    kSuccess,
47    kDoubleConfig,
48    kDelegateLDInfo,
49    kFindNameSpec,
50    kOpenObjectFile,
51    kOpenMemory,
52    kNotConfig,
53    kNotSetUpOutput,
54    kOpenOutput,
55    kReadSections,
56    kReadSymbols,
57    kAddAdditionalSymbols,
58    kMaxErrorCode
59  };
60
61  static const char *GetErrorString(enum ErrorCode pErrCode);
62
63private:
64  const mcld::LinkerConfig *mLDConfig;
65  mcld::Module *mModule;
66  mcld::Linker *mLinker;
67  mcld::IRBuilder *mBuilder;
68  std::string mSOName;
69  std::string mOutputPath;
70  int mOutputHandler;
71
72public:
73  Linker();
74
75  Linker(const LinkerConfig& pConfig);
76
77  ~Linker();
78
79  enum ErrorCode config(const LinkerConfig& pConfig);
80
81  enum ErrorCode addNameSpec(const std::string &pNameSpec);
82
83  enum ErrorCode addObject(const std::string &pObjectPath);
84
85  enum ErrorCode addObject(void* pMemory, size_t pSize);
86
87  enum ErrorCode addCode(void* pMemory, size_t pSize);
88
89  enum ErrorCode setOutput(const std::string &pPath);
90
91  enum ErrorCode setOutput(int pFileHandler);
92
93  enum ErrorCode link();
94
95private:
96  enum ErrorCode extractFiles(const LinkerConfig& pConfig);
97};
98
99} // end namespace bcc
100
101#endif // BCC_LINKER_H
102