1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-10-22 19:03:31 +09:00
parent 680271c8df
commit 3f74a8a2fa

74
main.cc
View File

@ -112,49 +112,24 @@ static OutputSection *create_interp_section() {
// We want to sort output sections in the following order.
//
// alloc !write !exec !tls !nobits
// alloc !write !exec !tls nobits
// alloc !write !exec tls !nobits
// alloc !write !exec tls nobits
// alloc !write exec
// alloc write !exec !tls !nobits
// alloc write !exec !tls nobits
// alloc write !exec tls !nobits
// alloc write !exec tls nobits
// alloc write exec
// alloc !writable !exec !tls !nobits
// alloc !writable !exec !tls nobits
// alloc !writable !exec tls !nobits
// alloc !writable !exec tls nobits
// alloc !writable exec
// alloc writable !exec !tls !nobits
// alloc writable !exec !tls nobits
// alloc writable !exec tls !nobits
// alloc writable !exec tls nobits
// alloc writable exec
// !alloc
struct SortKey {
bool is_alloc;
bool is_writable;
bool is_exec;
bool is_tls;
bool is_nobits;
StringRef name;
uint64_t flags;
uint32_t type;
bool less_than(SortKey other) {
if (is_alloc != other.is_alloc)
return is_alloc;
if (is_writable != other.is_writable)
return !is_writable;
if (is_exec != other.is_exec)
return !is_exec;
if (is_tls != other.is_tls)
return is_tls;
if (is_nobits != other.is_nobits)
return is_nobits;
if (name != other.name)
return name < other.name;
if (hdr.sh_flags != other.hdr.sh_flags)
return hdr.sh_flags < other.hdr.sh_flags
return hdr.sh_type < other.hdr.sh_type;
}
};
static bool compare_sections(OutputSection *a, OutputSection *b) {
if ((a->hdr.flags & SHF_ALLOC) &&
static int get_rank(OutputSection *x) {
bool alloc = x->hdr.sh_flags & SHF_ALLOC;
bool writable = x->hdr.sh_flags & SHF_WRITE;
bool exec = x->hdr.sh_flags & SHF_EXECINSTR;
bool tls = x->hdr.sh_flags & SHF_TLS;
bool nobits = x->hdr.sh_type & SHT_NOBITS;
return (alloc << 5) | (!writable << 4) | (!exec << 3) | (!tls << 2) | !nobits;
}
static std::vector<OutputSection *> get_output_sections() {
@ -163,8 +138,19 @@ static std::vector<OutputSection *> get_output_sections() {
if (!osec->chunks.empty())
vec.push_back(osec);
std::sort(vec.begin(), vec.end(), [](OutputSeciton *a, OutputSection *b) {
});
std::sort(vec.begin(), vec.end(), [](OutputSection *a, OutputSection *b) {
int x = get_rank(a);
int y = get_rank(b);
if (x != y)
return x > y;
// Tie-break to make output deterministic.
if (a->hdr.sh_flags != b->hdr.sh_flags)
return a->hdr.sh_flags < b->hdr.sh_flags;
if (a->hdr.sh_type != b->hdr.sh_type)
return a->hdr.sh_type < b->hdr.sh_type;
return a->name < b->name;
});
return vec;
}