diff options
Diffstat (limited to 'src/binary-writer.cc')
-rw-r--r-- | src/binary-writer.cc | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/binary-writer.cc b/src/binary-writer.cc index c0a841e7..c628b108 100644 --- a/src/binary-writer.cc +++ b/src/binary-writer.cc @@ -479,13 +479,8 @@ void BinaryWriter::BeginCustomSection(const char* name) { void BinaryWriter::EndSection() { assert(last_section_leb_size_guess_ != 0); - Offset delta = WriteFixupU32Leb128Size( - last_section_offset_, last_section_leb_size_guess_, "FIXUP section size"); - if (current_reloc_section_ && delta != 0) { - for (Reloc& reloc : current_reloc_section_->relocations) { - reloc.offset += delta; - } - } + WriteFixupU32Leb128Size(last_section_offset_, last_section_leb_size_guess_, + "FIXUP section size"); last_section_leb_size_guess_ = 0; section_count_++; } @@ -1401,8 +1396,17 @@ Result BinaryWriter::WriteModule() { Offset body_size_offset = WriteU32Leb128Space(leb_size_guess, "func body size (guess)"); WriteFunc(func); - WriteFixupU32Leb128Size(body_size_offset, leb_size_guess, + auto func_start_offset = body_size_offset - last_section_payload_offset_; + auto func_end_offset = stream_->offset() - last_section_payload_offset_; + auto delta = WriteFixupU32Leb128Size(body_size_offset, leb_size_guess, "FIXUP func body size"); + if (current_reloc_section_ && delta != 0) { + for (Reloc& reloc : current_reloc_section_->relocations) { + if (reloc.offset >= func_start_offset && reloc.offset <= func_end_offset) { + reloc.offset += delta; + } + } + } } EndSection(); } |