Jelajahi Sumber

--- Merging r29501 into '.':
U compiler/systems/t_sunos.pas
--- Merging r29520 into '.':
U compiler/systems/i_sunos.pas
--- Merging r29521 into '.':
G compiler/systems/t_sunos.pas
--- Merging r29647 into '.':
G compiler/systems/t_sunos.pas
--- Merging r29549 into '.':
G compiler/systems/t_sunos.pas
--- Merging r29575 into '.':
G compiler/systems/i_sunos.pas

# revisions: 29501,29520,29521,29647,29549,29575

git-svn-id: branches/fixes_3_0@29658 -

marco 10 tahun lalu
induk
melakukan
78a734694f
2 mengubah file dengan 78 tambahan dan 29 penghapusan
  1. 2 1
      compiler/systems/i_sunos.pas
  2. 76 28
      compiler/systems/t_sunos.pas

+ 2 - 1
compiler/systems/i_sunos.pas

@@ -36,6 +36,7 @@ unit i_sunos;
             shortname    : 'solaris';
             shortname    : 'solaris';
             flags        : [tf_under_development,tf_needs_symbol_size,
             flags        : [tf_under_development,tf_needs_symbol_size,
                             tf_files_case_sensitive,tf_requires_proper_alignment,
                             tf_files_case_sensitive,tf_requires_proper_alignment,
+                            tf_pic_uses_got,tf_library_needs_pic,
                             tf_smartlink_library,tf_has_winlike_resources];
                             tf_smartlink_library,tf_has_winlike_resources];
             cpu          : cpu_i386;
             cpu          : cpu_i386;
             unit_env     : 'SOLARISUNITS';
             unit_env     : 'SOLARISUNITS';
@@ -130,7 +131,7 @@ unit i_sunos;
             Cprefix      : '';
             Cprefix      : '';
             newline      : #10;
             newline      : #10;
             dirsep       : '/';
             dirsep       : '/';
-            assem        : as_ggas{as_x86_64_elf64};
+            assem        : as_x86_64_elf64;
             assemextern  : as_ggas;
             assemextern  : as_ggas;
             link         : ld_none;
             link         : ld_none;
             linkextern   : ld_solaris;
             linkextern   : ld_solaris;

+ 76 - 28
compiler/systems/t_sunos.pas

@@ -115,10 +115,23 @@ implementation
                                   TLINKERsolaris
                                   TLINKERsolaris
 *****************************************************************************}
 *****************************************************************************}
 
 
+{$ifdef x86_64}
+const
+  gnu_emul = '-m elf_x86_64_sol2';
+{$endif}
+{$ifdef i386}
+const
+  gnu_emul = '-m elf_i386_sol2';
+{$endif }
+{$ifdef sparc}
+const
+  { no emulation specification needed, as long as only 32-bit is supported }
+  gnu_emul = '';
+{$endif}
+
 Constructor TLinkersolaris.Create;
 Constructor TLinkersolaris.Create;
 begin
 begin
   Inherited Create;
   Inherited Create;
-
   if cs_link_native in init_settings.globalswitches then
   if cs_link_native in init_settings.globalswitches then
     use_gnu_ld:=false
     use_gnu_ld:=false
   else
   else
@@ -143,12 +156,12 @@ procedure TLinkersolaris.SetDefaultInfo;
 }
 }
 {$ifdef x86_64}
 {$ifdef x86_64}
 const
 const
-  gld = 'gld -m elf_x86_64_sol2 ';
+  gld = 'gld $EMUL ';
   solaris_ld = '/usr/bin/ld -64 ';
   solaris_ld = '/usr/bin/ld -64 ';
 {$endif}
 {$endif}
 {$ifdef i386}
 {$ifdef i386}
 const
 const
-  gld = 'gld ';
+  gld = 'gld $EMUL';
   solaris_ld = '/usr/bin/ld ';
   solaris_ld = '/usr/bin/ld ';
 {$endif }
 {$endif }
 {$ifdef sparc}
 {$ifdef sparc}
@@ -163,10 +176,10 @@ begin
    begin
    begin
 {$IFDEF GnuLd}
 {$IFDEF GnuLd}
      ExeCmd[1]:=gld + '$OPT $DYNLINK $STATIC $STRIP -L. -o $EXE $RES';
      ExeCmd[1]:=gld + '$OPT $DYNLINK $STATIC $STRIP -L. -o $EXE $RES';
-     ExeCmd[2]:=solaris_ld + '$OPT $DYNLINK $STATIC $STRIP -L . -o $EXE $RESDATA';
-     DllCmd[1]:=gld + '$OPT $INITFINI -shared -L. -o $EXE $RES';
+     ExeCmd[2]:=solaris_ld + '$OPT $DYNLINK $STATIC $STRIP -L . -o $EXE $RESDATA $REDIRECT';
+     DllCmd[1]:=gld + '$OPT $INITFINI -shared -L. $MAP -o $EXE $RES';
      DllCmd[2]:='gstrip --strip-unneeded $EXE';
      DllCmd[2]:='gstrip --strip-unneeded $EXE';
-     DllCmd[3]:=solaris_ld + '$OPT $INITFINI -M $VERSIONFILE -G -Bdynamic -L. -o $EXE $RESDATA';
+     DllCmd[3]:=solaris_ld + '$OPT $INITFINI -M $VERSIONFILE $MAP -G -Bdynamic -L. -o $EXE $RESDATA $REDIRECT';
      DynamicLinker:=''; { Gnu uses the default }
      DynamicLinker:=''; { Gnu uses the default }
      Glibc21:=false;
      Glibc21:=false;
 {$ELSE}
 {$ELSE}
@@ -242,7 +255,7 @@ begin
   if (isdll) then
   if (isdll) then
     begin
     begin
       LinkRes.add('VERSION');
       LinkRes.add('VERSION');
-      LinkRes.add('{');
+      LinkRes.add('{ DEFAULT'); { gld 2.25 does not support anonymous version }
       LinkRes.add('  {');
       LinkRes.add('  {');
       if not texportlibunix(exportlib).exportedsymnames.empty then
       if not texportlibunix(exportlib).exportedsymnames.empty then
         begin
         begin
@@ -310,6 +323,7 @@ begin
          end
          end
         else
         else
          begin
          begin
+           LinkRes.Add('-lc');
            linklibc:=true;
            linklibc:=true;
            linkdynamic:=false; { libc will include the ld-solaris (war ld-linux) for us }
            linkdynamic:=false; { libc will include the ld-solaris (war ld-linux) for us }
          end;
          end;
@@ -409,13 +423,13 @@ begin
   { Write staticlibraries }
   { Write staticlibraries }
   if not StaticLibFiles.Empty then
   if not StaticLibFiles.Empty then
    begin
    begin
-     linkres.add('-('); 
+     linkres.add('-(');
      While not StaticLibFiles.Empty do
      While not StaticLibFiles.Empty do
       begin
       begin
         S:=StaticLibFiles.GetFirst;
         S:=StaticLibFiles.GetFirst;
         LinkRes.AddFileName(maybequoted(s))
         LinkRes.AddFileName(maybequoted(s))
       end;
       end;
-     linkres.add('-)'); 
+     linkres.add('-)');
    end;
    end;
 
 
   { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
   { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
@@ -474,20 +488,32 @@ var
   cmdstr  : TCmdStr;
   cmdstr  : TCmdStr;
   success : boolean;
   success : boolean;
   DynLinkStr : string[60];
   DynLinkStr : string[60];
-  StaticStr,
+  StaticStr, RedirectStr,
   StripStr   : string[40];
   StripStr   : string[40];
 begin
 begin
+  success:=false;
   if not(cs_link_nolink in current_settings.globalswitches) then
   if not(cs_link_nolink in current_settings.globalswitches) then
    Message1(exec_i_linking,current_module.exefilename);
    Message1(exec_i_linking,current_module.exefilename);
 
 
 { Create some replacements }
 { Create some replacements }
   StaticStr:='';
   StaticStr:='';
   StripStr:='';
   StripStr:='';
+  RedirectStr:='';
   DynLinkStr:='';
   DynLinkStr:='';
   if (cs_link_staticflag in current_settings.globalswitches) then
   if (cs_link_staticflag in current_settings.globalswitches) then
     StaticStr:='-Bstatic';
     StaticStr:='-Bstatic';
   if (cs_link_strip in current_settings.globalswitches) then
   if (cs_link_strip in current_settings.globalswitches) then
    StripStr:='-s';
    StripStr:='-s';
+  if (cs_link_map in current_settings.globalswitches) then
+   begin
+     if use_gnu_ld then
+       StripStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'))
+     else
+       begin
+         StripStr:='-m';
+         RedirectStr:=' > '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
+       end;
+   end;
   If (cs_profile in current_settings.moduleswitches) or
   If (cs_profile in current_settings.moduleswitches) or
      ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
      ((Info.DynamicLinker<>'') and (not SharedLibFiles.Empty)) then
    DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
    DynLinkStr:='-dynamic-linker='+Info.DynamicLinker;
@@ -509,7 +535,10 @@ begin
   Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
   Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   if use_gnu_ld then
   if use_gnu_ld then
-    Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName))
+    begin
+      Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+      Replace(cmdstr,'$EMUL',gnu_emul);
+    end
   else
   else
     begin
     begin
       linkstr:='';
       linkstr:='';
@@ -524,12 +553,13 @@ begin
     end;
     end;
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$STRIP',StripStr);
+  Replace(cmdstr,'$REDIRECT',RedirectStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
   if BinStr[1]<>'/' then
   if BinStr[1]<>'/' then
-    success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false)
-  else { Using utilsprefix has no sense on /usr/bin/ld }
-    success:=DoExec(BinStr,Trim(CmdStr),true,false);
+    BinStr:=FindUtil(utilsprefix+BinStr);
 
 
+  { We need shell if output is redirected }
+  success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
 { Remove ReponseFile }
 { Remove ReponseFile }
 {$IFNDEF LinkTest}
 {$IFNDEF LinkTest}
   if (success) and use_gnu_ld and
   if (success) and use_gnu_ld and
@@ -543,11 +573,12 @@ end;
 Function TLinkersolaris.MakeSharedLibrary:boolean;
 Function TLinkersolaris.MakeSharedLibrary:boolean;
 var
 var
   InitFiniStr : string;
   InitFiniStr : string;
-  binstr,
-  s, linkstr,
+  binstr, RedirectStr,
+  s, linkstr, MapStr,
   cmdstr  : TCmdStr;
   cmdstr  : TCmdStr;
-  success : boolean;
+  need_quotes, success : boolean;
 begin
 begin
+  success:=false;
   MakeSharedLibrary:=false;
   MakeSharedLibrary:=false;
   if not(cs_link_nolink in current_settings.globalswitches) then
   if not(cs_link_nolink in current_settings.globalswitches) then
    Message1(exec_i_linking,current_module.sharedlibfilename);
    Message1(exec_i_linking,current_module.sharedlibfilename);
@@ -555,20 +586,34 @@ begin
 { Write used files and libraries }
 { Write used files and libraries }
   WriteResponseFile(true);
   WriteResponseFile(true);
 
 
+  RedirectStr:='';
+  MapStr:='';
 { Create some replacements }
 { Create some replacements }
+  if (cs_link_map in current_settings.globalswitches) then
+   begin
+     if use_gnu_ld then
+       MapStr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'))
+     else
+       begin
+         MapStr:='-m';
+         RedirectStr:=' > '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
+       end;
+   end;
+  need_quotes:= (cs_link_nolink in current_settings.globalswitches) or
+                (RedirectStr<>'');
 { initname and fininame may contain $, which can be wrongly interpreted
 { initname and fininame may contain $, which can be wrongly interpreted
-  in a link script, thus we surround them with single quotes 
+  in a link script, thus we surround them with single quotes
   in cs_link_nolink is in globalswitches }
   in cs_link_nolink is in globalswitches }
   if use_gnu_ld then
   if use_gnu_ld then
     begin
     begin
       InitFiniStr:='-init ';
       InitFiniStr:='-init ';
-      if cs_link_nolink in current_settings.globalswitches then
+      if need_quotes then
         InitFiniStr:=InitFiniStr+''''+exportlib.initname+''''
         InitFiniStr:=InitFiniStr+''''+exportlib.initname+''''
       else
       else
         InitFiniStr:=InitFiniStr+exportlib.initname;
         InitFiniStr:=InitFiniStr+exportlib.initname;
       if (exportlib.fininame<>'') then
       if (exportlib.fininame<>'') then
         begin
         begin
-          if cs_link_nolink in current_settings.globalswitches then
+          if need_quotes then
             InitFiniStr:=InitFiniStr+' -fini '''+exportlib.initname+''''
             InitFiniStr:=InitFiniStr+' -fini '''+exportlib.initname+''''
           else
           else
             InitFiniStr:=InitFiniStr+' -fini '+exportlib.fininame;
             InitFiniStr:=InitFiniStr+' -fini '+exportlib.fininame;
@@ -577,13 +622,13 @@ begin
   else
   else
     begin
     begin
       InitFiniStr:='-z initarray=';
       InitFiniStr:='-z initarray=';
-      if cs_link_nolink in current_settings.globalswitches then
+      if need_quotes then
         InitFiniStr:=InitFiniStr+''''+exportlib.initname+''''
         InitFiniStr:=InitFiniStr+''''+exportlib.initname+''''
       else
       else
         InitFiniStr:=InitFiniStr+exportlib.initname;
         InitFiniStr:=InitFiniStr+exportlib.initname;
       if (exportlib.fininame<>'') then
       if (exportlib.fininame<>'') then
         begin
         begin
-          if cs_link_nolink in current_settings.globalswitches then
+          if need_quotes then
             InitFiniStr:=InitFiniStr+' -z finiarray='''+exportlib.initname+''''
             InitFiniStr:=InitFiniStr+' -z finiarray='''+exportlib.initname+''''
           else
           else
             InitFiniStr:=InitFiniStr+' -z finiarray='+exportlib.fininame;
             InitFiniStr:=InitFiniStr+' -z finiarray='+exportlib.fininame;
@@ -599,7 +644,10 @@ begin
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$INITFINI',InitFiniStr);
   Replace(cmdstr,'$INITFINI',InitFiniStr);
   if use_gnu_ld then
   if use_gnu_ld then
-    Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName))
+    begin
+      Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+      Replace(cmdstr,'$EMUL',gnu_emul);
+    end
   else
   else
     begin
     begin
       Replace(cmdstr,'$VERSIONFILE',maybequoted(outputexedir+Info.ResName));
       Replace(cmdstr,'$VERSIONFILE',maybequoted(outputexedir+Info.ResName));
@@ -613,12 +661,12 @@ begin
       linkres.free;
       linkres.free;
       Replace(cmdstr,'$RESDATA',linkstr);
       Replace(cmdstr,'$RESDATA',linkstr);
     end;
     end;
+  Replace(cmdstr,'$REDIRECT',RedirectStr);
+  Replace(cmdstr,'$MAP',MapStr);
   if BinStr[1]<>'/' then
   if BinStr[1]<>'/' then
-    success:=DoExec(FindUtil(utilsprefix+BinStr),CmdStr,true,false)
-  else { Using utilsprefix has no sense on /usr/bin/ld }
-    success:=DoExec(BinStr,Trim(CmdStr),true,false);
-
-
+    BinStr:=FindUtil(utilsprefix+BinStr);
+  { We need shell if output is redirected }
+  success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
 { Strip the library ? }
 { Strip the library ? }
   if success and (cs_link_strip in current_settings.globalswitches) then
   if success and (cs_link_strip in current_settings.globalswitches) then
    begin
    begin