Browse Source

sinclairql: support the upcoming QL binary linking feature of vlink (still in development). it's behind an undocumented -WL switch now. also, reduce the amount of used dataspace by the size of the relocation table in the current linking mode

git-svn-id: trunk@49234 -
Károly Balogh 4 years ago
parent
commit
f718567c95
3 changed files with 24 additions and 3 deletions
  1. 1 0
      compiler/globals.pas
  2. 7 0
      compiler/options.pas
  3. 16 3
      compiler/systems/t_sinclairql.pas

+ 1 - 0
compiler/globals.pas

@@ -416,6 +416,7 @@ interface
 {$if defined(m68k)}
 {$if defined(m68k)}
        { Sinclair QL specific }
        { Sinclair QL specific }
        sinclairql_metadata_format: string[4] = 'QHDR';
        sinclairql_metadata_format: string[4] = 'QHDR';
+       sinclairql_vlink_experimental: boolean = false; { temporary }
 {$endif defined(m68k)}
 {$endif defined(m68k)}
 
 
        { default name of the C-style "main" procedure of the library/program }
        { default name of the C-style "main" procedure of the library/program }

+ 7 - 0
compiler/options.pas

@@ -2761,6 +2761,13 @@ begin
                           IllegalPara(opt);
                           IllegalPara(opt);
                       end;
                       end;
 {$if defined(m68k)}
 {$if defined(m68k)}
+                    'L':
+                      begin
+                        if (target_info.system in [system_m68k_sinclairql]) then
+                          sinclairql_vlink_experimental:=true
+                        else
+                          IllegalPara(opt);
+                      end;
                     'Q':
                     'Q':
                       begin
                       begin
                         if (target_info.system in [system_m68k_sinclairql]) then
                         if (target_info.system in [system_m68k_sinclairql]) then

+ 16 - 3
compiler/systems/t_sinclairql.pas

@@ -115,7 +115,7 @@ begin
      end
      end
     else
     else
      begin
      begin
-      ExeCmd[1]:='vlink -b rawseg -q $FLAGS $GCSECTIONS $OPT $STRIP $MAP -o $EXE -T $RES';
+      ExeCmd[1]:='vlink $QLFLAGS $FLAGS $GCSECTIONS $OPT $STRIP $MAP -o $EXE -T $RES';
      end;
      end;
    end;
    end;
 end;
 end;
@@ -245,6 +245,7 @@ var
   DynLinkStr : string;
   DynLinkStr : string;
   GCSectionsStr : string;
   GCSectionsStr : string;
   FlagsStr : string;
   FlagsStr : string;
+  QLFlagsStr: string;
   MapStr : string;
   MapStr : string;
   ExeName: string;
   ExeName: string;
   fd,fs: file;
   fd,fs: file;
@@ -258,6 +259,7 @@ var
   QLHeader: TQLHeader;
   QLHeader: TQLHeader;
   XTccData: TXTccData;
   XTccData: TXTccData;
   BinSize: longint;
   BinSize: longint;
+  RelocSize: longint;
   DataSpace: DWord;
   DataSpace: DWord;
 begin
 begin
   StripStr:='';
   StripStr:='';
@@ -276,6 +278,10 @@ begin
     begin
     begin
       if create_smartlink_sections then
       if create_smartlink_sections then
         GCSectionsStr:='-gc-all';
         GCSectionsStr:='-gc-all';
+      if sinclairql_vlink_experimental then
+        QLFlagsStr:='-b sinclairql -q -'+lower(sinclairql_metadata_format)+' -stack='+tostr(StackSize)
+      else
+        QLFlagsStr:='-b rawseg -q';
     end;
     end;
 
 
   ExeName:=current_module.exefilename;
   ExeName:=current_module.exefilename;
@@ -292,18 +298,20 @@ begin
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
+  Replace(cmdstr,'$QLFLAGS',QLFlagsStr);
 
 
   MakeSinclairQLExe:=DoExec(BinStr,CmdStr,true,false);
   MakeSinclairQLExe:=DoExec(BinStr,CmdStr,true,false);
 
 
   { Kludge:
   { Kludge:
       With the above linker script, vlink will produce two files. The main binary 
       With the above linker script, vlink will produce two files. The main binary 
       and the relocation info. Here we copy the two together. (KB) }
       and the relocation info. Here we copy the two together. (KB) }
-  if MakeSinclairQLExe then
+  if MakeSinclairQLExe and not sinclairql_vlink_experimental then
     begin
     begin
       QLHeader:=DefaultQLHeader;
       QLHeader:=DefaultQLHeader;
       XTccData:=DefaultXTccData;
       XTccData:=DefaultXTccData;
 
 
       BinSize:=0;
       BinSize:=0;
+      RelocSize:=0;
       bufsize:=16384;
       bufsize:=16384;
 {$push}
 {$push}
 {$i-}
 {$i-}
@@ -321,13 +329,18 @@ begin
       assign(fd,ExeName);
       assign(fd,ExeName);
       rewrite(fd,1);
       rewrite(fd,1);
 
 
+      assign(fs,ExeName+'.'+ProgramHeaderName+'.rel'+ProgramHeaderName);
+      reset(fs,1);
+      RelocSize := FileSize(fs);
+      close(fs);
+
       assign(fs,ExeName+'.'+ProgramHeaderName);
       assign(fs,ExeName+'.'+ProgramHeaderName);
       reset(fs,1);
       reset(fs,1);
       BinSize := FileSize(fs);
       BinSize := FileSize(fs);
 
 
       { We assume .bss size is total size indicated by linker minus emmited binary.
       { We assume .bss size is total size indicated by linker minus emmited binary.
         DataSpace size is .bss + stack space }
         DataSpace size is .bss + stack space }
-      DataSpace := NToBE(DWord(HeaderSize - BinSize + StackSize));
+      DataSpace := NToBE(DWord(max((HeaderSize - BinSize) - RelocSize + StackSize,0)));
 
 
       { Option: prepend QEmuLator and QPC2 v5 compatible header to EXE }
       { Option: prepend QEmuLator and QPC2 v5 compatible header to EXE }
       if sinclairql_metadata_format='QHDR' then
       if sinclairql_metadata_format='QHDR' then