diff --git a/.gitattributes b/.gitattributes index 6d9845f026..a3a8db0547 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6793,6 +6793,7 @@ tests/test/tintfdef.pp svneol=native#text/plain tests/test/tintuint.pp svneol=native#text/plain tests/test/tlibrary1.pp svneol=native#text/plain tests/test/tlibrary2.pp svneol=native#text/plain +tests/test/tlibrary3.pp svneol=native#text/plain tests/test/tmacbool.pp svneol=native#text/plain tests/test/tmacfunret.pp svneol=native#text/plain tests/test/tmaclocalprocparam.pp svneol=native#text/plain diff --git a/compiler/systems/t_linux.pas b/compiler/systems/t_linux.pas index c041a2a697..8e444fff60 100644 --- a/compiler/systems/t_linux.pas +++ b/compiler/systems/t_linux.pas @@ -425,10 +425,22 @@ begin { try to add crti and crtbegin if linking to C } if linklibc then begin - if librarysearchpath.FindFile('crtbegin.o',false,s) then - AddFileName(s); + { 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) + } +{$ifdef x86_64} + if current_module.islibrary then + begin + if librarysearchpath.FindFile('crtbeginS.o',false,s) then + AddFileName(s); + end + else +{$endif x86_64} + if librarysearchpath.FindFile('crtbegin.o',false,s) then + AddFileName(s); if librarysearchpath.FindFile('crti.o',false,s) then - AddFileName(s); + AddFileName(s); end; { main objectfiles } while not ObjectFiles.Empty do @@ -490,7 +502,17 @@ begin { objects which must be at the end } if linklibc and (libctype<>uclibc) then begin - found1:=librarysearchpath.FindFile('crtend.o',false,s1); + { 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) + } +{$ifdef x86_64} + if current_module.islibrary then + found1:=librarysearchpath.FindFile('crtendS.o',false,s1) + else +{$else x86_64} + found1:=librarysearchpath.FindFile('crtend.o',false,s1); +{$endif x86_64} found2:=librarysearchpath.FindFile('crtn.o',false,s2); if found1 or found2 then begin diff --git a/tests/test/tlibrary3.pp b/tests/test/tlibrary3.pp new file mode 100644 index 0000000000..acca9fa289 --- /dev/null +++ b/tests/test/tlibrary3.pp @@ -0,0 +1,54 @@ +{ %NORUN } +{ %SKIPTARGET=macos } + +{$ifdef CPUX86_64} +{$ifndef WINDOWS} +{$PIC+} +{$endif WINDOWS} +{$endif CPUX86_64} + +{ The .so of the library needs to be in the current dir when + testing the loading at runtime } + +{$ifdef mswindows} + {$define supported} + {$define supportidx} +{$endif win32} +{$ifdef Unix} + {$define supported} +{$endif Unix} +{$ifndef fpc} + {$define supported} +{$endif} + +{$ifdef supported} + +library bug; + +uses + initc; + +const + publicname='TestName'; + publicindex = 1234; + +procedure Test;export; + + begin +// writeln('Hoi'); + end; + +exports + Test name publicname; +{$ifdef supportidx} +exports + Test index publicindex; +{$endif} + +begin +end. +{$else supported} +begin + Writeln('No library for that target'); +end. +{$endif supported}