Quellcode durchsuchen

* fixed shared library initialisation for FPC-compiled libraries
when linked to FPC-compiled programs under linux/i386 which
do not use libc + test (mantis #8730). Programs which do use
libc and other linux targets have to be fixed in a similar
way until we properly fix everything by not exporting
any symbols at all from shared libraries by default (and
only those appearing in the "exports" section).

Finalisation does not work yet either for FPC-compiled
programs on linux/anything.

git-svn-id: trunk@10495 -

Jonas Maebe vor 17 Jahren
Ursprung
Commit
3eec0569be

+ 5 - 0
.gitattributes

@@ -8918,6 +8918,9 @@ tests/webtbs/tw8677.pp svneol=native#text/plain
 tests/webtbs/tw8678.pp svneol=native#text/plain
 tests/webtbs/tw8678a.pp svneol=native#text/plain
 tests/webtbs/tw8685.pp svneol=native#text/plain
+tests/webtbs/tw8730a.pp svneol=native#text/plain
+tests/webtbs/tw8730b.pp svneol=native#text/plain
+tests/webtbs/tw8730c.pp svneol=native#text/plain
 tests/webtbs/tw8757.pp svneol=native#text/plain
 tests/webtbs/tw8777f.pp svneol=native#text/plain
 tests/webtbs/tw8777g.pp svneol=native#text/plain
@@ -9045,6 +9048,8 @@ tests/webtbs/uw6767.pp svneol=native#text/plain
 tests/webtbs/uw7381.pp svneol=native#text/plain
 tests/webtbs/uw8180.pp svneol=native#text/plain
 tests/webtbs/uw8372.pp svneol=native#text/plain
+tests/webtbs/uw8730a.pp svneol=native#text/plain
+tests/webtbs/uw8730b.pp svneol=native#text/plain
 tests/webtbs/uw9113a.pp svneol=native#text/plain
 tests/webtbs/uw9113b.pp svneol=native#text/plain
 utils/Makefile svneol=native#text/plain

+ 30 - 1
compiler/systems/t_linux.pas

@@ -239,7 +239,7 @@ begin
      if length(sysrootpath) > 0 then
        ExeCmd[1]:=ExeCmd[1]+' -T';
      ExeCmd[1]:=ExeCmd[1]+' $RES';
-     DllCmd[1]:='ld '+platform_select+' $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES -E';
+     DllCmd[1]:='ld '+platform_select+' $OPT $INIT $FINI $SONAME -shared -L. -o $EXE $RES';
      DllCmd[2]:='strip --strip-unneeded $EXE';
      ExtDbgCmd[1]:='objcopy --only-keep-debug $EXE $DBG';
      ExtDbgCmd[2]:='objcopy --add-gnu-debuglink=$DBG $EXE';
@@ -425,6 +425,35 @@ begin
          HPath:=TCmdStrListItem(HPath.Next);
        end;
 
+      { force local symbol resolution (i.e., inside the shared }
+      { library itself) for a number of global symbols which   }
+      { appear in every FPC-compiled program/library. This is  }
+      { actually the wrong approach (the right one is to make  }
+      { everything local, except for what appears in the       }
+      { "exports" statements), but it fixes some of the worst  }
+      { problems for now.                                      }
+      if (isdll) then
+        begin
+          add('VERSION');
+          add('{');
+          add('  {');
+          add('    local:');
+          add('      __fpc_valgrind;');
+          add('      __heapsize;');
+          add('      __stklen;');
+          add('      _FPC_SHARED_LIB_START_LOCAL;');
+          add('      FPC_FINALIZEUNITS;');
+          add('      FPC_INITIALIZEUNITS;');
+          add('      FPC_RESLOCATION;');
+          add('      FPC_RESOURCESTRINGTABLES;');
+          add('      FPC_THREADVARTABLES;');
+          add('      INITFINAL;');
+          add('      PASCALFINALIZE;');
+          add('      PASCALMAIN;');
+          add('  };');
+          add('}');
+        end;
+
       StartSection('INPUT(');
       { add objectfiles, start with prt0 always }
       if not (target_info.system in system_internal_sysinit) and (prtobj<>'') then

+ 8 - 3
rtl/linux/i386/si_dll.inc

@@ -40,7 +40,7 @@ procedure PASCALMAIN; external name 'PASCALMAIN';
  ******************************************************************************}
 {$asmmode ATT}
 
-procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name '_start';
+procedure _FPC_shared_lib_start(argc : dword;argv,envp : pointer); cdecl; public name '_FPC_SHARED_LIB_START_LOCAL'; public name '_start';
 begin
   { we've to discuss about the use of this ;) }
   asm
@@ -58,6 +58,11 @@ begin
 end;
 
 {$ifndef VER2_0}
+
+{ this hack is needed so we can make the reference below to _FPC_shared_lib_start }
+{ local in compiler/systems/t_linux.pas                                           }
+procedure _FPC_SHARED_LIB_START_LOCAL(argc : dword;argv,envp : pointer); cdecl; external;
+
 procedure initdummy; assembler; nostackframe;
 label
   FPC_LIB_START;
@@ -68,9 +73,9 @@ asm
 //    .type FPC_LIB_START,@function
 FPC_LIB_START:
 {$ifdef FPC_PIC}
-  jmp	_FPC_shared_lib_start@PLT
+  jmp	_FPC_SHARED_LIB_START_LOCAL@PLT
 {$else FPC_PIC}
-  jmp	_FPC_shared_lib_start
+  jmp	_FPC_SHARED_LIB_START_LOCAL
 {$endif FPC_PIC}
 .text
 end;

+ 25 - 0
tests/webtbs/tw8730a.pp

@@ -0,0 +1,25 @@
+{ %norun }
+{ %target=win32,win64,wince,darwin,linux,freebsd,solaris,beos}
+
+{$mode delphi}
+
+{$ifdef darwin}
+{$PIC+}
+{$endif darwin}
+
+{$ifdef CPUX86_64}
+{$ifndef WINDOWS}
+{$PIC+}
+{$endif WINDOWS}
+{$endif CPUX86_64}
+
+library tw8730a;
+
+uses uw8730a;
+
+exports
+_Lib1Func;
+
+end.
+
+//= END OF FILE ===============================================================

+ 35 - 0
tests/webtbs/tw8730b.pp

@@ -0,0 +1,35 @@
+{ %norun }
+{ %target=win32,win64,wince,darwin,linux,freebsd,solaris,beos}
+{ %NEEDLIBRARY }
+
+{$mode delphi}
+
+{$ifdef darwin}
+{$PIC+}
+{$endif darwin}
+
+{$ifdef CPUX86_64}
+{$ifndef WINDOWS}
+{$PIC+}
+{$endif WINDOWS}
+{$endif CPUX86_64}
+
+library tw8730b;
+
+{$ifndef windows}
+  {$linklib tw8730a}
+{$endif}
+
+
+uses uw8730b;
+
+exports
+{$if defined(darwin) or defined(win32) or defined(wince)}
+Lib2Func name '_Lib2Func';
+{$else}
+Lib2Func;
+{$endif}
+
+end.
+
+//= END OF FILE ===============================================================

+ 25 - 0
tests/webtbs/tw8730c.pp

@@ -0,0 +1,25 @@
+{ %target=win32,win64,wince,darwin,linux,freebsd,solaris,beos}
+{ %NEEDLIBRARY }
+
+{$mode delphi}
+program MainApp;
+
+uses
+  sysutils;
+
+const
+{$ifdef windows}
+  libname='tw8730b.dll';
+{$else}
+  libname='tw8730b';
+  {$linklib tw8730b}
+{$endif}
+
+function Lib2Func: pchar; CDecl; external libname name 'Lib2Func';
+
+begin
+  WriteLn( Lib2Func );
+  if not(fileexists('tw8730a.txt')) or
+     not(fileexists('tw8730b.txt')) then
+    halt(1);
+end.

+ 36 - 0
tests/webtbs/uw8730a.pp

@@ -0,0 +1,36 @@
+{$mode delphi}
+
+{$ifdef darwin}
+{$PIC+}
+{$endif darwin}
+
+{$ifdef CPUX86_64}
+{$ifndef WINDOWS}
+{$PIC+}
+{$endif WINDOWS}
+{$endif CPUX86_64}
+unit uw8730a;
+
+interface
+
+function _Lib1Func: pchar;
+
+implementation
+
+function _Lib1Func: pchar;
+begin
+  result := 'result of function Lib1Func';
+end;
+
+var
+  t: text;
+
+initialization
+assign(t,'tw8730a.txt');
+rewrite(t);
+close(t);
+WriteLn( 'Init of Unit1' );
+
+end.
+
+//= END OF FILE ===============================================================

+ 46 - 0
tests/webtbs/uw8730b.pp

@@ -0,0 +1,46 @@
+{$mode delphi}
+
+{$ifdef darwin}
+{$PIC+}
+{$endif darwin}
+
+{$ifdef CPUX86_64}
+{$ifndef WINDOWS}
+{$PIC+}
+{$endif WINDOWS}
+{$endif CPUX86_64}
+unit uw8730b;
+
+interface
+
+function Lib2Func: pchar; CDecl;
+
+implementation
+
+const
+{$ifdef windows}
+  alibname='tw8730a.dll';
+{$else}
+  alibname='tw8730a';
+  {$linklib tw8730a}
+{$endif}
+
+function Lib1Func: pchar; external alibname name '_Lib1Func';
+
+function Lib2Func: pchar;
+begin
+  Writeln( Lib1Func );
+  result := 'result of function Lib2Func';
+end;
+
+var
+  t: text;
+initialization
+assign(t,'tw8730b.txt');
+rewrite(t);
+close(t);
+WriteLn( 'Init of Unit 2' );
+
+end.
+
+//= END OF FILE ===============================================================