Browse Source

+ WebAssembly internal linker: support data relocations to threadvars, resolve
them as relative values to the beginning of the TLS section. Will be used for
generating debug info for threadvars.

Nikolay Nikolov 11 months ago
parent
commit
ee98fa8e3f
2 changed files with 21 additions and 0 deletions
  1. 14 0
      compiler/dbgdwarf.pas
  2. 7 0
      compiler/ogwasm.pas

+ 14 - 0
compiler/dbgdwarf.pas

@@ -2384,6 +2384,19 @@ implementation
                        (not (target_info.system in systems_wasm) or
                             (ts_wasm_threads in current_settings.targetswitches)) then
                       begin
+{$ifdef wasm}
+                        if target_info.system in systems_wasm then
+                          begin
+                            templist.concat(tai_const.create_8bit(ord(DW_OP_WASM_location)));
+                            templist.concat(tai_const.create_8bit(3)); { wasm global }
+                            templist.concat(tai_const.create_32bit(0));
+                            //templist.concat(tai_const.Create_type_name(aitconst_ptr_unaligned,TLS_BASE_SYM,AT_WASM_GLOBAL,0));
+                            templist.concat(tai_const.create_8bit(ord(DW_OP_addr)));
+                            templist.concat(tai_const.Create_type_name(aitconst_ptr_unaligned,sym.mangledname,0));
+                            templist.concat(tai_const.create_8bit(ord(DW_OP_plus)));
+                            blocksize:=3+2*sizeof(puint);
+                          end;
+{$else wasm}
                         if tf_section_threadvars in target_info.flags then
                           begin
                             case sizeof(puint) of
@@ -2419,6 +2432,7 @@ implementation
                               offset+sizeof(pint)));
                             blocksize:=1+sizeof(puint);
                           end;
+{$endif wasm}
                       end
                     else
                       begin

+ 7 - 0
compiler/ogwasm.pas

@@ -5151,6 +5151,13 @@ implementation
                             objsec.Data.seek(objreloc.DataOffset);
                             writeUInt32LE(UInt32((objsym.offset+objsym.objsection.MemPos)+objreloc.Addend));
                           end;
+                        AT_TLS:
+                          begin
+                            if objreloc.IsFunctionOffsetI32 then
+                              internalerror(2024010602);
+                            objsec.Data.seek(objreloc.DataOffset);
+                            writeUInt32LE(UInt32((objsym.offset+objsym.objsection.MemPos-objsym.objsection.ExeSection.MemPos)+objreloc.Addend));
+                          end;
                         else
                           internalerror(2024010108);
                       end;