mirror of
https://github.com/rui314/mold.git
synced 2026-11-09 04:49:33 -10:00
Handle -C and --chroot early
We read version script files in cmdline.cc, so we need to handle -C and --chroot early. Otherwise, a version script passed by command line can cause a "file not found" error.
This commit is contained in:
1 parent
aeb1041f1a
commit
6d6a128bf9
2 files changed
+13
-13
No files matched your search
+13
-8
@@ -1460,6 +1460,19 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx.arg.chroot.empty()) {
|
||||
if (!ctx.arg.Map.empty())
|
||||
ctx.arg.Map = ctx.arg.chroot + "/" + ctx.arg.Map;
|
||||
|
||||
if (!ctx.arg.dependency_file.empty())
|
||||
ctx.arg.dependency_file = ctx.arg.chroot + "/" + ctx.arg.dependency_file;
|
||||
}
|
||||
|
||||
if (!ctx.arg.directory.empty())
|
||||
if (chdir(ctx.arg.directory.c_str()) == -1)
|
||||
Fatal(ctx) << "chdir failed: " << ctx.arg.directory
|
||||
<< ": " << errno_string();
|
||||
|
||||
if (!ctx.arg.sysroot.empty()) {
|
||||
for (std::string &path : ctx.arg.library_paths) {
|
||||
if (std::string_view(path).starts_with('='))
|
||||
@@ -1623,14 +1636,6 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
|
||||
// object file.
|
||||
ctx.overwrite_output_file = (!ctx.arg.shared && returns_etxtbsy());
|
||||
|
||||
if (!ctx.arg.chroot.empty()) {
|
||||
if (!ctx.arg.Map.empty())
|
||||
ctx.arg.Map = ctx.arg.chroot + "/" + ctx.arg.Map;
|
||||
|
||||
if (!ctx.arg.dependency_file.empty())
|
||||
ctx.arg.dependency_file = ctx.arg.chroot + "/" + ctx.arg.dependency_file;
|
||||
}
|
||||
|
||||
// Mark GC root symbols
|
||||
for (Symbol<E> *sym : ctx.arg.undefined)
|
||||
sym->gc_root = true;
|
||||
|
||||
@@ -302,11 +302,6 @@ int mold_main(int argc, char **argv) {
|
||||
|
||||
install_signal_handler();
|
||||
|
||||
if (!ctx.arg.directory.empty())
|
||||
if (chdir(ctx.arg.directory.c_str()) == -1)
|
||||
Fatal(ctx) << "chdir failed: " << ctx.arg.directory
|
||||
<< ": " << errno_string();
|
||||
|
||||
// Fork a subprocess unless --no-fork is given.
|
||||
if (ctx.arg.fork)
|
||||
fork_child<E>();
|
||||
|
||||
Reference in new issue
Block a user