diff --git a/archive-file.h b/archive-file.h index 7108c7262a..496aa81ed6 100644 --- a/archive-file.h +++ b/archive-file.h @@ -93,6 +93,7 @@ read_thin_archive_members(C &ctx, MappedFile *mf) { std::string path = name.starts_with('/') ? name : (filepath(mf->name).parent_path() / name).string(); vec.push_back(MappedFile::must_open(ctx, path)); + vec.back()->thin_parent = mf; data = body; } return vec; diff --git a/elf/main.cc b/elf/main.cc index 27b5dc95bb..c910b5c02c 100644 --- a/elf/main.cc +++ b/elf/main.cc @@ -45,6 +45,7 @@ static ObjectFile *new_lto_obj(Context &ctx, MappedFile> *mf, ObjectFile *file = read_lto_object(ctx, mf); file->priority = ctx.file_priority++; + file->archive_name = archive_name; file->is_in_lib = ctx.in_lib || (!archive_name.empty() && !ctx.whole_archive); file->is_alive = !file->is_in_lib; ctx.has_lto_object = true; diff --git a/mold.h b/mold.h index 7c6f9feba7..a0e8166e62 100644 --- a/mold.h +++ b/mold.h @@ -590,6 +590,12 @@ class MappedFile { // because archive members may have the same name. return parent->name + ":" + std::to_string(get_offset()); } + + if (thin_parent) { + // If this is a thin archive member, the filename part is + // guaranteed to be unique. + return thin_parent->name + ":" + name; + } return name; } @@ -599,6 +605,7 @@ class MappedFile { i64 mtime = 0; bool given_fullpath = true; MappedFile *parent = nullptr; + MappedFile *thin_parent = nullptr; int fd = -1; };