Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 1 | //===- LinkerScript.cpp ---------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the parser/evaluator of the linker script. |
| 11 | // It does not construct an AST but consume linker script directives directly. |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 12 | // Results are written to Driver or Config object. |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "Config.h" |
| 17 | #include "Driver.h" |
| 18 | #include "SymbolTable.h" |
| 19 | #include "llvm/Support/FileSystem.h" |
| 20 | #include "llvm/Support/MemoryBuffer.h" |
Rui Ueyama | f03f3cc | 2015-10-13 00:09:21 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Path.h" |
Rui Ueyama | a47ee68 | 2015-10-11 01:53:04 +0000 | [diff] [blame] | 22 | #include "llvm/Support/StringSaver.h" |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
| 25 | using namespace lld; |
| 26 | using namespace lld::elf2; |
| 27 | |
| 28 | namespace { |
| 29 | class LinkerScript { |
| 30 | public: |
Simon Atanasyan | 16b0cc9 | 2015-11-26 05:53:00 +0000 | [diff] [blame] | 31 | LinkerScript(BumpPtrAllocator *A, StringRef S, bool B) |
| 32 | : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {} |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 33 | void run(); |
| 34 | |
| 35 | private: |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 36 | void setError(const Twine &Msg); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 37 | static std::vector<StringRef> tokenize(StringRef S); |
| 38 | static StringRef skipSpace(StringRef S); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 39 | bool atEOF(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 40 | StringRef next(); |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 41 | bool skip(StringRef Tok); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 42 | void expect(StringRef Expect); |
| 43 | |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 44 | void addFile(StringRef Path); |
| 45 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 46 | void readAsNeeded(); |
Denis Protivensky | 90c5099 | 2015-10-08 06:48:38 +0000 | [diff] [blame] | 47 | void readEntry(); |
George Rimar | 83f406c | 2015-10-19 17:35:12 +0000 | [diff] [blame] | 48 | void readExtern(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 49 | void readGroup(); |
Rui Ueyama | 31aa1f8 | 2015-10-11 01:31:55 +0000 | [diff] [blame] | 50 | void readInclude(); |
Rui Ueyama | ee59282 | 2015-10-07 00:25:09 +0000 | [diff] [blame] | 51 | void readOutput(); |
Davide Italiano | 9159ce9 | 2015-10-12 21:50:08 +0000 | [diff] [blame] | 52 | void readOutputArch(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 53 | void readOutputFormat(); |
Davide Italiano | 68a39a6 | 2015-10-08 17:51:41 +0000 | [diff] [blame] | 54 | void readSearchDir(); |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 55 | void readSections(); |
| 56 | |
| 57 | void readOutputSectionDescription(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 58 | |
Rui Ueyama | a47ee68 | 2015-10-11 01:53:04 +0000 | [diff] [blame] | 59 | StringSaver Saver; |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 60 | std::vector<StringRef> Tokens; |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 61 | bool Error = false; |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 62 | size_t Pos = 0; |
Simon Atanasyan | 16b0cc9 | 2015-11-26 05:53:00 +0000 | [diff] [blame] | 63 | bool IsUnderSysroot; |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 64 | }; |
| 65 | } |
| 66 | |
| 67 | void LinkerScript::run() { |
| 68 | while (!atEOF()) { |
| 69 | StringRef Tok = next(); |
Davide Italiano | 10d268d | 2015-10-13 20:48:56 +0000 | [diff] [blame] | 70 | if (Tok == ";") |
| 71 | continue; |
Denis Protivensky | 90c5099 | 2015-10-08 06:48:38 +0000 | [diff] [blame] | 72 | if (Tok == "ENTRY") { |
| 73 | readEntry(); |
George Rimar | 83f406c | 2015-10-19 17:35:12 +0000 | [diff] [blame] | 74 | } else if (Tok == "EXTERN") { |
| 75 | readExtern(); |
Rui Ueyama | 00f9727 | 2015-10-11 01:31:57 +0000 | [diff] [blame] | 76 | } else if (Tok == "GROUP" || Tok == "INPUT") { |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 77 | readGroup(); |
Rui Ueyama | 31aa1f8 | 2015-10-11 01:31:55 +0000 | [diff] [blame] | 78 | } else if (Tok == "INCLUDE") { |
| 79 | readInclude(); |
Rui Ueyama | ee59282 | 2015-10-07 00:25:09 +0000 | [diff] [blame] | 80 | } else if (Tok == "OUTPUT") { |
| 81 | readOutput(); |
Davide Italiano | 9159ce9 | 2015-10-12 21:50:08 +0000 | [diff] [blame] | 82 | } else if (Tok == "OUTPUT_ARCH") { |
| 83 | readOutputArch(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 84 | } else if (Tok == "OUTPUT_FORMAT") { |
| 85 | readOutputFormat(); |
Davide Italiano | 68a39a6 | 2015-10-08 17:51:41 +0000 | [diff] [blame] | 86 | } else if (Tok == "SEARCH_DIR") { |
| 87 | readSearchDir(); |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 88 | } else if (Tok == "SECTIONS") { |
| 89 | readSections(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 90 | } else { |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 91 | setError("unknown directive: " + Tok); |
| 92 | return; |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 97 | // We don't want to record cascading errors. Keep only the first one. |
| 98 | void LinkerScript::setError(const Twine &Msg) { |
| 99 | if (Error) |
| 100 | return; |
| 101 | error(Msg); |
| 102 | Error = true; |
| 103 | } |
| 104 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 105 | // Split S into linker script tokens. |
| 106 | std::vector<StringRef> LinkerScript::tokenize(StringRef S) { |
| 107 | std::vector<StringRef> Ret; |
| 108 | for (;;) { |
| 109 | S = skipSpace(S); |
| 110 | if (S.empty()) |
| 111 | return Ret; |
| 112 | |
| 113 | // Quoted token |
| 114 | if (S.startswith("\"")) { |
| 115 | size_t E = S.find("\"", 1); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 116 | if (E == StringRef::npos) { |
| 117 | error("unclosed quote"); |
| 118 | return {}; |
| 119 | } |
Pete Cooper | 6025933 | 2016-01-22 23:46:37 +0000 | [diff] [blame] | 120 | Ret.push_back(S.substr(1, E - 1)); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 121 | S = S.substr(E + 1); |
| 122 | continue; |
| 123 | } |
| 124 | |
| 125 | // Unquoted token |
| 126 | size_t Pos = S.find_first_not_of( |
| 127 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 128 | "0123456789_.$/\\~=+[]*?-:"); |
| 129 | // A character that cannot start a word (which is usually a |
| 130 | // punctuation) forms a single character token. |
| 131 | if (Pos == 0) |
| 132 | Pos = 1; |
| 133 | Ret.push_back(S.substr(0, Pos)); |
| 134 | S = S.substr(Pos); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Skip leading whitespace characters or /**/-style comments. |
| 139 | StringRef LinkerScript::skipSpace(StringRef S) { |
| 140 | for (;;) { |
| 141 | if (S.startswith("/*")) { |
| 142 | size_t E = S.find("*/", 2); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 143 | if (E == StringRef::npos) { |
| 144 | error("unclosed comment in a linker script"); |
| 145 | return ""; |
| 146 | } |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 147 | S = S.substr(E + 2); |
| 148 | continue; |
| 149 | } |
| 150 | size_t Size = S.size(); |
| 151 | S = S.ltrim(); |
| 152 | if (S.size() == Size) |
| 153 | return S; |
| 154 | } |
| 155 | } |
| 156 | |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 157 | // An errneous token is handled as if it were the last token before EOF. |
| 158 | bool LinkerScript::atEOF() { return Error || Tokens.size() == Pos; } |
| 159 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 160 | StringRef LinkerScript::next() { |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 161 | if (Error) |
| 162 | return ""; |
| 163 | if (atEOF()) { |
| 164 | setError("unexpected EOF"); |
| 165 | return ""; |
| 166 | } |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 167 | return Tokens[Pos++]; |
| 168 | } |
| 169 | |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 170 | bool LinkerScript::skip(StringRef Tok) { |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 171 | if (Error) |
| 172 | return false; |
| 173 | if (atEOF()) { |
| 174 | setError("unexpected EOF"); |
| 175 | return false; |
| 176 | } |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 177 | if (Tok != Tokens[Pos]) |
| 178 | return false; |
| 179 | ++Pos; |
| 180 | return true; |
| 181 | } |
| 182 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 183 | void LinkerScript::expect(StringRef Expect) { |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 184 | if (Error) |
| 185 | return; |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 186 | StringRef Tok = next(); |
| 187 | if (Tok != Expect) |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 188 | setError(Expect + " expected, but got " + Tok); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 191 | void LinkerScript::addFile(StringRef S) { |
Simon Atanasyan | 16b0cc9 | 2015-11-26 05:53:00 +0000 | [diff] [blame] | 192 | if (IsUnderSysroot && S.startswith("/")) { |
| 193 | SmallString<128> Path; |
| 194 | (Config->Sysroot + S).toStringRef(Path); |
| 195 | if (sys::fs::exists(Path)) { |
| 196 | Driver->addFile(Saver.save(Path.str())); |
| 197 | return; |
| 198 | } |
| 199 | } |
| 200 | |
Rui Ueyama | f03f3cc | 2015-10-13 00:09:21 +0000 | [diff] [blame] | 201 | if (sys::path::is_absolute(S)) { |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 202 | Driver->addFile(S); |
| 203 | } else if (S.startswith("=")) { |
| 204 | if (Config->Sysroot.empty()) |
| 205 | Driver->addFile(S.substr(1)); |
| 206 | else |
| 207 | Driver->addFile(Saver.save(Config->Sysroot + "/" + S.substr(1))); |
| 208 | } else if (S.startswith("-l")) { |
Rui Ueyama | 21eecb4 | 2016-02-02 21:13:09 +0000 | [diff] [blame^] | 209 | Driver->addLibrary(S.substr(2)); |
Simon Atanasyan | a1b8fc3 | 2015-11-26 20:23:46 +0000 | [diff] [blame] | 210 | } else if (sys::fs::exists(S)) { |
| 211 | Driver->addFile(S); |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 212 | } else { |
| 213 | std::string Path = findFromSearchPaths(S); |
| 214 | if (Path.empty()) |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 215 | setError("Unable to find " + S); |
| 216 | else |
| 217 | Driver->addFile(Saver.save(Path)); |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 221 | void LinkerScript::readAsNeeded() { |
| 222 | expect("("); |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 223 | bool Orig = Config->AsNeeded; |
| 224 | Config->AsNeeded = true; |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 225 | while (!Error) { |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 226 | StringRef Tok = next(); |
| 227 | if (Tok == ")") |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 228 | break; |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 229 | addFile(Tok); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 230 | } |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 231 | Config->AsNeeded = Orig; |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Denis Protivensky | 90c5099 | 2015-10-08 06:48:38 +0000 | [diff] [blame] | 234 | void LinkerScript::readEntry() { |
| 235 | // -e <symbol> takes predecence over ENTRY(<symbol>). |
| 236 | expect("("); |
| 237 | StringRef Tok = next(); |
| 238 | if (Config->Entry.empty()) |
| 239 | Config->Entry = Tok; |
| 240 | expect(")"); |
| 241 | } |
| 242 | |
George Rimar | 83f406c | 2015-10-19 17:35:12 +0000 | [diff] [blame] | 243 | void LinkerScript::readExtern() { |
| 244 | expect("("); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 245 | while (!Error) { |
George Rimar | 83f406c | 2015-10-19 17:35:12 +0000 | [diff] [blame] | 246 | StringRef Tok = next(); |
| 247 | if (Tok == ")") |
| 248 | return; |
| 249 | Config->Undefined.push_back(Tok); |
| 250 | } |
| 251 | } |
| 252 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 253 | void LinkerScript::readGroup() { |
| 254 | expect("("); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 255 | while (!Error) { |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 256 | StringRef Tok = next(); |
| 257 | if (Tok == ")") |
| 258 | return; |
| 259 | if (Tok == "AS_NEEDED") { |
| 260 | readAsNeeded(); |
| 261 | continue; |
| 262 | } |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 263 | addFile(Tok); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Rui Ueyama | 31aa1f8 | 2015-10-11 01:31:55 +0000 | [diff] [blame] | 267 | void LinkerScript::readInclude() { |
| 268 | StringRef Tok = next(); |
| 269 | auto MBOrErr = MemoryBuffer::getFile(Tok); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 270 | if (!MBOrErr) { |
| 271 | setError("cannot open " + Tok); |
| 272 | return; |
| 273 | } |
Rui Ueyama | 31aa1f8 | 2015-10-11 01:31:55 +0000 | [diff] [blame] | 274 | std::unique_ptr<MemoryBuffer> &MB = *MBOrErr; |
Rui Ueyama | a47ee68 | 2015-10-11 01:53:04 +0000 | [diff] [blame] | 275 | StringRef S = Saver.save(MB->getMemBufferRef().getBuffer()); |
| 276 | std::vector<StringRef> V = tokenize(S); |
Rui Ueyama | 31aa1f8 | 2015-10-11 01:31:55 +0000 | [diff] [blame] | 277 | Tokens.insert(Tokens.begin() + Pos, V.begin(), V.end()); |
Rui Ueyama | 31aa1f8 | 2015-10-11 01:31:55 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Rui Ueyama | ee59282 | 2015-10-07 00:25:09 +0000 | [diff] [blame] | 280 | void LinkerScript::readOutput() { |
| 281 | // -o <file> takes predecence over OUTPUT(<file>). |
| 282 | expect("("); |
| 283 | StringRef Tok = next(); |
| 284 | if (Config->OutputFile.empty()) |
| 285 | Config->OutputFile = Tok; |
| 286 | expect(")"); |
| 287 | } |
| 288 | |
Davide Italiano | 9159ce9 | 2015-10-12 21:50:08 +0000 | [diff] [blame] | 289 | void LinkerScript::readOutputArch() { |
| 290 | // Error checking only for now. |
| 291 | expect("("); |
| 292 | next(); |
| 293 | expect(")"); |
| 294 | } |
| 295 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 296 | void LinkerScript::readOutputFormat() { |
| 297 | // Error checking only for now. |
| 298 | expect("("); |
| 299 | next(); |
Davide Italiano | 6836c61 | 2015-10-12 21:08:41 +0000 | [diff] [blame] | 300 | StringRef Tok = next(); |
| 301 | if (Tok == ")") |
| 302 | return; |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 303 | if (Tok != ",") { |
| 304 | setError("unexpected token: " + Tok); |
| 305 | return; |
| 306 | } |
Davide Italiano | 6836c61 | 2015-10-12 21:08:41 +0000 | [diff] [blame] | 307 | next(); |
| 308 | expect(","); |
| 309 | next(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 310 | expect(")"); |
| 311 | } |
| 312 | |
Davide Italiano | 68a39a6 | 2015-10-08 17:51:41 +0000 | [diff] [blame] | 313 | void LinkerScript::readSearchDir() { |
| 314 | expect("("); |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 315 | Config->SearchPaths.push_back(next()); |
Davide Italiano | 68a39a6 | 2015-10-08 17:51:41 +0000 | [diff] [blame] | 316 | expect(")"); |
| 317 | } |
| 318 | |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 319 | void LinkerScript::readSections() { |
| 320 | expect("{"); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 321 | while (!Error && !skip("}")) |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 322 | readOutputSectionDescription(); |
| 323 | } |
| 324 | |
| 325 | void LinkerScript::readOutputSectionDescription() { |
| 326 | StringRef Name = next(); |
| 327 | std::vector<StringRef> &InputSections = Config->OutputSections[Name]; |
| 328 | |
| 329 | expect(":"); |
| 330 | expect("{"); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 331 | while (!Error && !skip("}")) { |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 332 | next(); // Skip input file name. |
| 333 | expect("("); |
Rui Ueyama | 025d59b | 2016-02-02 20:27:59 +0000 | [diff] [blame] | 334 | while (!Error && !skip(")")) |
Denis Protivensky | 8e3b38a | 2015-11-12 09:52:08 +0000 | [diff] [blame] | 335 | InputSections.push_back(next()); |
| 336 | } |
| 337 | } |
| 338 | |
Simon Atanasyan | 16b0cc9 | 2015-11-26 05:53:00 +0000 | [diff] [blame] | 339 | static bool isUnderSysroot(StringRef Path) { |
| 340 | if (Config->Sysroot == "") |
| 341 | return false; |
| 342 | for (; !Path.empty(); Path = sys::path::parent_path(Path)) |
| 343 | if (sys::fs::equivalent(Config->Sysroot, Path)) |
| 344 | return true; |
| 345 | return false; |
| 346 | } |
| 347 | |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 348 | // Entry point. The other functions or classes are private to this file. |
Rui Ueyama | 83cd6e0 | 2016-01-06 20:11:55 +0000 | [diff] [blame] | 349 | void elf2::readLinkerScript(BumpPtrAllocator *A, MemoryBufferRef MB) { |
Simon Atanasyan | 16b0cc9 | 2015-11-26 05:53:00 +0000 | [diff] [blame] | 350 | StringRef Path = MB.getBufferIdentifier(); |
| 351 | LinkerScript(A, MB.getBuffer(), isUnderSysroot(Path)).run(); |
Rui Ueyama | f7c5fbb | 2015-09-30 17:23:26 +0000 | [diff] [blame] | 352 | } |