فهرست منبع

* experimental fix for #8210

git-svn-id: trunk@6948 -
florian 18 سال پیش
والد
کامیت
8c8042aaf0
3فایلهای تغییر یافته به همراه81 افزوده شده و 4 حذف شده
  1. 1 0
      .gitattributes
  2. 26 4
      compiler/systems/t_linux.pas
  3. 54 0
      tests/test/tlibrary3.pp

+ 1 - 0
.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

+ 26 - 4
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

+ 54 - 0
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}