Browse Source

windows: fix external linking with binutils >= 2.36, based on a patch by Pierre Muller

Karoly Balogh 10 months ago
parent
commit
2bdfabe607
1 changed files with 6 additions and 4 deletions
  1. 6 4
      compiler/systems/t_win.pas

+ 6 - 4
compiler/systems/t_win.pas

@@ -1157,15 +1157,15 @@ implementation
 {$ifdef arm}
 {$ifdef arm}
            targetopts:='-m arm_wince_pe';
            targetopts:='-m arm_wince_pe';
 {$endif arm}
 {$endif arm}
-           ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP $APPTYPE $ENTRY  $IMAGEBASE $RELOC -o $EXE $RES';
-           DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP --dll $APPTYPE $ENTRY  $IMAGEBASE $RELOC -o $EXE $RES';
+           ExeCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP $APPTYPE $ENTRY  $IMAGEBASE $RELOC -o $EXE -T $RES';
+           DllCmd[1]:='ld '+targetopts+' $OPT $GCSECTIONS $MAP $STRIP --dll $APPTYPE $ENTRY  $IMAGEBASE $RELOC -o $EXE -T $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';
-           ExeCmd[3]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $ENTRY $IMAGEBASE -o $EXE $RES exp.$$$';
+           ExeCmd[3]:='ld '+targetopts+' $OPT $STRIP $APPTYPE $ENTRY $IMAGEBASE -o $EXE -T $RES exp.$$$';
            { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
            { DllCmd[2]:='dlltool --as $ASBIN --dllname $EXE --output-exp exp.$$$ $RELOC $DEF'; }
            DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
            DllCmd[2]:='dlltool -S $ASBIN -D $EXE -e exp.$$$ $RELOC $DEF';
-           DllCmd[3]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $ENTRY  $IMAGEBASE -o $EXE $RES exp.$$$';
+           DllCmd[3]:='ld '+targetopts+' $OPT $STRIP --dll $APPTYPE $ENTRY  $IMAGEBASE -o $EXE -T $RES exp.$$$';
          end;
          end;
       end;
       end;
 
 
@@ -1362,6 +1362,7 @@ implementation
             Add('    ___crt_xt_start__ = . ;');
             Add('    ___crt_xt_start__ = . ;');
             Add('    *(SORT(.CRT$XT*))  /* Termination */');
             Add('    *(SORT(.CRT$XT*))  /* Termination */');
             Add('    ___crt_xt_end__ = . ;');
             Add('    ___crt_xt_end__ = . ;');
+            Add('    . = . ; /* This forces GNU linker to keep the section even if it is empty */');
             Add('  }');
             Add('  }');
             Add('  .tls BLOCK(__section_alignment__) :');
             Add('  .tls BLOCK(__section_alignment__) :');
             Add('  {');
             Add('  {');
@@ -1370,6 +1371,7 @@ implementation
             Add('    *(.tls$)');
             Add('    *(.tls$)');
             Add('    *(SORT(.tls$*))');
             Add('    *(SORT(.tls$*))');
             Add('    ___tls_end__ = . ;');
             Add('    ___tls_end__ = . ;');
+            Add('    . = . ; /* This forces GNU linker to keep the section even if it is empty */');
             Add('  }');
             Add('  }');
             Add('  .rsrc BLOCK(__section_alignment__) :');
             Add('  .rsrc BLOCK(__section_alignment__) :');
             Add('  {');
             Add('  {');