mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 09:26:15 +02:00
* Add code to try old GNU emulation if new names are not recognized
* Add support for map file * Add -lc (for libc library) two times instead of only at the end. git-svn-id: trunk@29521 -
This commit is contained in:
parent
aebebe4f04
commit
ce20dcf7a6
@ -115,10 +115,26 @@ implementation
|
|||||||
TLINKERsolaris
|
TLINKERsolaris
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
|
|
||||||
|
{$ifdef x86_64}
|
||||||
|
const
|
||||||
|
new_gnu_emul = '-m elf_x86_64_sol2';
|
||||||
|
old_gnu_emul = '-m elf_x86_64';
|
||||||
|
{$endif}
|
||||||
|
{$ifdef i386}
|
||||||
|
const
|
||||||
|
new_gnu_emul = '-m elf_i386_sol2';
|
||||||
|
old_gnu_emul = '-m elf_i386';
|
||||||
|
{$endif }
|
||||||
|
{$ifdef sparc}
|
||||||
|
const
|
||||||
|
{ no emulation specification needed, as long as only 32-bit is supported }
|
||||||
|
new_gnu_emul = '';
|
||||||
|
old_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 +159,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 -m elf_i386_sol2 ';
|
gld = 'gld $EMUL';
|
||||||
solaris_ld = '/usr/bin/ld ';
|
solaris_ld = '/usr/bin/ld ';
|
||||||
{$endif }
|
{$endif }
|
||||||
{$ifdef sparc}
|
{$ifdef sparc}
|
||||||
@ -163,10 +179,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';
|
ExeCmd[2]:=solaris_ld + '$OPT $DYNLINK $STATIC $STRIP -L . -o $EXE $RESDATA $REDIRECT';
|
||||||
DllCmd[1]:=gld + '$OPT $INITFINI -shared -L. -o $EXE $RES';
|
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 +258,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 +326,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;
|
||||||
@ -474,7 +491,7 @@ 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
|
||||||
if not(cs_link_nolink in current_settings.globalswitches) then
|
if not(cs_link_nolink in current_settings.globalswitches) then
|
||||||
@ -483,11 +500,22 @@ begin
|
|||||||
{ 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 +537,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',new_gnu_emul);
|
||||||
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
linkstr:='';
|
linkstr:='';
|
||||||
@ -524,12 +555,37 @@ 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)
|
BinStr:=FindUtil(utilsprefix+BinStr);
|
||||||
else { Using utilsprefix has no sense on /usr/bin/ld }
|
|
||||||
success:=DoExec(BinStr,Trim(CmdStr),true,false);
|
|
||||||
|
|
||||||
|
if (cs_link_nolink in current_settings.globalswitches) then
|
||||||
|
begin
|
||||||
|
AsmRes.Add('echo Linking '+ScriptFixFileName(current_module.exefilename));
|
||||||
|
AsmRes.Add('OFS=$IFS');
|
||||||
|
AsmRes.Add('IFS="');
|
||||||
|
AsmRes.Add('"');
|
||||||
|
AsmRes.Add(maybequoted(BinStr)+' '+Trim(cmdstr));
|
||||||
|
AsmRes.Add('if [ $? != 0 ] ; then');
|
||||||
|
AsmRes.Add('echo "Retrying with old emulation"');
|
||||||
|
Replace(cmdstr,new_gnu_emul,old_gnu_emul);
|
||||||
|
AsmRes.Add(maybequoted(BinStr)+' '+Trim(cmdstr));
|
||||||
|
AsmRes.Add('fi');
|
||||||
|
AsmRes.Add('if [ $? != 0 ]; then DoExitLink '+ScriptFixFileName(current_module.exefilename)+'; fi');
|
||||||
|
AsmRes.Add('IFS=$OFS');
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
{ We need shell if output is redirected }
|
||||||
|
success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
|
||||||
|
{ Try old emulation name if new failed }
|
||||||
|
if use_gnu_ld and (not success) and (new_gnu_emul <> '') then
|
||||||
|
begin
|
||||||
|
Replace(cmdstr,new_gnu_emul,old_gnu_emul);
|
||||||
|
success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
{ Remove ReponseFile }
|
{ Remove ReponseFile }
|
||||||
{$IFNDEF LinkTest}
|
{$IFNDEF LinkTest}
|
||||||
if (success) and use_gnu_ld and
|
if (success) and use_gnu_ld and
|
||||||
@ -543,10 +599,10 @@ end;
|
|||||||
Function TLinkersolaris.MakeSharedLibrary:boolean;
|
Function TLinkersolaris.MakeSharedLibrary:boolean;
|
||||||
var
|
var
|
||||||
InitFiniStr : string;
|
InitFiniStr : string;
|
||||||
binstr,
|
binstr, RedirectStr,
|
||||||
s, linkstr,
|
s, linkstr, MapStr,
|
||||||
cmdstr : TCmdStr;
|
cmdstr : TCmdStr;
|
||||||
success : boolean;
|
need_quotes, success : boolean;
|
||||||
begin
|
begin
|
||||||
MakeSharedLibrary:=false;
|
MakeSharedLibrary:=false;
|
||||||
if not(cs_link_nolink in current_settings.globalswitches) then
|
if not(cs_link_nolink in current_settings.globalswitches) then
|
||||||
@ -555,20 +611,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 +647,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 +669,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',new_gnu_emul);
|
||||||
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Replace(cmdstr,'$VERSIONFILE',maybequoted(outputexedir+Info.ResName));
|
Replace(cmdstr,'$VERSIONFILE',maybequoted(outputexedir+Info.ResName));
|
||||||
@ -613,12 +686,36 @@ 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)
|
BinStr:=FindUtil(utilsprefix+BinStr);
|
||||||
else { Using utilsprefix has no sense on /usr/bin/ld }
|
if (cs_link_nolink in current_settings.globalswitches) then
|
||||||
success:=DoExec(BinStr,Trim(CmdStr),true,false);
|
begin
|
||||||
|
AsmRes.Add('echo Linking '+ScriptFixFileName(current_module.exefilename));
|
||||||
|
AsmRes.Add('OFS=$IFS');
|
||||||
|
AsmRes.Add('IFS="');
|
||||||
|
AsmRes.Add('"');
|
||||||
|
AsmRes.Add(maybequoted(BinStr)+' '+Trim(cmdstr));
|
||||||
|
AsmRes.Add('if [ $? != 0 ] ; then');
|
||||||
|
AsmRes.Add('echo "Retrying with old emulation"');
|
||||||
|
Replace(cmdstr,new_gnu_emul,old_gnu_emul);
|
||||||
|
AsmRes.Add(maybequoted(BinStr)+' '+Trim(cmdstr));
|
||||||
|
AsmRes.Add('fi');
|
||||||
|
AsmRes.Add('if [ $? != 0 ]; then DoExitLink '+ScriptFixFileName(current_module.exefilename)+'; fi');
|
||||||
|
AsmRes.Add('IFS=$OFS');
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
{ We need shell if output is redirected }
|
||||||
|
success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
|
||||||
|
{ Try old emulation name if new failed }
|
||||||
|
if use_gnu_ld and (not success) and (new_gnu_emul <> '') then
|
||||||
|
begin
|
||||||
|
Replace(cmdstr,new_gnu_emul,old_gnu_emul);
|
||||||
|
success:=DoExec(BinStr,Trim(CmdStr),true,RedirectStr<>'');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
{ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user