Browse Source

* fixed crashes with the WebAssembly internal object writer, when debug info is enabled. The debug info itself is not yet written to the file, though.

Nikolay Nikolov 3 years ago
parent
commit
b82af25e63
1 changed files with 30 additions and 21 deletions
  1. 30 21
      compiler/ogwasm.pas

+ 30 - 21
compiler/ogwasm.pas

@@ -1123,11 +1123,13 @@ implementation
                 relout:=FWasmRelocationCodeTable;
                 relout:=FWasmRelocationCodeTable;
                 relcount:=@FWasmRelocationCodeTableEntriesCount;
                 relcount:=@FWasmRelocationCodeTableEntriesCount;
               end
               end
-            else
+            else if objsec.IsData then
               begin
               begin
                 relout:=FWasmRelocationDataTable;
                 relout:=FWasmRelocationDataTable;
                 relcount:=@FWasmRelocationDataTableEntriesCount;
                 relcount:=@FWasmRelocationDataTableEntriesCount;
-              end;
+              end
+            else
+              continue;
             for ri:=0 to objsec.ObjRelocations.Count-1 do
             for ri:=0 to objsec.ObjRelocations.Count-1 do
               begin
               begin
                 objrel:=TWasmObjRelocation(objsec.ObjRelocations[ri]);
                 objrel:=TWasmObjRelocation(objsec.ObjRelocations[ri]);
@@ -1300,7 +1302,7 @@ implementation
             objsec:=TWasmObjSection(Data.ObjSectionList[i]);
             objsec:=TWasmObjSection(Data.ObjSectionList[i]);
             if objsec.IsCode then
             if objsec.IsCode then
               objsec.SegIdx:=-1
               objsec.SegIdx:=-1
-            else
+            else if objsec.IsData then
               begin
               begin
                 objsec.SegIdx:=segment_count;
                 objsec.SegIdx:=segment_count;
                 objsec.SegOfs:=cur_seg_ofs;
                 objsec.SegOfs:=cur_seg_ofs;
@@ -1634,26 +1636,33 @@ implementation
               end
               end
             else if (objsym.typ in [AT_DATA,AT_TLS]) or ((objsym.typ=AT_NONE) and (objsym.bind=AB_EXTERNAL)) then
             else if (objsym.typ in [AT_DATA,AT_TLS]) or ((objsym.typ=AT_NONE) and (objsym.bind=AB_EXTERNAL)) then
               begin
               begin
-                objsym.SymbolIndex:=FWasmSymbolTableEntriesCount;
-                Inc(FWasmSymbolTableEntriesCount);
-                WriteByte(FWasmSymbolTable,Ord(SYMTAB_DATA));
-                if objsym.bind=AB_GLOBAL then
-                  SymbolFlags:=0
-                else if objsym.bind=AB_LOCAL then
-                  SymbolFlags:=WASM_SYM_BINDING_LOCAL
-                else if objsym.bind=AB_EXTERNAL then
-                  SymbolFlags:=WASM_SYM_UNDEFINED
+                if (objsym.bind<>AB_EXTERNAL) and TWasmObjSection(objsym.objsection).IsDebug then
+                  begin
+                    {todo: debug symbols}
+                  end
                 else
                 else
-                  internalerror(2021092506);
-                if (objsym.typ=AT_TLS) and (ts_wasm_threads in current_settings.targetswitches) then
-                  SymbolFlags:=(SymbolFlags and not WASM_SYM_BINDING_LOCAL) or WASM_SYM_TLS;
-                WriteUleb(FWasmSymbolTable,SymbolFlags);
-                WriteName(FWasmSymbolTable,objsym.Name);
-                if objsym.bind<>AB_EXTERNAL then
                   begin
                   begin
-                    WriteUleb(FWasmSymbolTable,TWasmObjSection(objsym.objsection).SegIdx);
-                    WriteUleb(FWasmSymbolTable,objsym.offset);
-                    WriteUleb(FWasmSymbolTable,objsym.size);
+                    objsym.SymbolIndex:=FWasmSymbolTableEntriesCount;
+                    Inc(FWasmSymbolTableEntriesCount);
+                    WriteByte(FWasmSymbolTable,Ord(SYMTAB_DATA));
+                    if objsym.bind=AB_GLOBAL then
+                      SymbolFlags:=0
+                    else if objsym.bind=AB_LOCAL then
+                      SymbolFlags:=WASM_SYM_BINDING_LOCAL
+                    else if objsym.bind=AB_EXTERNAL then
+                      SymbolFlags:=WASM_SYM_UNDEFINED
+                    else
+                      internalerror(2021092506);
+                    if (objsym.typ=AT_TLS) and (ts_wasm_threads in current_settings.targetswitches) then
+                      SymbolFlags:=(SymbolFlags and not WASM_SYM_BINDING_LOCAL) or WASM_SYM_TLS;
+                    WriteUleb(FWasmSymbolTable,SymbolFlags);
+                    WriteName(FWasmSymbolTable,objsym.Name);
+                    if objsym.bind<>AB_EXTERNAL then
+                      begin
+                        WriteUleb(FWasmSymbolTable,TWasmObjSection(objsym.objsection).SegIdx);
+                        WriteUleb(FWasmSymbolTable,objsym.offset);
+                        WriteUleb(FWasmSymbolTable,objsym.size);
+                      end;
                   end;
                   end;
               end;
               end;
           end;
           end;