Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2001-07

Linking FPC program with FPC made *.so

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sergey Korshunoff

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,@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,@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

Reply by email

Peter Vreman
to Sergey Korshunoff
Show quoted text 15 lines
-+- 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,@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).

Thanks, i'll implement it this way

Peter

Reply by email