Browse Source

+ override MakeExecutable for the WASI target (not working yet, clone of MakeSharedLibrary for now)

git-svn-id: branches/wasm@46295 -
nickysn 5 years ago
parent
commit
5c8cfdf958
1 changed files with 60 additions and 1 deletions
  1. 60 1
      compiler/systems/t_wasi.pas

+ 60 - 1
compiler/systems/t_wasi.pas

@@ -66,7 +66,7 @@ type
     constructor Create;override;
     procedure SetDefaultInfo;override;
 
-    //function  MakeExecutable:boolean;override;
+    function  MakeExecutable:boolean;override;
     function  MakeSharedLibrary:boolean;override;
   end;
 
@@ -92,6 +92,65 @@ begin
   //Info.DllCmd[2] := 'wasmtool --exportrename $INPUT $EXE';
 end;
 
+function tlinkerwasi.MakeExecutable:boolean;
+var
+  GCSectionsStr  : ansistring;
+  binstr, cmdstr : Tcmdstr;
+  InitStr,
+  FiniStr,
+  SoNameStr      : string[80];
+  mapstr,ltostr  : TCmdStr;
+  success        : Boolean;
+
+  tmp : TCmdStrListItem;
+  tempFileName : ansistring;
+begin
+  if (cs_link_smart in current_settings.globalswitches) and
+     create_smartlink_sections then
+   GCSectionsStr:='--gc-sections'
+  else
+    GCSectionsStr:='';
+
+  SoNameStr:='';
+  SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
+  Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
+
+  tmp := TCmdStrListItem(ObjectFiles.First);
+  while Assigned(tmp) do begin
+    cmdstr := tmp.Str+ ' ' + cmdstr;
+    tmp := TCmdStrListItem(tmp.Next);
+  end;
+
+  if HasExports then
+    cmdstr := cmdstr + ' --export-dynamic'; //' --export-dynamic';
+
+  cmdstr := cmdstr + ' --no-entry --allow-undefined';
+
+  if (cs_link_strip in current_settings.globalswitches) then
+   begin
+     { only remove non global symbols and debugging info for a library }
+     cmdstr := cmdstr + ' --strip-all';
+   end;
+
+  //Replace(cmdstr,'$OPT',Info.ExtraOptions);
+  //Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+  //Replace(cmdstr,'$INIT',InitStr);
+  //Replace(cmdstr,'$FINI',FiniStr);
+  Replace(cmdstr,'$SONAME',SoNameStr);
+  //Replace(cmdstr,'$MAP',mapstr);
+  //Replace(cmdstr,'$LTO',ltostr);
+  Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
+  writeln(utilsprefix+binstr,' ',cmdstr);
+  success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,false);
+
+  //SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
+  //Replace(cmdstr,'$INPUT',current_module.objfilename );
+  //Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
+  //DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
+
+  MakeExecutable:=success;
+end;
+
 function tlinkerwasi.MakeSharedLibrary: boolean;
 var
   GCSectionsStr  : ansistring;