diff --git a/elf/passes.cc b/elf/passes.cc index f6ccddd76b..634ab99103 100644 --- a/elf/passes.cc +++ b/elf/passes.cc @@ -2457,6 +2457,8 @@ static i64 set_file_offsets(Context &ctx) { } if (first.shdr.sh_type == SHT_NOBITS) { + fileoff = align_to(fileoff, first.shdr.sh_addralign); + first.shdr.sh_offset = fileoff; i++; continue; } @@ -2497,8 +2499,11 @@ static i64 set_file_offsets(Context &ctx) { while (i < chunks.size() && (chunks[i]->shdr.sh_flags & SHF_ALLOC) && - chunks[i]->shdr.sh_type == SHT_NOBITS) + chunks[i]->shdr.sh_type == SHT_NOBITS) { + fileoff = align_to(fileoff, chunks[i]->shdr.sh_addralign); + chunks[i]->shdr.sh_offset = fileoff; i++; + } } return fileoff;