1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-12 23:48:51 +03:00
This commit is contained in:
Rui Ueyama 2022-05-30 13:30:24 +08:00
parent 2f78d2eb94
commit 348f2bb9da
6 changed files with 24 additions and 17 deletions

View File

@ -145,7 +145,7 @@ void Subsection<E>::scan_relocations(Context<E> &ctx) {
continue;
if (sym->is_imported && sym->file->is_dylib)
((DylibFile<E> *)sym->file)->is_needed = true;
((DylibFile<E> *)sym->file)->is_alive = true;
switch (r.type) {
case ARM64_RELOC_UNSIGNED:

View File

@ -139,7 +139,7 @@ void Subsection<E>::scan_relocations(Context<E> &ctx) {
continue;
if (sym->is_imported && sym->file->is_dylib)
((DylibFile<E> *)sym->file)->is_needed = true;
((DylibFile<E> *)sym->file)->is_alive = true;
switch (r.type) {
case X86_64_RELOC_UNSIGNED:

View File

@ -671,7 +671,7 @@ void ObjectFile<E>::parse_lto_symbols(Context<E> &ctx) {
template <typename E>
DylibFile<E> *DylibFile<E>::create(Context<E> &ctx, MappedFile<Context<E>> *mf) {
DylibFile<E> *dylib = new DylibFile<E>(mf);
dylib->is_needed = (ctx.needed_l || !ctx.arg.dead_strip_dylibs);
dylib->is_alive = (ctx.needed_l || !ctx.arg.dead_strip_dylibs);
ctx.dylib_pool.emplace_back(dylib);
return dylib;
};

View File

@ -127,6 +127,8 @@ void do_lto(Context<E> &ctx) {
}
}
std::erase_if(ctx.objs, [](InputFile<E> *file) { return !file->is_alive; });
// Add a result of LTO as a new object file.
MappedFile<Context<E>> *mf = new MappedFile<Context<E>>;
mf->name = "<LTO>";

View File

@ -36,11 +36,14 @@ template <typename E>
static void resolve_symbols(Context<E> &ctx) {
Timer t(ctx, "resolve_symbols");
std::vector<InputFile<E> *> files;
append(files, ctx.objs);
append(files, ctx.dylibs);
auto for_each_file = [&](std::function<void(InputFile<E> *)> fn) {
tbb::parallel_for_each(ctx.objs, fn);
tbb::parallel_for_each(ctx.dylibs, fn);
};
for (InputFile<E> *file : files)
for (InputFile<E> *file : ctx.objs)
file->resolve_symbols(ctx);
for (InputFile<E> *file : ctx.dylibs)
file->resolve_symbols(ctx);
std::vector<ObjectFile<E> *> live_objs;
@ -54,7 +57,18 @@ static void resolve_symbols(Context<E> &ctx) {
});
}
for (InputFile<E> *file : files)
// Remove symbols of eliminated files.
for_each_file([&](InputFile<E> *file) {
if (!file->is_alive)
file->clear_symbols();
});
std::erase_if(ctx.objs, [](InputFile<E> *file) { return !file->is_alive; });
std::erase_if(ctx.dylibs, [](InputFile<E> *file) { return !file->is_alive; });
for (InputFile<E> *file : ctx.objs)
file->resolve_symbols(ctx);
for (InputFile<E> *file : ctx.dylibs)
file->resolve_symbols(ctx);
if (has_lto_obj(ctx))
@ -689,9 +703,6 @@ static int do_main(int argc, char **argv) {
create_internal_file(ctx);
std::erase_if(ctx.objs, [](ObjectFile<E> *file) { return !file->is_alive; });
std::erase_if(ctx.dylibs, [](DylibFile<E> *file) { return !file->is_alive; });
if (ctx.arg.trace) {
for (ObjectFile<E> *file : ctx.objs)
SyncOut(ctx) << *file;
@ -723,10 +734,6 @@ static int do_main(int argc, char **argv) {
subsec->scan_relocations(ctx);
scan_unwind_info(ctx);
if (ctx.arg.dead_strip_dylibs)
std::erase_if(ctx.dylibs, [](DylibFile<E> *file) { return !file->is_needed; });
export_symbols(ctx);
i64 output_size = assign_offsets(ctx);

View File

@ -158,7 +158,6 @@ public:
std::string_view install_name;
i64 dylib_idx = 0;
std::atomic_bool is_needed = false;
private:
void parse_dylib(Context<E> &ctx);
@ -167,7 +166,6 @@ private:
DylibFile(MappedFile<Context<E>> *mf) : InputFile<E>(mf) {
this->is_dylib = true;
this->is_alive = true;
}
};