diff --git a/elf/passes.cc b/elf/passes.cc index 864f0b2ab4..76c696e71f 100644 --- a/elf/passes.cc +++ b/elf/passes.cc @@ -623,18 +623,18 @@ void create_output_sections(Context &ctx) { continue; } - OutputSectionKey key = get_output_section_key(ctx, *isec); + auto get_or_insert = [&] { + OutputSectionKey key = get_output_section_key(ctx, *isec); - if (auto it = cache.find(key); it != cache.end()) { - isec->output_section = it->second; - continue; - } + if (auto it = cache.find(key); it != cache.end()) + return it->second; - auto get_or_insert = [&] { { 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> osec = @@ -646,13 +646,15 @@ void create_output_sections(Context &ctx) { if (inserted) ctx.osec_pool.emplace_back(std::move(osec)); + cache.insert({key, it->second}); return ret; }; OutputSection *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}); } }); diff --git a/test/elf/section-attributes.sh b/test/elf/section-attributes.sh new file mode 100755 index 0000000000..63eacf3582 --- /dev/null +++ b/test/elf/section-attributes.sh @@ -0,0 +1,24 @@ +#!/bin/bash +. $(dirname $0)/common.inc + +cat <