Sign in Join

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

Mailing lists / fpc-pascal / 2009-05

Firebird +lin32 + fpc lib udf returns garbage.

10 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Coco Pascal

If I build a library with udf functions for Firebird tests with an fpc app calling those routines works fine. However with Firebird module and entrypoint are found but garbage is returned.

function vv(const AValue: LongInt): LongInt; cdecl; export;
begin
  Result := AValue;
end;

declare external function vv
integer
returns integer by value
entry_point 'vv' module_name 'libyfbudf';

select vv(13) from rdb$database;
returns -12350740

All variations of the input parameter return the same result.

What can I do? Has anybody succesfully created a Firebird udf library on lin32?

(The same module build with fpc win32 works fine with Firebird win32.)

Coco Pascal
to Coco Pascal
Coco Pascal wrote 23 lines
If I build a library with udf functions for Firebird tests with an fpc app calling those routines works fine. However with Firebird module and entrypoint are found but garbage is returned. function vv(const AValue: LongInt): LongInt; cdecl; export; begin Result := AValue; end; declare external function vv integer returns integer by value entry_point 'vv' module_name 'libyfbudf'; select vv(13) from rdb$database; returns -12350740 All variations of the input parameter return the same result. What can I do? Has anybody succesfully created a Firebird udf library on lin32? (The same module build with fpc win32 works fine with Firebird win32.)

It looks as if the code isn't Firebird requires
PIC. Is PIC on the shortlist of features for linux i386? Bugtracker doesn't have an entry about this.

Jonas Maebe
to Coco Pascal
Coco Pascal wrote
It looks as if the code isn't Firebird requires PIC.

That is extremely unlikely (I'd say "impossible", but that's dangerous). Whether or not the code in the library is position- independent is something Firebird has no clue about (unless it starts disassembling the library and/or reading the relocation information).

Jonas

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote 10 lines
On 01 Jun 2009, at 11:40, Coco Pascal wrote: > It looks as if the code isn't Firebird > requires PIC. That is extremely unlikely (I'd say "impossible", but that's dangerous). Whether or not the code in the library is position- independent is something Firebird has no clue about (unless it starts disassembling the library and/or reading the relocation information).

Not to mention that it would make no difference for the function you posted, since it does not refer to any other code nor to global data.

Jonas

Coco Pascal
to Jonas Maebe: That is extremely unlikely (I'd say "impossible", but that's dangerous). Whether or not…
Jonas Maebe wrote 12 lines
On 01 Jun 2009, at 11:40, Coco Pascal wrote: > It looks as if the code isn't Firebird > requires PIC. That is extremely unlikely (I'd say "impossible", but that's dangerous). Whether or not the code in the library is position-independent is something Firebird has no clue about (unless it starts disassembling the library and/or reading the relocation information).

Found this thread on the firebird-support list which blames PIC http://tech.groups.yahoo.com/group/firebird-support/message/99600

Coco Pascal
to Jonas Maebe: Not to mention that it would make no difference for the function you posted, since it…
Jonas Maebe wrote 17 lines
On 01 Jun 2009, at 12:30, Jonas Maebe wrote: > On 01 Jun 2009, at 11:40, Coco Pascal wrote: > >> It looks as if the code isn't Firebird >> requires PIC. > > That is extremely unlikely (I'd say "impossible", but that's > dangerous). Whether or not the code in the library is > position-independent is something Firebird has no clue about (unless > it starts disassembling the library and/or reading the relocation > information). Not to mention that it would make no difference for the function you posted, since it does not refer to any other code nor to global data.

This made me start a test again with a clean sheet and guess...

function VV(const AValue: LongInt): LongInt; cdecl; export;
begin
Result := AValue;
end;

works fine now.
But if I add the following function it returns wrong results. This one does refer to other code.

function Y_Odd(const AValue: LongInt): LongInt; cdecl; export;
begin
if Odd(AValue) then
Result := -1
else
Result := 0;
end;
Jonas Maebe
to Coco Pascal
Coco Pascal wrote 10 lines
But if I add the following function it returns wrong results. This one does refer to other code. function Y_Odd(const AValue: LongInt): LongInt; cdecl; export; begin if Odd(AValue) then Result := -1 else Result := 0; end;

It doesn't anymore once it is compiled, because odd() gets inlined.

Jonas

Coco Pascal
to Jonas Maebe
Jonas Maebe wrote 16 lines
On 01 Jun 2009, at 14:39, Coco Pascal wrote: > But if I add the following function it returns wrong results. This > one does refer to other code. > > function Y_Odd(const AValue: LongInt): LongInt; cdecl; export; > begin > if Odd(AValue) then > Result := -1 > else > Result := 0; > end; It doesn't anymore once it is compiled, because odd() gets inlined.

So, what do think? A simple module contains two simple functions. On win32 it works fine. On lin32 one function works as expected, the other returns garbage (0 or null). Is the problem linux, firebird or fpc related?

Jonas Maebe
to Coco Pascal
Coco Pascal wrote
So, what do think? A simple module contains two simple functions. On win32 it works fine. On lin32 one function works as expected, the other returns garbage (0 or null). Is the problem linux, firebird or fpc related?

I really don't know. I have no experience whatsoever with Firebird on any platform.

Jonas

Coco Pascal
to Jonas Maebe
Jonas Maebe wrote 11 lines
On 01 Jun 2009, at 21:06, Coco Pascal wrote: > So, what do think? A simple module contains two simple functions. On > win32 it works fine. On lin32 one function works as expected, the > other returns garbage (0 or null). Is the problem linux, firebird or > fpc related? I really don't know. I have no experience whatsoever with Firebird on any platform.

Bug reported: http://bugs.freepascal.org/view.php?id=13891