Explorar el Código

* Enable use of amd64 ld GNU linker for i386 by adding target and emul command line args for freebsd

git-svn-id: trunk@23282 -
pierre hace 12 años
padre
commit
1dd964960c
Se han modificado 1 ficheros con 44 adiciones y 8 borrados
  1. 44 8
      compiler/systems/t_bsd.pas

+ 44 - 8
compiler/systems/t_bsd.pas

@@ -146,8 +146,8 @@ begin
        begin
        begin
          if not(target_info.system in systems_darwin) then
          if not(target_info.system in systems_darwin) then
            begin
            begin
-             ExeCmd[1]:='ld $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $CATRES';
-             DllCmd[1]:='ld $OPT -shared -L. -o $EXE $CATRES'
+             ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $CATRES';
+             DllCmd[1]:='ld $TARGET $EMUL $OPT -shared -L. -o $EXE $CATRES'
            end
            end
          else
          else
            begin
            begin
@@ -166,22 +166,22 @@ begin
                programs with problems that require Valgrind will have more
                programs with problems that require Valgrind will have more
                than 60KB of data (first 4KB of address space is always invalid)
                than 60KB of data (first 4KB of address space is always invalid)
              }
              }
-               ExeCmd[1]:='ld $PRTOBJ $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES';
+               ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES';
              if not(cs_gdb_valgrind in current_settings.globalswitches) then
              if not(cs_gdb_valgrind in current_settings.globalswitches) then
                ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
                ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
 {$else ndef cpu64bitaddr}
 {$else ndef cpu64bitaddr}
-             ExeCmd[1]:='ld $PRTOBJ $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES';
+             ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -multiply_defined suppress -L. -o $EXE $CATRES';
 {$endif ndef cpu64bitaddr}
 {$endif ndef cpu64bitaddr}
              if (apptype<>app_bundle) then
              if (apptype<>app_bundle) then
-               DllCmd[1]:='ld $PRTOBJ $OPT $GCSECTIONS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES'
+               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES'
              else
              else
-               DllCmd[1]:='ld $PRTOBJ $OPT $GCSECTIONS -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES'
+               DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES'
            end
            end
        end
        end
      else
      else
        begin
        begin
-         ExeCmd[1]:='ld $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP -L. -o $EXE $RES';
-         DllCmd[1]:='ld $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
+         ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP -L. -o $EXE $RES';
+         DllCmd[1]:='ld $TARGET $EMUL $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
        end;
        end;
      if not(target_info.system in systems_darwin) then
      if not(target_info.system in systems_darwin) then
        DllCmd[2]:='strip --strip-unneeded $EXE'
        DllCmd[2]:='strip --strip-unneeded $EXE'
@@ -596,6 +596,8 @@ function TLinkerBSD.MakeExecutable:boolean;
 var
 var
   binstr,
   binstr,
   cmdstr,
   cmdstr,
+  targetstr,
+  emulstr,
   extdbgbinstr,
   extdbgbinstr,
   extdbgcmdstr: TCmdStr;
   extdbgcmdstr: TCmdStr;
   linkscript: TAsmScript;
   linkscript: TAsmScript;
@@ -614,6 +616,20 @@ begin
   StripStr:='';
   StripStr:='';
   DynLinkStr:='';
   DynLinkStr:='';
   GCSectionsStr:='';
   GCSectionsStr:='';
+  { i386_freebsd needs -b elf32-i386-freebsd and -m elf_i386_fbsd
+    to avoid creation of a i386:x86_64 arch binary }
+
+  if target_info.system=system_i386_freebsd then
+    begin
+      targetstr:='-b elf32-i386-freebsd';
+      emulstr:='-m elf_i386_fbsd';
+    end
+  else
+    begin
+      targetstr:='';
+      emulstr:='';
+    end;
+
   if (cs_link_staticflag in current_settings.globalswitches) then
   if (cs_link_staticflag in current_settings.globalswitches) then
     begin
     begin
       if (target_info.system=system_m68k_netbsd) and
       if (target_info.system=system_m68k_netbsd) and
@@ -655,6 +671,8 @@ begin
   SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
   SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
   Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
   Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
+  Replace(cmdstr,'$TARGET',targetstr);
+  Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STATIC',StaticStr);
@@ -721,6 +739,8 @@ var
   linkscript: TAsmScript;
   linkscript: TAsmScript;
   binstr,
   binstr,
   cmdstr,
   cmdstr,
+  targetstr,
+  emulstr,
   extdbgbinstr,
   extdbgbinstr,
   extdbgcmdstr  : TCmdStr;
   extdbgcmdstr  : TCmdStr;
   GCSectionsStr : string[63];
   GCSectionsStr : string[63];
@@ -743,6 +763,20 @@ begin
     else
     else
       GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
       GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
 
 
+  { i386_freebsd needs -b elf32-i386-freebsd and -m elf_i386_fbsd
+    to avoid creation of a i386:x86_64 arch binary }
+
+  if target_info.system=system_i386_freebsd then
+    begin
+      targetstr:='-b elf32-i386-freebsd';
+      emulstr:='-m elf_i386_fbsd';
+    end
+  else
+    begin
+      targetstr:='';
+      emulstr:='';
+    end;
+
   InitStr:='-init FPC_LIB_START';
   InitStr:='-init FPC_LIB_START';
   FiniStr:='-fini FPC_LIB_EXIT';
   FiniStr:='-fini FPC_LIB_EXIT';
   SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
   SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
@@ -755,6 +789,8 @@ begin
   Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename)));
   Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename)));
 {$endif darwin}
 {$endif darwin}
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
+  Replace(cmdstr,'$TARGET',targetstr);
+  Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$INIT',InitStr);
   Replace(cmdstr,'$INIT',InitStr);