* fixed static linking under Linux for ppc64; test still crashes under

linux/i386 and linux/x86_64 (but at least it links now, mantis #14265)

git-svn-id: trunk@13584 -
This commit is contained in:
Jonas Maebe 2009-08-23 11:53:00 +00:00
parent c2c68ddb8f
commit 9a84dee059
3 changed files with 95 additions and 26 deletions

1
.gitattributes vendored
View File

@ -8066,6 +8066,7 @@ tests/test/packages/webtbs/tw10045.pp svneol=native#text/plain
tests/test/packages/webtbs/tw11142.pp svneol=native#text/plain
tests/test/packages/webtbs/tw11570.pp svneol=native#text/plain
tests/test/packages/webtbs/tw12830.pp svneol=native#text/plain
tests/test/packages/webtbs/tw14265.pp svneol=native#text/plain
tests/test/packages/webtbs/tw1808.pp svneol=native#text/plain
tests/test/packages/webtbs/tw3820.pp svneol=native#text/plain
tests/test/packages/win-base/tdispvar1.pp svneol=native#text/plain

View File

@ -380,6 +380,10 @@ begin
{ try to add crti and crtbegin if linking to C }
if linklibc and (libctype<>uclibc) then
begin
{ crti.o must come first }
if librarysearchpath.FindFile('crti.o',false,s) then
AddFileName(s);
{ then the crtbegin* }
{ x86_64 requires this to use entry/exit code with pic,
see also issue #8210 regarding a discussion
no idea about the other non i386 CPUs (FK)
@ -392,10 +396,11 @@ begin
end
else
{$endif x86_64}
if librarysearchpath.FindFile('crtbegin.o',false,s) then
if (cs_link_staticflag in current_settings.globalswitches) and
librarysearchpath.FindFile('crtbeginT.o',false,s) then
AddFileName(s)
else if librarysearchpath.FindFile('crtbegin.o',false,s) then
AddFileName(s);
if librarysearchpath.FindFile('crti.o',false,s) then
AddFileName(s);
end;
{ main objectfiles }
while not ObjectFiles.Empty do
@ -429,29 +434,44 @@ begin
if not SharedLibFiles.Empty then
begin
Add('INPUT(');
While not SharedLibFiles.Empty do
begin
S:=SharedLibFiles.GetFirst;
if (s<>'c') or reorder then
begin
i:=Pos(target_info.sharedlibext,S);
if i>0 then
Delete(S,i,255);
Add('-l'+s);
end
else
begin
linklibc:=true;
end;
end;
{ be sure that libc is the last lib }
if linklibc and not reorder then
Add('-lc');
{ when we have -static for the linker the we also need libgcc }
if (cs_link_staticflag in current_settings.globalswitches) then
Add('-lgcc');
Add(')');
if (SharedLibFiles.Count<>1) or
(TCmdStrListItem(SharedLibFiles.First).Str<>'c') or
reorder then
begin
Add('INPUT(');
While not SharedLibFiles.Empty do
begin
S:=SharedLibFiles.GetFirst;
if (s<>'c') or reorder then
begin
i:=Pos(target_info.sharedlibext,S);
if i>0 then
Delete(S,i,255);
Add('-l'+s);
end
else
begin
linklibc:=true;
end;
end;
Add(')');
end;
if (cs_link_staticflag in current_settings.globalswitches) or
(linklibc and not reorder) then
begin
Add('GROUP(');
{ when we have -static for the linker the we also need libgcc }
if (cs_link_staticflag in current_settings.globalswitches) then
begin
Add('-lgcc');
if librarysearchpath.FindFile('libgcc_eh.a',false,s1) then
Add('-lgcc_eh');
end;
{ be sure that libc is the last lib }
if linklibc and not reorder then
Add('-lc');
Add(')');
end;
end;
{ objects which must be at the end }

View File

@ -0,0 +1,48 @@
{ %target=linux }
{ %opt=-Xt }
program phello;
{$linklib c}
{$packrecords c}
uses
ctypes, unixtype, pthreads;
const N = 2;
var
res:array[1..N] of Integer;
function Hello(arg: pointer): longint; cdecl;
begin
// writeln('Hello from thread #', PInteger(arg)^);
res[PInteger(arg)^] := PInteger(arg)^;
Hello := 0;
pthread_exit(pointer(Hello));
end;
var
i: Integer;
ret: Pointer;
arg: array[1..N] of Integer;
threads: array[1..N] of TThreadID;
attr: TThreadAttr;
begin
Writeln('Testing simple thread creation');
pthread_attr_init(attr);
for i := 1 to N do
begin
Writeln('Creating thread #',i);
arg[i] := i;
if pthread_create(threads[i], attr, @Hello, @arg[i]) <> 0 then
Writeln('Failed to create thread');
end;
for i := 1 to N do
begin
Write('Waiting for thread #',i, ' ... ');
pthread_join(threads[i], ret);
Writeln('result: ', res[i]);
end;
end.