mirror of
https://github.com/rui314/mold.git
synced 2024-11-11 05:46:58 +03:00
wip
This commit is contained in:
parent
35ab5ff089
commit
bac66c1304
@ -106,9 +106,10 @@ read_group(std::span<std::string_view> tok, ReadContext &ctx) {
|
||||
|
||||
while (!tok.empty() && tok[0] != ")") {
|
||||
if (tok[0] == "AS_NEEDED") {
|
||||
ReadContext ctx2 = ctx;
|
||||
ctx2.as_needed = true;
|
||||
tok = read_group(tok.subspan(1), ctx2);
|
||||
bool orig = ctx.as_needed;
|
||||
ctx.as_needed = true;
|
||||
tok = read_group(tok.subspan(1), ctx);
|
||||
ctx.as_needed = orig;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
36
main.cc
36
main.cc
@ -6,12 +6,8 @@
|
||||
#include <tbb/global_control.h>
|
||||
#include <tbb/parallel_do.h>
|
||||
#include <tbb/parallel_for_each.h>
|
||||
#include <tbb/task_group.h>
|
||||
#include <unordered_set>
|
||||
|
||||
static tbb::task_group parser_tg;
|
||||
static bool preloading;
|
||||
|
||||
i64 BuildId::size() const {
|
||||
switch (kind) {
|
||||
case HEX:
|
||||
@ -58,13 +54,13 @@ static ObjectFile *new_object_file(MemoryMappedFile *mb,
|
||||
ReadContext &ctx) {
|
||||
bool in_lib = (!archive_name.empty() && !ctx.whole_archive);
|
||||
ObjectFile *file = new ObjectFile(mb, archive_name, in_lib);
|
||||
parser_tg.run([=]() { file->parse(); });
|
||||
ctx.tg.run([=]() { file->parse(); });
|
||||
return file;
|
||||
}
|
||||
|
||||
static SharedFile *new_shared_file(MemoryMappedFile *mb, bool as_needed) {
|
||||
SharedFile *file = new SharedFile(mb, as_needed);
|
||||
parser_tg.run([=]() { file->parse(); });
|
||||
static SharedFile *new_shared_file(MemoryMappedFile *mb, ReadContext &ctx) {
|
||||
SharedFile *file = new SharedFile(mb, ctx.as_needed);
|
||||
ctx.tg.run([=]() { file->parse(); });
|
||||
return file;
|
||||
}
|
||||
|
||||
@ -97,13 +93,13 @@ void read_file(MemoryMappedFile *mb, ReadContext &ctx) {
|
||||
static FileCache<ObjectFile> obj_cache;
|
||||
static FileCache<SharedFile> dso_cache;
|
||||
|
||||
if (preloading) {
|
||||
if (ctx.is_preloading) {
|
||||
switch (get_file_type(mb)) {
|
||||
case FileType::OBJ:
|
||||
obj_cache.store(mb, new_object_file(mb, "", ctx));
|
||||
return;
|
||||
case FileType::DSO:
|
||||
dso_cache.store(mb, new_shared_file(mb, ctx.as_needed));
|
||||
dso_cache.store(mb, new_shared_file(mb, ctx));
|
||||
return;
|
||||
case FileType::AR:
|
||||
for (MemoryMappedFile *child : read_fat_archive_members(mb))
|
||||
@ -131,7 +127,7 @@ void read_file(MemoryMappedFile *mb, ReadContext &ctx) {
|
||||
if (SharedFile *obj = dso_cache.get_one(mb))
|
||||
out::dsos.push_back(obj);
|
||||
else
|
||||
out::dsos.push_back(new_shared_file(mb, ctx.as_needed));
|
||||
out::dsos.push_back(new_shared_file(mb, ctx));
|
||||
return;
|
||||
case FileType::AR:
|
||||
if (std::vector<ObjectFile *> objs = obj_cache.get(mb); !objs.empty()) {
|
||||
@ -932,9 +928,8 @@ MemoryMappedFile *find_library(std::string name,
|
||||
Fatal() << "library not found: " << name;
|
||||
}
|
||||
|
||||
static void read_input_files(std::span<std::string_view> args) {
|
||||
ReadContext ctx;
|
||||
|
||||
static void read_input_files(std::span<std::string_view> args,
|
||||
ReadContext &ctx) {
|
||||
while (!args.empty()) {
|
||||
std::string_view arg;
|
||||
|
||||
@ -953,7 +948,6 @@ static void read_input_files(std::span<std::string_view> args) {
|
||||
args = args.subspan(1);
|
||||
}
|
||||
}
|
||||
parser_tg.wait();
|
||||
}
|
||||
|
||||
static void show_stats() {
|
||||
@ -1003,8 +997,11 @@ int main(int argc, char **argv) {
|
||||
if (config.preload) {
|
||||
std::function<void()> wait_for_client;
|
||||
daemonize(argv, &wait_for_client, &on_complete);
|
||||
preloading = true;
|
||||
read_input_files(file_args);
|
||||
|
||||
ReadContext ctx(true);
|
||||
read_input_files(file_args, ctx);
|
||||
ctx.tg.wait();
|
||||
|
||||
wait_for_client();
|
||||
} else if (config.fork) {
|
||||
on_complete = fork_child();
|
||||
@ -1019,8 +1016,9 @@ int main(int argc, char **argv) {
|
||||
// Parse input files
|
||||
{
|
||||
Timer t("parse");
|
||||
preloading = false;
|
||||
read_input_files(file_args);
|
||||
ReadContext ctx(false);
|
||||
read_input_files(file_args, ctx);
|
||||
ctx.tg.wait();
|
||||
}
|
||||
|
||||
// Uniquify shared object files with soname
|
||||
|
25
mold.h
25
mold.h
@ -19,6 +19,7 @@
|
||||
#include <tbb/concurrent_hash_map.h>
|
||||
#include <tbb/enumerable_thread_specific.h>
|
||||
#include <tbb/spin_mutex.h>
|
||||
#include <tbb/task_group.h>
|
||||
#include <vector>
|
||||
|
||||
typedef uint8_t u8;
|
||||
@ -44,6 +45,7 @@ class MergedSection;
|
||||
class ObjectFile;
|
||||
class OutputChunk;
|
||||
class OutputSection;
|
||||
class ReadContext;
|
||||
class SharedFile;
|
||||
class Symbol;
|
||||
|
||||
@ -918,6 +920,9 @@ public:
|
||||
InputFile(MemoryMappedFile *mb);
|
||||
InputFile() : name("<internal>") {}
|
||||
|
||||
std::string_view get_string(const ElfShdr &shdr);
|
||||
std::string_view get_string(i64 idx);
|
||||
|
||||
MemoryMappedFile *mb;
|
||||
std::span<ElfShdr> elf_sections;
|
||||
std::vector<Symbol *> symbols;
|
||||
@ -927,9 +932,6 @@ public:
|
||||
u32 priority;
|
||||
std::atomic_bool is_alive = false;
|
||||
|
||||
std::string_view get_string(const ElfShdr &shdr);
|
||||
std::string_view get_string(i64 idx);
|
||||
|
||||
protected:
|
||||
template<typename T> std::span<T> get_data(const ElfShdr &shdr);
|
||||
template<typename T> std::span<T> get_data(i64 idx);
|
||||
@ -1040,11 +1042,6 @@ std::vector<MemoryMappedFile *> read_thin_archive_members(MemoryMappedFile *mb);
|
||||
// linker_script.cc
|
||||
//
|
||||
|
||||
struct ReadContext {
|
||||
bool as_needed = false;
|
||||
bool whole_archive = false;
|
||||
};
|
||||
|
||||
void parse_linker_script(MemoryMappedFile *mb, ReadContext &ctx);
|
||||
void parse_version_script(std::string path);
|
||||
void parse_dynamic_list(std::string path);
|
||||
@ -1182,6 +1179,18 @@ void parse_nonpositional_args(std::span<std::string_view> args,
|
||||
// main.cc
|
||||
//
|
||||
|
||||
class ReadContext {
|
||||
public:
|
||||
ReadContext(bool x) : is_preloading(x) {}
|
||||
|
||||
std::function<void(InputFile *)> parse;
|
||||
|
||||
bool as_needed = false;
|
||||
bool whole_archive = false;
|
||||
bool is_preloading = false;
|
||||
tbb::task_group tg;
|
||||
};
|
||||
|
||||
MemoryMappedFile *find_library(std::string path,
|
||||
std::span<std::string_view> lib_paths);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user