FirebirdSQL / firebird

Firebird server, client and tools
https://www.firebirdsql.org/
1.26k stars 216 forks source link

can not load UDF compiled by FreePascal [CORE2188] #997

Closed firebird-automations closed 15 years ago

firebird-automations commented 15 years ago

Submitted by: Eugenk Konkov (kes)

library tkes2;

{$mode objfpc} {$PACKRECORDS C}

function somefn: integer; cdecl; export; begin somefn:= 3; end;

exports //I do not do as: // somefn name 'somefn'; // because of this cause error tkes2(17,1) Error: Asm: Duplicate label somefn

//so I do as: somefn name '_somefn';

end.

⁠fpc tkes2 -Xp

Free Pascal Compiler version 2.2.0 [2008/11/09] for i386 Copyright (c) 1993-2007 by Florian Klaempfl Target OS: FreeBSD/ELF for i386 Compiling tkes2 Linking http://libtkes2.so 17 lines compiled, 0.1 sec

⁠ld -shared -soname libtkes2.so.1 -o libtkes2.so.1.0 -lc tkes2.o

⁠cp http://tkes2.so /usr/local/libexec/firebird/udf/

⁠cp tkes2.so.1.0 /usr/local/libexec/firebird/udf/

⁠cd /usr/local/libexec/firebird/udf/

⁠ls -l

-rwxr-xr-x 1 root wheel 6022 12 ноя 04:07 http://libtkes2.so -rwxr-xr-x 1 root wheel 3219 12 ноя 04:32 libtkes2.so.1.0

⁠ /etc/rc.d/inetd restart

Stopping inetd. Starting inetd.

in SQL: DECLARE EXTERNAL FUNCTION FNTEST2 RETURNS INTEGER BY VALUE ENTRY_POINT 'tkes2__somefn' MODULE_NAME 'libtkes2'

select fntest2() from sometable;

invalid requiest BLR at offset 64 function FNTEST2 is not defined module name or entrypoint could not be found

repeat: DECLARE EXTERNAL FUNCTION FNTEST2 RETURNS INTEGER BY VALUE ENTRY_POINT 'tkes2_somefn' MODULE_NAME 'libtkes2'

select fntest2() from sometable;

invalid requiest BLR at offset 64 function FNTEST2 is not defined module name or entrypoint could not be found

another try:

DECLARE EXTERNAL FUNCTION FNTEST2 RETURNS INTEGER BY VALUE ENTRY_POINT '_somefn' MODULE_NAME 'libtkes2'

select fntest2() from sometable;

invalid requiest BLR at offset 64 function FNTEST2 is not defined module name or entrypoint could not be found

DECLARE EXTERNAL FUNCTION FNTEST2 RETURNS INTEGER BY VALUE ENTRY_POINT 'somefn' MODULE_NAME 'libtkes2'

select fntest2() from sometable;

invalid requiest BLR at offset 64 function FNTEST2 is not defined module name or entrypoint could not be found

I have tryed in C:

extern int fntest();

int fntest()

return 8;

this work, but fpc does not ((( I need fpc because of I have many functions in delphi on Win32 platform that I need to port to FreeBSD

C file: http://testudf.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (FreeBSD), dyna 00001630 A _DYNAMIC 00001704 A _GLOBAL_OFFSET_TABLE_ w _Jv_RegisterClasses 000016f4 d __CTOR_END__ 000016f0 d __CTOR_LIST__ 000016fc d __DTOR_END__ 000016f8 d __DTOR_LIST__ 0000162c r __FRAME_END__ 00001700 d __JCR_END__ 00001700 d __JCR_LIST__ 0000171c A __bss_start w __cxa_finalize@@FBSD_1.0 00000550 t __do_global_ctors_aux 000004a0 t __do_global_dtors_aux 00001624 d __dso_handle 00000537 t __i686.get_pc_thunk.bx 0000171c A _edata 00001720 A _end 00000584 T _fini 0000046c T _init 0000171c b completed.4685 00000540 T fntest 00000500 t frame_dummy 00001628 d p.4683

FreePascal: http://tkes2.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (FreeBSD), dynamically linked, not stripped U FINALIZE$_OBJPAS U FPC_INITIALIZEUNITS 0000158c D FPC_RESOURCESTRINGTABLES 0000157c D FPC_THREADVARTABLES U INIT$_OBJPAS U INIT$_SYSTEM 00001564 D INITFINAL 00000530 T P$TKES2_SOMEFN$$LONGINT 00000544 T P$TKES2_main 00000544 T PASCALMAIN U THREADVARLIST_OBJPAS 00001560 D THREADVARLIST_P$TKES2 U THREADVARLIST_SYSTEM 000015cc A _DYNAMIC 00001654 A _GLOBAL_OFFSET_TABLE_ 00001660 A __bss_start 00001598 D __fpc_valgrind 00001594 D __heapsize 00001590 D __stklen 00001660 A _edata 00001660 A _end 00000550 T _somefn 00000530 T somefn

C file:

⁠ Compiler executable checksum: 420481ffe9facb411cc92bbca2cb4405

    \.text
    \.p2align 4,,15

.globl fntest .type fntest, @function fntest: pushl %ebp #⁠ movl %esp, %ebp #⁠, movl $8, %eax #⁠, D.1541 popl %ebp #⁠ ret .size fntest, .-fntest .ident "GCC: (GNU) 4.2.1 20070719 [FreeBSD]"

FreePascal .file "tkes2"

⁠ Begin asmlist al_begin

⁠ End asmlist al_begin

⁠ Begin asmlist al_stabs

⁠ End asmlist al_stabs

⁠ Begin asmlist al_procedures

.section .text .balign 4,0x90 .globl P$TKES2_SOMEFN$$LONGINT .type P$TKES2_SOMEFN$$LONGINT,@function P$TKES2_SOMEFN$$LONGINT: .globl somefn .type somefn,@function somefn: pushl %ebp movl %esp,%ebp subl $4,%esp movl $3,-4(%ebp) movl -4(%ebp),%eax leave ret .Le0: .size P$TKES2_SOMEFN$$LONGINT, .Le0 - P$TKES2_SOMEFN$$LONGINT

.section .text .balign 4,0x90 .globl PASCALMAIN .type PASCALMAIN,@function PASCALMAIN: .globl P$TKES2_main .type P$TKES2_main,@function P$TKES2_main: pushl %ebp movl %esp,%ebp call FPC_INITIALIZEUNITS leave ret .Le1: .size P$TKES2_main, .Le1 - P$TKES2_main

.section .text .balign 4,0x90 .globl _somefn .type _somefn,@function _somefn: jmp P$TKES2_SOMEFN$$LONGINT .Le2: .size _somefn, .Le2 - _somefn

⁠ End asmlist al_procedures

⁠ Begin asmlist al_globals

.section .data .balign 4 .globl THREADVARLIST_P$TKES2 .type THREADVARLIST_P$TKES2,@object THREADVARLIST_P$TKES2: .long 0 .Le3: .size THREADVARLIST_P$TKES2, .Le3 - THREADVARLIST_P$TKES2

.section .data .balign 4 .globl INITFINAL .type INITFINAL,@object INITFINAL: .long 2,0 .long INIT$_SYSTEM .long 0 .long INIT$_OBJPAS .long FINALIZE$_OBJPAS .Le4: .size INITFINAL, .Le4 - INITFINAL

.section .data .balign 4 .globl FPC_THREADVARTABLES .type FPC_THREADVARTABLES,@object FPC_THREADVARTABLES: .long 3 .long THREADVARLIST_SYSTEM .long THREADVARLIST_OBJPAS .long THREADVARLIST_P$TKES2 .Le5: .size FPC_THREADVARTABLES, .Le5 - FPC_THREADVARTABLES .section .data .balign 4 .globl FPC_RESOURCESTRINGTABLES .type FPC_RESOURCESTRINGTABLES,@object FPC_RESOURCESTRINGTABLES: .long 0 .Le6: .size FPC_RESOURCESTRINGTABLES, .Le6 - FPC_RESOURCESTRINGTABLES

.section .fpc .balign 4 .ascii "FPC 2.2.0 [2008/11/09] for i386 - FreeBSD"

.section .data .balign 4 .globl __stklen .type __stklen,@object __stklen: .long 262144

.section .data .balign 4 .globl __heapsize .type __heapsize,@object __heapsize: .long 0

.section .data .globl __fpc_valgrind .type __fpc_valgrind,@object __fpc_valgrind: .byte 0

⁠ End asmlist al_globals

⁠ Begin asmlist al_const

⁠ End asmlist al_const

⁠ Begin asmlist al_typedconsts

⁠ End asmlist al_typedconsts

⁠ Begin asmlist al_rotypedconsts

⁠ End asmlist al_rotypedconsts

⁠ Begin asmlist al_threadvars

⁠ End asmlist al_threadvars

⁠ Begin asmlist al_imports

⁠ End asmlist al_imports

⁠ Begin asmlist al_exports

⁠ End asmlist al_exports

⁠ Begin asmlist al_resources

⁠ End asmlist al_resources

⁠ Begin asmlist al_rtti

⁠ End asmlist al_rtti

⁠ Begin asmlist al_dwarf

⁠ End asmlist al_dwarf

⁠ Begin asmlist al_dwarf_info

⁠ End asmlist al_dwarf_info

⁠ Begin asmlist al_dwarf_abbrev

⁠ End asmlist al_dwarf_abbrev

⁠ Begin asmlist al_dwarf_line

⁠ End asmlist al_dwarf_line

⁠ Begin asmlist al_picdata

⁠ End asmlist al_picdata

⁠ Begin asmlist al_resourcestrings

⁠ End asmlist al_resourcestrings

⁠ Begin asmlist al_end

⁠ End asmlist al_end

firebird-automations commented 15 years ago

Commented by: Eugenk Konkov (kes)

From FPC (FreePascal) mailing list: > On Thu, Dec 11, 2008 at 1:46 PM, Jonas Maebe <mailto:jonas.maebe@elis.ugent.be > > wrote: >> >>> How to build .so with FPC and use it in C program on FreeBSD
>>> platform? >> >> FPC cannot build dynamic libraries on FreeBSD at this time (well,
>> at least >> none that work properly with C programs).

> Can this be done for other platforms? eg: Linux 32/64bit and Windows > 32/64bit etc... > I'm mostly interested in 32bit Linux & Windows OS's.

Only the FreeBSD port is broken in that respect as far as I know.

You must close ticked because of this is FPC issue not FireBird

firebird-automations commented 15 years ago
Modified by: @dyemanov status: Open \[ 1 \] =\> Resolved \[ 5 \] resolution: Won't Fix \[ 2 \]
firebird-automations commented 15 years ago
Modified by: @pcisar status: Resolved \[ 5 \] =\> Closed \[ 6 \]