+ implement pascal inline asm start/halt code for linux/i386

git-svn-id: trunk@5181 -
This commit is contained in:
micha 2006-11-02 16:58:41 +00:00
parent e754f21053
commit ad7d549965
8 changed files with 117 additions and 7 deletions

View File

@ -45,6 +45,9 @@
{$define SUPPORT_MMX}
{$define cpumm}
{$define fewintregisters}
{$ifdef linux}
{$define has_internal_sysinit}
{$endif}
{$endif i386}
{$ifdef x86_64}

View File

@ -47,6 +47,7 @@ interface
public
HasResources,
HasExports : boolean;
SysInitUnit : string[20];
ObjectFiles,
SharedLibFiles,
StaticLibFiles : TStringList;
@ -59,6 +60,7 @@ interface
Procedure AddStaticCLibrary(const S : String);
Procedure AddSharedCLibrary(S : String);
procedure AddImportSymbol(const libname,symname:string;OrdNr: longint;isvar:boolean);virtual;
Procedure InitSysInitUnitName;virtual;
Function MakeExecutable:boolean;virtual;
Function MakeSharedLibrary:boolean;virtual;
Function MakeStaticLibrary:boolean;virtual;
@ -472,6 +474,10 @@ Implementation
end;
procedure TLinker.InitSysInitUnitName;
begin
end;
function TLinker.MakeExecutable:boolean;
begin
MakeExecutable:=false;

View File

@ -1395,6 +1395,13 @@ implementation
{ do we need to add the variants unit? }
maybeloadvariantsunit;
{$ifdef has_internal_sysinit}
linker.initsysinitunitname;
{ add start/halt unit }
AddUnit('si_'+linker.sysinitunit);
{$endif}
{$ifdef arm}
{ Insert .pdata section for arm-wince.
It is needed for exception handling. }

View File

@ -87,8 +87,11 @@ type
end;
TLinkRes = Class (TScript)
section: string[30];
procedure Add(const s:string);
procedure AddFileName(const s:string);
procedure EndSection(const s:string);
procedure StartSection(const s:string);
end;
var
@ -495,6 +498,11 @@ end;
procedure TLinkRes.AddFileName(const s:string);
begin
if section<>'' then
begin
inherited Add(section);
section:='';
end;
if s<>'' then
begin
if not(s[1] in ['a'..'z','A'..'Z','/','\','.','"']) then
@ -509,4 +517,17 @@ begin
end;
end;
procedure TLinkRes.EndSection(const s:string);
begin
{ only terminate if we started the section }
if section='' then
inherited Add(s);
section:='';
end;
procedure TLinkRes.StartSection(const s:string);
begin
section:=s;
end;
end.

View File

@ -45,10 +45,17 @@ interface
tlinkerlinux=class(texternallinker)
private
libctype:(libc5,glibc2,glibc21,uclibc);
{$ifdef has_internal_sysinit}
reorder : boolean;
linklibc: boolean;
{$endif}
Function WriteResponseFile(isdll:boolean) : Boolean;
public
constructor Create;override;
procedure SetDefaultInfo;override;
{$ifdef has_internal_sysinit}
procedure InitSysInitUnitName;override;
{$endif}
function MakeExecutable:boolean;override;
function MakeSharedLibrary:boolean;override;
function postprocessexecutable(const fn : string;isdll:boolean):boolean;
@ -307,22 +314,80 @@ Begin
end;
End;
{$ifdef has_internal_sysinit}
Procedure TLinkerLinux.InitSysInitUnitName;
var
csysinitunit,
gsysinitunit : string[20];
hp : tmodule;
begin
hp:=tmodule(loaded_units.first);
while assigned(hp) do
begin
linklibc := hp.linkunitsharedlibs.find('c');
if linklibc then break;
hp:=tmodule(hp.next);
end;
reorder := linklibc and ReOrderEntries;
if islibrary then
begin
sysinitunit:='dll';
csysinitunit:='dll';
gsysinitunit:='dll';
end
else
begin
sysinitunit:='prc';
case libctype of
glibc21:
begin
csysinitunit:='c21';
gsysinitunit:='c21g';
end;
uclibc:
begin
csysinitunit:='uc';
gsysinitunit:='ucg';
end
else
csysinitunit:='c';
gsysinitunit:='g';
end;
end;
if cs_profile in current_settings.moduleswitches then
begin
sysinitunit:=gsysinitunit;
linklibc:=true;
end
else
begin
if linklibc then
sysinitunit:=csysinitunit;
end;
end;
{$endif}
Function TLinkerLinux.WriteResponseFile(isdll:boolean) : Boolean;
Var
linkres : TLinkRes;
i : longint;
{$ifndef has_internal_sysinit}
cprtobj,
gprtobj,
prtobj : string[80];
reorder,
linklibc : boolean;
{$endif}
HPath : TStringListItem;
s,s1,s2 : string;
found1,
found2,
Reorder,
linklibc : boolean;
found2 : boolean;
begin
result:=False;
{ set special options for some targets }
{$ifndef has_internal_sysinit}
linklibc:=(SharedLibFiles.Find('c')<>nil);
reorder := linklibc and ReOrderEntries;
if isdll then
@ -350,9 +415,12 @@ begin
gprtobj:='gprt0';
end;
end;
{$endif}
if cs_profile in current_settings.moduleswitches then
begin
{$ifndef has_internal_sysinit}
prtobj:=gprtobj;
{$endif}
if not(libctype in [glibc2,glibc21]) then
AddSharedLibrary('gmon');
AddSharedLibrary('c');
@ -360,8 +428,10 @@ begin
end
else
begin
{$ifndef has_internal_sysinit}
if linklibc then
prtobj:=cprtobj;
{$endif}
end;
{ Open link.res file }
@ -382,10 +452,12 @@ begin
HPath:=TStringListItem(HPath.Next);
end;
Add('INPUT(');
StartSection('INPUT(');
{$ifndef has_internal_sysinit}
{ add objectfiles, start with prt0 always }
if prtobj<>'' then
AddFileName(maybequoted(FindObjectFile(prtobj,'',false)));
{$endif}
{ try to add crti and crtbegin if linking to C }
if linklibc then
begin
@ -401,7 +473,7 @@ begin
if s<>'' then
AddFileName(maybequoted(s));
end;
Add(')');
EndSection(')');
{ Write staticlibraries }
if not StaticLibFiles.Empty then

View File

@ -342,7 +342,7 @@ const
InitProc : Pointer = nil;
var
ExitCode : Word; public name 'operatingsystem_result';
ExitCode : Word; {$ifdef VER2_0} public name 'operatingsystem_result'; {$endif}
RandSeed : Cardinal;
{ Delphi compatibility }
IsLibrary : boolean = false;

View File

@ -251,7 +251,7 @@ override FPCOPT+=-Ur
endif
OBJPASDIR=$(RTL)/objpas
ifeq ($(FULL_TARGET),i386-linux)
override TARGET_UNITS+=$(SYSTEMUNIT) unixtype ctypes baseunix strings objpas macpas syscall unixutil heaptrc lineinfo termio unix linux initc cmem $(CPU_UNITS) crt printer linuxvcs sysutils typinfo math matrix varutils charset ucomplex getopts errors sockets gpm ipc serial terminfo dl dynlibs video mouse keyboard variants types dateutils sysconst fmtbcd cthreads classes convutils stdconvs strutils rtlconsts dos objects cwstring fpcylix
override TARGET_UNITS+=$(SYSTEMUNIT) unixtype ctypes baseunix strings objpas macpas syscall unixutil heaptrc lineinfo termio unix linux initc cmem $(CPU_UNITS) crt printer linuxvcs sysutils typinfo math matrix varutils charset ucomplex getopts errors sockets gpm ipc serial terminfo dl dynlibs video mouse keyboard variants types dateutils sysconst fmtbcd cthreads classes convutils stdconvs strutils rtlconsts dos objects cwstring fpcylix si_prc si_c21g si_c21 si_c si_dll
endif
ifeq ($(FULL_TARGET),i386-go32v2)
override TARGET_UNITS+=$(SYSTEMUNIT) unixtype ctypes baseunix strings objpas macpas syscall unixutil heaptrc lineinfo termio unix linux initc cmem $(CPU_UNITS) crt printer linuxvcs sysutils typinfo math matrix varutils charset ucomplex getopts errors sockets gpm ipc serial terminfo dl dynlibs video mouse keyboard variants types dateutils sysconst fmtbcd cthreads classes convutils stdconvs strutils rtlconsts dos objects cwstring fpcylix

View File

@ -16,6 +16,7 @@ units=$(SYSTEMUNIT) unixtype ctypes baseunix strings objpas macpas syscall unixu
errors sockets gpm ipc serial terminfo dl dynlibs \
video mouse keyboard variants types dateutils sysconst fmtbcd \
cthreads classes convutils stdconvs strutils rtlconsts dos objects cwstring fpcylix
units_i386_linux=si_prc si_c21g si_c21 si_c si_dll
rsts=math varutils typinfo variants sysconst rtlconsts stdconvs