[fpc-devel]Linking FPC program with FPC made *.so

Sergey Korshunoff Sergey.Korshunoff at p5.f2666.n5020.z2.fidonet.org
Thu Jul 5 01:40:33 CEST 2001


I found another solution :-)
SK> And to allow FPC made libxxx.so work with FPC made main program
SK> there is a need to patch a prt0.as:
SK>         movl    %eax,U_SYSLINUX_ENVP
SK> +       movl    %eax,_environ
SK> .................
SK> +        .globl  _environ
SK> +        .type   _environ, at object
SK> +        .size   _environ,4
SK> +_environ:
SK> +        .long   0

Insteed of:
SK> And patch for dllprt0.as:
SK> -        call    PASCALMAIN
SK> +        call    LIB_PASCALMAIN

SK> And in ld call we need to add a parm
SK> --defsym LIB_PASCALMAIN=P1_main
SK> for libp1.

SK> Without this changes FPC made main program can not use
SK> FPC made shared library (this is for linux):
SK>    call    PASCALMAIN
SK> from dllprt0.as resolves to FPC made main program symbol and
SK> P1_main do not get control.

we need only to mark PASCALMAIN as hidden:

==================================
program p;

uses
   SysUtils;

procedure pas1;cdecl; external 'libp1.so';

begin
   writeln('Start!');
   pas1();
   writeln('End');
end.
==================================
==================================
library p1;
uses SysUtils;
procedure pas1;cdecl;
begin
   writeln('Hello world!');
   Writeln('Home: ',GetEnvironmentVariable('HOME'));
end;
exports pas1;
begin
   writeln('Lib started!');
   writeln('ParamCount = ', ParamCount);
   // writeln('ParamStr(0) = ', ParamStr(0));
end.
==================================

-+- p1.s.bak    Wed Jul  4 16:02:59 2001
+++ p1.s        Wed Jul  4 16:04:09 2001
@@ -72,6 +72,7 @@
        .size   pas1, .Le0 - pas1
        .balign 16
 .globl PASCALMAIN
+.hidden PASCALMAIN
        .type   PASCALMAIN, at function
 PASCALMAIN:
 .globl P1_main

This is more correct solution for Linux (2 shared library can now have
PASCALMAIN as entry without name conflict). But I do not know
how this AS keyword is supported under other OS (OS2, WIN32).

Regards,
    Sergey Korshunoff





More information about the fpc-devel mailing list