mirror of
https://github.com/rui314/mold.git
synced 2024-12-25 17:34:02 +03:00
temporary
This commit is contained in:
parent
67dd2cd365
commit
e9f015e52f
14
main.cc
14
main.cc
@ -140,6 +140,16 @@ static std::vector<ArrayRef<T>> split(const std::vector<T> &input, int unit) {
|
||||
return vec;
|
||||
}
|
||||
|
||||
static void eliminate_comdats(std::vector<ObjectFile *> &files) {
|
||||
tbb::parallel_for_each(files, [](ObjectFile *file) {
|
||||
file->resolve_comdat_groups();
|
||||
});
|
||||
|
||||
tbb::parallel_for_each(files, [](ObjectFile *file) {
|
||||
file->eliminate_duplicate_comdat_groups();
|
||||
});
|
||||
}
|
||||
|
||||
static void handle_mergeable_strings(std::vector<ObjectFile *> &files) {
|
||||
// Resolve mergeable string pieces
|
||||
tbb::parallel_for_each(files, [](ObjectFile *file) {
|
||||
@ -778,9 +788,7 @@ int main(int argc, char **argv) {
|
||||
// Eliminate duplicate comdat groups.
|
||||
{
|
||||
MyTimer t("comdat", before_copy);
|
||||
tbb::parallel_for_each(files, [](ObjectFile *file) {
|
||||
file->eliminate_duplicate_comdat_groups();
|
||||
});
|
||||
eliminate_comdats(files);
|
||||
}
|
||||
|
||||
// Resolve mergeable strings
|
||||
|
2
mold.h
2
mold.h
@ -557,7 +557,6 @@ struct ComdatGroup {
|
||||
ComdatGroup(const ComdatGroup &other)
|
||||
: file(other.file.load()), section_idx(other.section_idx) {}
|
||||
|
||||
tbb::spin_mutex mu;
|
||||
std::atomic<ObjectFile *> file;
|
||||
u32 section_idx;
|
||||
};
|
||||
@ -571,6 +570,7 @@ public:
|
||||
void resolve_symbols();
|
||||
void mark_live_archive_members(tbb::parallel_do_feeder<ObjectFile *> &feeder);
|
||||
void hanlde_undefined_weak_symbols();
|
||||
void resolve_comdat_groups();
|
||||
void eliminate_duplicate_comdat_groups();
|
||||
void assign_mergeable_string_offsets();
|
||||
void convert_common_symbols();
|
||||
|
@ -408,40 +408,22 @@ void ObjectFile::hanlde_undefined_weak_symbols() {
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectFile::resolve_comdat_groups() {
|
||||
for (auto &pair : comdat_groups) {
|
||||
ComdatGroup *group = pair.first;
|
||||
ObjectFile *cur = group->file;
|
||||
while (!cur || cur->priority > this->priority)
|
||||
if (group->file.compare_exchange_strong(cur, this))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectFile::eliminate_duplicate_comdat_groups() {
|
||||
for (auto &pair : comdat_groups) {
|
||||
ComdatGroup *g = pair.first;
|
||||
ComdatGroup *group = pair.first;
|
||||
u32 section_idx = pair.second;
|
||||
|
||||
ObjectFile *other = g->file;
|
||||
if (other && other->priority < this->priority) {
|
||||
this->remove_comdat_members(section_idx);
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjectFile *file;
|
||||
u32 idx;
|
||||
|
||||
{
|
||||
std::lock_guard lock(g->mu);
|
||||
if (g->file == nullptr) {
|
||||
g->file = this;
|
||||
g->section_idx = section_idx;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g->file.load()->priority < this->priority) {
|
||||
file = this;
|
||||
idx = section_idx;
|
||||
} else {
|
||||
file = g->file;
|
||||
idx = g->section_idx;
|
||||
g->file = this;
|
||||
g->section_idx = section_idx;
|
||||
}
|
||||
}
|
||||
|
||||
file->remove_comdat_members(idx);
|
||||
if (group->file != this)
|
||||
remove_comdat_members(section_idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user