1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-27 10:23:41 +03:00

Add -Bstatic and -Bdynamic

This commit is contained in:
Rui Ueyama 2021-03-16 21:57:28 +09:00
parent 73f1e755e0
commit a96bd43246
4 changed files with 25 additions and 11 deletions

View File

@ -222,8 +222,12 @@ void parse_nonpositional_args(std::span<std::string_view> args,
config.print_map = true;
} else if (read_flag(args, "print-map") || read_flag(args, "M")) {
config.print_map = true;
} else if (read_flag(args, "static")) {
} else if (read_flag(args, "static") || read_flag(args, "Bstatic")) {
config.is_static = true;
remaining.push_back("-Bstatic");
} else if (read_flag(args, "Bdynamic")) {
config.is_static = false;
remaining.push_back("-Bdynamic");
} else if (read_flag(args, "shared") || read_flag(args, "Bshareable")) {
config.shared = true;
} else if (read_flag(args, "demangle")) {

View File

@ -76,12 +76,12 @@ static std::span<std::string_view> read_output_format(std::span<std::string_view
return tok.subspan(1);
}
static MemoryMappedFile *resolve_path(std::string str) {
static MemoryMappedFile *resolve_path(std::string str, ReadContext &ctx) {
if (str.starts_with("/"))
return MemoryMappedFile::must_open(config.sysroot + str);
if (str.starts_with("-l"))
return find_library(str.substr(2), config.library_paths);
return find_library(str.substr(2), config.library_paths, ctx);
if (std::string path = path_dirname(current_file) + "/";
MemoryMappedFile *mb = MemoryMappedFile::open(path + str))
@ -113,7 +113,8 @@ read_group(std::span<std::string_view> tok, ReadContext &ctx) {
continue;
}
read_file(resolve_path(std::string(unquote(tok[0]))), ctx);
MemoryMappedFile *mb = resolve_path(std::string(unquote(tok[0])), ctx);
read_file(mb, ctx);
tok = tok.subspan(1);
}

19
main.cc
View File

@ -983,11 +983,12 @@ static void signal_handler(int) {
}
MemoryMappedFile *find_library(std::string name,
std::span<std::string_view> lib_paths) {
std::span<std::string_view> lib_paths,
ReadContext &ctx) {
for (std::string_view dir : lib_paths) {
std::string root = dir.starts_with("/") ? config.sysroot : "";
std::string stem = root + std::string(dir) + "/lib" + name;
if (!config.is_static)
if (!ctx.is_static)
if (MemoryMappedFile *mb = MemoryMappedFile::open(stem + ".so"))
return mb;
if (MemoryMappedFile *mb = MemoryMappedFile::open(stem + ".a"))
@ -998,7 +999,7 @@ MemoryMappedFile *find_library(std::string name,
static void read_input_files(std::span<std::string_view> args,
ReadContext &ctx) {
std::vector<std::tuple<bool, bool>> state;
std::vector<std::tuple<bool, bool, bool>> state;
while (!args.empty()) {
std::string_view arg;
@ -1011,15 +1012,21 @@ static void read_input_files(std::span<std::string_view> args,
ctx.whole_archive = true;
} else if (read_flag(args, "no-whole-archive")) {
ctx.whole_archive = false;
} else if (read_flag(args, "Bstatic")) {
ctx.is_static = true;
} else if (read_flag(args, "Bdynamic")) {
ctx.is_static = false;
} else if (read_flag(args, "push-state")) {
state.push_back({ctx.as_needed, ctx.whole_archive});
state.push_back({ctx.as_needed, ctx.whole_archive, ctx.is_static});
} else if (read_flag(args, "pop-state")) {
if (state.empty())
Fatal() << "no state pushed before popping";
std::tie(ctx.as_needed, ctx.whole_archive) = state.back();
std::tie(ctx.as_needed, ctx.whole_archive, ctx.is_static) = state.back();
state.pop_back();
} else if (read_arg(args, arg, "l")) {
read_file(find_library(std::string(arg), config.library_paths), ctx);
MemoryMappedFile *mb =
find_library(std::string(arg), config.library_paths, ctx);
read_file(mb, ctx);
} else {
read_file(MemoryMappedFile::must_open(std::string(args[0])), ctx);
args = args.subspan(1);

4
mold.h
View File

@ -1207,12 +1207,14 @@ public:
bool as_needed = false;
bool whole_archive = false;
bool is_preloading = false;
bool is_static = config.is_static;
std::unordered_set<std::string_view> visited;
tbb::task_group tg;
};
MemoryMappedFile *find_library(std::string path,
std::span<std::string_view> lib_paths);
std::span<std::string_view> lib_paths,
ReadContext &ctx);
void read_file(MemoryMappedFile *mb, ReadContext &ctx);