1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 21:17:28 +03:00

Fix non-deterministic behavior

This commit is contained in:
Rui Ueyama 2024-04-18 20:20:09 +09:00
parent 7434465334
commit 6463a7c48a
2 changed files with 36 additions and 10 deletions

View File

@ -623,18 +623,18 @@ void create_output_sections(Context<E> &ctx) {
continue;
}
OutputSectionKey key = get_output_section_key(ctx, *isec);
if (auto it = cache.find(key); it != cache.end()) {
isec->output_section = it->second;
continue;
}
auto get_or_insert = [&] {
OutputSectionKey key = get_output_section_key(ctx, *isec);
if (auto it = cache.find(key); it != cache.end())
return it->second;
{
std::shared_lock lock(mu);
if (auto it = map.find(key); it != map.end())
if (auto it = map.find(key); it != map.end()) {
cache.insert({key, it->second});
return it->second;
}
}
std::unique_ptr<OutputSection<E>> osec =
@ -646,13 +646,15 @@ void create_output_sections(Context<E> &ctx) {
if (inserted)
ctx.osec_pool.emplace_back(std::move(osec));
cache.insert({key, it->second});
return ret;
};
OutputSection<E> *osec = get_or_insert();
osec->sh_flags |= sh_flags & ~SHF_GROUP;
sh_flags &= ~SHF_GROUP;
if ((osec->sh_flags & sh_flags) != sh_flags)
osec->sh_flags |= sh_flags;
isec->output_section = osec;
cache.insert({key, osec});
}
});

24
test/elf/section-attributes.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
. $(dirname $0)/common.inc
cat <<EOF | $CC -o $t/a.o -c -xassembler -
.section .foobar,"aw"
.ascii "foo\0"
EOF
cat <<EOF | $CC -o $t/b.o -c -xassembler -
.section .foobar,"a"
.ascii "bar\0"
EOF
cat <<EOF | $CC -o $t/c.o -c -xassembler -
.section .foobar,"ax"
.ascii "bar\0"
EOF
cat <<EOF | $CC -o $t/d.o -c -xc -
int main() {}
EOF
$CC -B. -o $t/exe $t/a.o $t/b.o $t/c.o $t/d.o
readelf -W --sections $t/exe | grep -q 'foobar.*WAX'