[fpc-devel]Library linking with C explanation
Sergey.Korshunoff at p5.f2666.n5020.z2.fidonet.org
Wed Jul 4 00:14:21 CEST 2001
SK> Are You shure, that INIT function for *.so can get this args?
SK> I look sources from ld-linux.so. As I understand, this args are
SK> send to global constructors and not to *.so INIT function.
SK> I examine DCC behavior.
SK> There is no ParamCount and ParamStr avaible for library functions
SK> ( ParamCount result in DCC compiled example is 0).
SK> And GetEnvironmentVariable() in DCC use function from libc
SK> There is error in FPC 1.0.5 ParamCount:
SK> it result is -1 when argc is 0
I discover how to init U_SYSLINUX_ENVP in dllprt0.as.
xorl %eax, %eax
movl _environ, %eax # defined in ld-linux.so.2
writeln('ParamCount = ', ParamCount); (* RTL error !!!: must be 0 *)
(* writeln('ParamStr(0) = ', ParamStr(0)); *)
(* RTL error !!!: ParamStr is trapped for argc = 0 *)
Output of FPC made test program:
ParamCount = -1
Output of KYLIX made test program:
ParamCount = 0
And to allow FPC made libxxx.so work with FPC made main program
there is a need a patch for prt0.as:
movl %eax,U_SYSLINUX_ENVP /* Move the environment pointer */
+ movl %eax,_environ
+ .globl _environ
+ .type _environ, at object
+ .size _environ,4
+ .long 0
And patch for dllprt0.as:
- call PASCALMAIN
+ call LIB_PASCALMAIN
And in ld call we need to add a parm
Without this changes FPC made main program can not use
FPC made shared library (this is for linux):
from dllprt0.as resolves to FPC made main program symbol and
P1_main do not get control.
More information about the fpc-devel