From 2a196899bcac210138cc267bb47475075aa07cb0 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Wed, 3 Aug 2022 20:30:09 +0300 Subject: [PATCH] * wasm32 obj writer: writing the debug section symbols to the symbol table moved before the writing of the debug sections themselves --- compiler/ogwasm.pas | 90 ++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 58 deletions(-) diff --git a/compiler/ogwasm.pas b/compiler/ogwasm.pas index f988a4ed60..038a7f1799 100644 --- a/compiler/ogwasm.pas +++ b/compiler/ogwasm.pas @@ -1382,7 +1382,24 @@ implementation var section_nr: Integer; - procedure MaybeWriteDebugSection(const sn: string; st: TWasmCustomSectionType; var debug_section_nr: Integer); + procedure MaybeAddDebugSectionToSymbolTable(const sn: string; st: TWasmCustomSectionType; var debug_section_nr: Integer); + var + objsec: TWasmObjSection; + begin + objsec:=TWasmObjSection(Data.ObjSectionList.Find(sn)); + if Assigned(objsec) then + begin + debug_section_nr:=section_nr; + Inc(section_nr); + objsec.SegSymIdx:=FWasmSymbolTableEntriesCount; + Inc(FWasmSymbolTableEntriesCount); + WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); + WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); + WriteUleb(FWasmSymbolTable,debug_section_nr); + end; + end; + + procedure MaybeWriteDebugSection(const sn: string; st: TWasmCustomSectionType); var i: Integer; objsec: TWasmObjSection; @@ -1392,8 +1409,6 @@ implementation objsec:=TWasmObjSection(Data.ObjSectionList[i]); if objsec.Name=sn then begin - debug_section_nr:=section_nr; - Inc(section_nr); if oso_Data in objsec.SecOptions then begin objsec.Data.seek(0); @@ -1939,62 +1954,21 @@ implementation Inc(section_nr); end; - MaybeWriteDebugSection('.debug_abbrev',wcstDebugAbbrev,debug_abbrev_section_nr); - MaybeWriteDebugSection('.debug_info',wcstDebugInfo,debug_info_section_nr); - MaybeWriteDebugSection('.debug_str',wcstDebugStr,debug_str_section_nr); - MaybeWriteDebugSection('.debug_line',wcstDebugLine,debug_line_section_nr); - MaybeWriteDebugSection('.debug_frame',wcstDebugFrame,debug_frame_section_nr); - MaybeWriteDebugSection('.debug_aranges',wcstDebugAranges,debug_aranges_section_nr); - MaybeWriteDebugSection('.debug_ranges',wcstDebugRanges,debug_ranges_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_abbrev',wcstDebugAbbrev,debug_abbrev_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_info',wcstDebugInfo,debug_info_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_str',wcstDebugStr,debug_str_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_line',wcstDebugLine,debug_line_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_frame',wcstDebugFrame,debug_frame_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_aranges',wcstDebugAranges,debug_aranges_section_nr); + MaybeAddDebugSectionToSymbolTable('.debug_ranges',wcstDebugRanges,debug_ranges_section_nr); - if debug_abbrev_section_nr<>-1 then - begin - TWasmObjSection(Data.ObjSectionList.Find('.debug_abbrev')).SegSymIdx:=FWasmSymbolTableEntriesCount; - Inc(FWasmSymbolTableEntriesCount); - WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); - WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); - WriteUleb(FWasmSymbolTable,debug_abbrev_section_nr); - end; - if debug_info_section_nr<>-1 then - begin - TWasmObjSection(Data.ObjSectionList.Find('.debug_info')).SegSymIdx:=FWasmSymbolTableEntriesCount; - Inc(FWasmSymbolTableEntriesCount); - WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); - WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); - WriteUleb(FWasmSymbolTable,debug_info_section_nr); - end; - if debug_str_section_nr<>-1 then - begin - TWasmObjSection(Data.ObjSectionList.Find('.debug_str')).SegSymIdx:=FWasmSymbolTableEntriesCount; - Inc(FWasmSymbolTableEntriesCount); - WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); - WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); - WriteUleb(FWasmSymbolTable,debug_str_section_nr); - end; - if debug_line_section_nr<>-1 then - begin - TWasmObjSection(Data.ObjSectionList.Find('.debug_line')).SegSymIdx:=FWasmSymbolTableEntriesCount; - Inc(FWasmSymbolTableEntriesCount); - WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); - WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); - WriteUleb(FWasmSymbolTable,debug_line_section_nr); - end; - if debug_frame_section_nr<>-1 then - begin - TWasmObjSection(Data.ObjSectionList.Find('.debug_frame')).SegSymIdx:=FWasmSymbolTableEntriesCount; - Inc(FWasmSymbolTableEntriesCount); - WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); - WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); - WriteUleb(FWasmSymbolTable,debug_frame_section_nr); - end; - if debug_aranges_section_nr<>-1 then - begin - TWasmObjSection(Data.ObjSectionList.Find('.debug_aranges')).SegSymIdx:=FWasmSymbolTableEntriesCount; - Inc(FWasmSymbolTableEntriesCount); - WriteByte(FWasmSymbolTable,Ord(SYMTAB_SECTION)); - WriteUleb(FWasmSymbolTable,WASM_SYM_BINDING_LOCAL); - WriteUleb(FWasmSymbolTable,debug_aranges_section_nr); - end; + MaybeWriteDebugSection('.debug_abbrev',wcstDebugAbbrev); + MaybeWriteDebugSection('.debug_info',wcstDebugInfo); + MaybeWriteDebugSection('.debug_str',wcstDebugStr); + MaybeWriteDebugSection('.debug_line',wcstDebugLine); + MaybeWriteDebugSection('.debug_frame',wcstDebugFrame); + MaybeWriteDebugSection('.debug_aranges',wcstDebugAranges); + MaybeWriteDebugSection('.debug_ranges',wcstDebugRanges); DoRelocations; WriteRelocations;