Selaa lähdekoodia

* section smartlink for win32 added, disabled by default because ld.exe
ignores the --gc-sections for pe-i38

git-svn-id: trunk@2305 -

peter 19 vuotta sitten
vanhempi
commit
abc49206fc
4 muutettua tiedostoa jossa 16 lisäystä ja 4 poistoa
  1. 5 0
      compiler/options.pas
  2. 1 1
      compiler/pmodules.pas
  3. 2 1
      compiler/systems/i_win.pas
  4. 8 2
      compiler/systems/t_win.pas

+ 5 - 0
compiler/options.pas

@@ -2117,6 +2117,11 @@ begin
   if target_info.system=system_arm_wince then
   if target_info.system=system_arm_wince then
     include(initmoduleswitches,cs_fp_emulation);
     include(initmoduleswitches,cs_fp_emulation);
 
 
+  { Section smartlinking conflicts with import sections on Windows }
+  if GenerateImportSection and
+     (target_info.system in [system_i386_win32]) then
+    exclude(target_info.flags,tf_smartlink_sections);
+
 {$ifdef x86_64}
 {$ifdef x86_64}
   {$warning HACK: turn off smartlinking}
   {$warning HACK: turn off smartlinking}
   exclude(initmoduleswitches,cs_create_smart);
   exclude(initmoduleswitches,cs_create_smart);

+ 1 - 1
compiler/pmodules.pas

@@ -98,7 +98,7 @@ implementation
 
 
         { Also create a smartlinked version ? }
         { Also create a smartlinked version ? }
         if (cs_create_smart in aktmoduleswitches) and
         if (cs_create_smart in aktmoduleswitches) and
-           not(af_smartlink_sections in target_asm.flags) then
+           (not use_smartlink_section) then
          begin
          begin
            { regenerate the importssection for win32 }
            { regenerate the importssection for win32 }
            if assigned(asmlist[al_imports]) and
            if assigned(asmlist[al_imports]) and

+ 2 - 1
compiler/systems/i_win.pas

@@ -32,7 +32,8 @@ unit i_win;
             system       : system_i386_WIN32;
             system       : system_i386_WIN32;
             name         : 'Win32 for i386';
             name         : 'Win32 for i386';
             shortname    : 'Win32';
             shortname    : 'Win32';
-            flags        : [tf_files_case_aware,tf_has_dllscanner,tf_use_function_relative_addresses{,tf_section_threadvars}];
+            flags        : [tf_files_case_aware,tf_has_dllscanner,tf_use_function_relative_addresses
+                            {,tf_smartlink_sections}{,tf_section_threadvars}];
             cpu          : cpu_i386;
             cpu          : cpu_i386;
             unit_env     : 'WIN32UNITS';
             unit_env     : 'WIN32UNITS';
             extradefines : 'MSWINDOWS;WINDOWS';
             extradefines : 'MSWINDOWS;WINDOWS';

+ 8 - 2
compiler/systems/t_win.pas

@@ -898,8 +898,8 @@ begin
      {$else ARM}
      {$else ARM}
        targetopts:='-b pe-i386 -m i386pe';
        targetopts:='-b pe-i386 -m i386pe';
      {$endif ARM}
      {$endif ARM}
-     ExeCmd[1]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
-     DllCmd[1]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
+     ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $STRIP $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
+     DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $STRIP --dll $APPTYPE $IMAGEBASE $RELOC -o $EXE $RES';
      { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
      { ExeCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF';
        use short forms to avoid 128 char limitation problem }
        use short forms to avoid 128 char limitation problem }
      ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
      ExeCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
@@ -1036,6 +1036,7 @@ var
   success : boolean;
   success : boolean;
   cmds,i       : longint;
   cmds,i       : longint;
   AsBinStr     : string[80];
   AsBinStr     : string[80];
+  GCSectionsStr,
   StripStr,
   StripStr,
   RelocStr,
   RelocStr,
   AppTypeStr,
   AppTypeStr,
@@ -1049,9 +1050,13 @@ begin
   AppTypeStr:='';
   AppTypeStr:='';
   ImageBaseStr:='';
   ImageBaseStr:='';
   StripStr:='';
   StripStr:='';
+  GCSectionsStr:='';
   AsBinStr:=FindUtil(utilsprefix+'as');
   AsBinStr:=FindUtil(utilsprefix+'as');
   if RelocSection then
   if RelocSection then
    RelocStr:='--base-file base.$$$';
    RelocStr:='--base-file base.$$$';
+  if (af_smartlink_sections in target_asm.flags) and
+     (tf_smartlink_sections in target_info.flags) then
+   GCSectionsStr:='--gc-sections';
   if target_info.system in [system_arm_wince,system_i386_wince] then
   if target_info.system in [system_arm_wince,system_i386_wince] then
     begin
     begin
       AppTypeStr:='--subsystem wince';
       AppTypeStr:='--subsystem wince';
@@ -1087,6 +1092,7 @@ begin
         Replace(cmdstr,'$ASBIN',AsbinStr);
         Replace(cmdstr,'$ASBIN',AsbinStr);
         Replace(cmdstr,'$RELOC',RelocStr);
         Replace(cmdstr,'$RELOC',RelocStr);
         Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
         Replace(cmdstr,'$IMAGEBASE',ImageBaseStr);
+        Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
         Replace(cmdstr,'$STRIP',StripStr);
         Replace(cmdstr,'$STRIP',StripStr);
         if not DefFile.Empty then
         if not DefFile.Empty then
           begin
           begin