Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 7, 2024
1 parent 2e326cc commit 806d740
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1122,14 +1122,11 @@ void check_symbol_types(Context<E> &ctx) {
append(files, ctx.dsos);

auto canonicalize = [](u32 ty) -> u32 {
switch (ty) {
case STT_GNU_IFUNC:
if (ty == STT_GNU_IFUNC)
return STT_FUNC;
case STT_COMMON:
if (ty == STT_COMMON)
return STT_OBJECT;
default:
return ty;
}
return ty;
};

tbb::parallel_for_each(files.begin(), files.end(), [&](InputFile<E> *file) {
Expand Down Expand Up @@ -1196,19 +1193,21 @@ void sort_init_fini(Context<E> &ctx) {
if (ctx.arg.shuffle_sections == SHUFFLE_SECTIONS_REVERSE)
std::reverse(osec->members.begin(), osec->members.end());

std::unordered_map<InputSection<E> *, i64> map;
typedef std::pair<InputSection<E> *, i64> P;
std::vector<P> vec;

for (InputSection<E> *isec : osec->members) {
std::string_view name = isec->name();
if (name.starts_with(".ctors") || name.starts_with(".dtors"))
map.insert({isec, 65535 - get_ctor_dtor_priority(isec)});
vec.emplace_back(isec, 65535 - get_ctor_dtor_priority(isec));
else
map.insert({isec, get_init_fini_priority(isec)});
vec.emplace_back(isec, get_init_fini_priority(isec));
}

sort(osec->members, [&](InputSection<E> *a, InputSection<E> *b) {
return map[a] < map[b];
});
sort(vec, [&](const P &a, const P &b) { return a.second < b.second; });

for (i64 i = 0; i < vec.size(); i++)
osec->members[i] = vec[i].first;
}
}
}
Expand All @@ -1224,13 +1223,16 @@ void sort_ctor_dtor(Context<E> &ctx) {
if (ctx.arg.shuffle_sections != SHUFFLE_SECTIONS_REVERSE)
std::reverse(osec->members.begin(), osec->members.end());

std::unordered_map<InputSection<E> *, i64> map;
typedef std::pair<InputSection<E> *, i64> P;
std::vector<P> vec;

for (InputSection<E> *isec : osec->members)
map.insert({isec, get_ctor_dtor_priority(isec)});
vec.emplace_back(isec, get_ctor_dtor_priority(isec));

sort(vec, [&](const P &a, const P &b) { return a.second < b.second; });

sort(osec->members, [&](InputSection<E> *a, InputSection<E> *b) {
return map[a] < map[b];
});
for (i64 i = 0; i < vec.size(); i++)
osec->members[i] = vec[i].first;
}
}
}
Expand Down

0 comments on commit 806d740

Please sign in to comment.