diff --git a/linker_script.cc b/linker_script.cc index f62afdb5..7fc8e2d7 100644 --- a/linker_script.cc +++ b/linker_script.cc @@ -6,6 +6,7 @@ #include "mold.h" static thread_local std::string script_dir; +static thread_local std::string current_file; static std::vector tokenize(std::string_view input) { std::vector vec; @@ -18,7 +19,7 @@ static std::vector tokenize(std::string_view input) { if (input.starts_with("/*")) { i64 pos = input.find("*/", 2); if (pos == std::string_view::npos) - Fatal() << "unclosed comment"; + Fatal() << current_file << ": unclosed comment"; input = input.substr(pos + 2); continue; } @@ -34,7 +35,7 @@ static std::vector tokenize(std::string_view input) { if (input[0] == '"') { i64 pos = input.find('"', 1); if (pos == std::string_view::npos) - Fatal() << "unclosed string literal"; + Fatal() << current_file << ": unclosed string literal"; vec.push_back(input.substr(0, pos)); input = input.substr(pos); continue; @@ -55,7 +56,7 @@ static std::vector tokenize(std::string_view input) { static std::span skip(std::span tok, std::string_view str) { if (tok.empty() || tok[0] != str) - Fatal() << "expected '" << str << "'"; + Fatal() << current_file << ": expected '" << str << "'"; return tok.subspan(1); } @@ -64,7 +65,7 @@ static std::span read_output_format(std::span @@ -102,11 +103,12 @@ read_group(std::span tok, ReadContext &ctx) { } if (tok.empty()) - Fatal() << "expected ')'"; + Fatal() << current_file << ": expected ')'"; return tok.subspan(1); } void parse_linker_script(MemoryMappedFile *mb, ReadContext &ctx) { + current_file = mb->name; script_dir = mb->name.substr(0, mb->name.find_last_of('/')); std::vector vec = tokenize(mb->get_contents()); @@ -118,11 +120,12 @@ void parse_linker_script(MemoryMappedFile *mb, ReadContext &ctx) { else if (tok[0] == "INPUT" || tok[0] == "GROUP") tok = read_group(tok.subspan(1), ctx); else - Fatal() << mb->name << ": unknown token: " << tok[0]; + Fatal() << current_file << ": unknown token: " << tok[0]; } } void parse_version_script(std::string path) { + current_file = path; script_dir = path.substr(0, path.find_last_of('/')); MemoryMappedFile *mb = MemoryMappedFile::must_open(path); @@ -167,10 +170,10 @@ void parse_version_script(std::string path) { tok = skip(tok, ";"); if (!tok.empty()) - Fatal() << path << ": trailing garbage token: " << tok[0]; + Fatal() << current_file << ": trailing garbage token: " << tok[0]; if (locals.size() != 1 || locals[0] != "*") - Fatal() << path << ": unsupported version script"; + Fatal() << current_file << ": unsupported version script"; config.export_dynamic = false; config.globals = globals; }