From c9faf3d34562d010b9e430ff3fec466c11db295e Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 22 Apr 2024 17:03:50 +0900 Subject: [PATCH] Optimize --- elf/output-chunks.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/elf/output-chunks.cc b/elf/output-chunks.cc index 7de0adc3d2..a0ba8a6825 100644 --- a/elf/output-chunks.cc +++ b/elf/output-chunks.cc @@ -2022,14 +2022,16 @@ void MergedSection::write_to(Context &ctx, u8 *buf) { i64 shard_size = map.nbuckets / map.NUM_SHARDS; tbb::parallel_for((i64)0, map.NUM_SHARDS, [&](i64 i) { - memset(buf + shard_offsets[i], 0, shard_offsets[i + 1] - shard_offsets[i]); + // There might be gaps between strings to satisfy alignment requirements. + // If that's the case, we need to zero-clear them. + if (this->shdr.sh_addralign > 1) + memset(buf + shard_offsets[i], 0, shard_offsets[i + 1] - shard_offsets[i]); + // Copy strings for (i64 j = shard_size * i; j < shard_size * (i + 1); j++) - if (const char *key = map.entries[j].key) { - SectionFragment &frag = map.entries[j].value; - if (frag.is_alive) + if (const char *key = map.entries[j].key) + if (SectionFragment &frag = map.entries[j].value; frag.is_alive) memcpy(buf + frag.offset, key, map.entries[j].keylen); - } }); }