Sign in Join

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

Mailing lists / fpc-devel / 2001-06

Library linking with C explanation

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
Show quoted text 17 lines
> >> Reply-To: > >> Date: Sun, 3 Jun 2001 15:12:42 +0200 (CEST) > >> From: Peter Vreman > >> X-Sender: > >> To: > >> Subject: Library linking with C working ! > >> > >> > >> It was more easy than i first thought. No need for .ctor and > >> .dtor stuff. Just pass "-init <Symbolname>" to the linker and the > >> symbol to run at load of the library is set. The same for -fini. > >> > >> The 1.0.5 compiler works correctly. > > Congratulation! > We speak about last variant of 1.0.5 -- that is right? > FPC 1.0.5 from 14 march 2001 do not works correctly.

As I see from compiler source LOG, changes are made at 6 june 2001. And "-init SYMBOL" key is quite new for ld. My old ld do not have it. It upgraded to GNU ld 2.10.90 (Copyright 2000 Free Software Foundation). I use glibc v2.1.1. Result:
In my configuration 1.0.5 _do not_ work correctly. There is problem with argc, argv, envp.

Are You shure, that INIT function for *.so can get this args? I look sources from ld-linux.so. As I understand, this args are send to global constructors and not to *.so INIT function.

I examine DCC behavior.
There is no ParamCount and ParamStr avaible for library functions ( ParamCount result in DCC compiled example is 0). And GetEnvironmentVariable() in DCC use function from libc

There is error in FPC 1.0.5 ParamCount:
it result is -1 when argc is 0

My patches:
=========================================
diff -urN 1.0.5-010619/rtl/linux/i386/dllprt0.as rtl/linux/i386/dllprt0.as -+- 1.0.5-010619/rtl/linux/i386/dllprt0.as Wed Jun 13 03:39:42 2001 +++ rtl/linux/i386/dllprt0.as Tue Jun 19 18:27:48 2001 @@ -26,12 +26,16 @@
pushl %ebp
movl %esp,%ebp

- movl 8(%ebp),%eax
- movl 12(%ebp),%ecx
- movl 16(%ebp),%edx
-
+# movl 8(%ebp),%eax
+ movl $0,%eax
movl %eax,U_SYSLINUX_ARGC /* Move the argument counter */ +
+# movl 12(%ebp),%ecx
+ movl $0,%ecx
movl %ecx,U_SYSLINUX_ARGV /* Move the argument pointer */ +
+# movl 16(%ebp),%edx
+ movl $0,%edx
movl %edx,U_SYSLINUX_ENVP /* Move the environment pointer */

movb $1,U_SYSLINUX_ISLIBRARY
diff -urN 1.0.5-010619/rtl/objpas/syspch.inc rtl/objpas/syspch.inc -+- 1.0.5-010619/rtl/objpas/syspch.inc Wed Jan 31 05:15:26 2001 +++ rtl/objpas/syspch.inc Tue Jun 19 19:17:21 2001 @@ -37,8 +37,11 @@

 function StrPas(Str: PChar): string;
 begin
-  SetLength(result, StrLen(Str));
-  Move(Str^, result[1], Length(result));
+  if Str = nil then StrPas:=''
+  else begin
+    SetLength(result, StrLen(Str));
+    Move(Str^, result[1], Length(result));
+  end;
 end ;

{ StrAlloc allocates a buffer of Size + 4
diff -urN 1.0.5-010619/rtl/unix/sysunix.inc rtl/unix/sysunix.inc -+- 1.0.5-010619/rtl/unix/sysunix.inc Wed Jun 13 03:40:26 2001 +++ rtl/unix/sysunix.inc Wed Jun 20 03:01:48 2001 @@ -55,7 +55,9 @@

 Function ParamCount: Longint;
 Begin
-  Paramcount:=argc-1
+  if argc = 0 then
+    Paramcount:=argc else
+    Paramcount:=argc-1;
 End;

=========================================

Regards,
Sergey Korshunoff

Reply by email

Michael Van Canneyt
to Sergey Korshunoff
Sergey Korshunoff wrote 33 lines
>> >> Reply-To: >> >> Date: Sun, 3 Jun 2001 15:12:42 +0200 (CEST) >> >> From: Peter Vreman >> >> X-Sender: >> >> To: >> >> Subject: Library linking with C working ! >> >> >> >> >> >> It was more easy than i first thought. No need for .ctor and >> >> .dtor stuff. Just pass "-init <Symbolname>" to the linker and the >> >> symbol to run at load of the library is set. The same for -fini. >> >> >> >> The 1.0.5 compiler works correctly. >> >> Congratulation! >> We speak about last variant of 1.0.5 -- that is right? >> FPC 1.0.5 from 14 march 2001 do not works correctly. As I see from compiler source LOG, changes are made at 6 june 2001. And "-init SYMBOL" key is quite new for ld. My old ld do not have it. It upgraded to GNU ld 2.10.90 (Copyright 2000 Free Software Foundation). I use glibc v2.1.1. Result: In my configuration 1.0.5 _do not_ work correctly. There is problem with argc, argv, envp. Are You shure, that INIT function for *.so can get this args? I look sources from ld-linux.so. As I understand, this args are send to global constructors and not to *.so INIT function. I examine DCC behavior. There is no ParamCount and ParamStr avaible for library functions ( ParamCount result in DCC compiled example is 0). And GetEnvironmentVariable() in DCC use function from libc

The support for libraries in Linux is quite new, and hasn't been tested extensively yet, this still needs to be done.

We'll see what we can do to solve these problems.

Michael.

Reply by email