[fpc-pascal] Mangle name in fpc-FreeBSD ?
Marc Santhoff
M.Santhoff at web.de
Sun Mar 20 16:13:29 CET 2016
On So, 2016-03-20 at 15:10 +0100, Marc Santhoff wrote:
> On So, 2016-03-20 at 14:27 +0100, Ewald wrote:
>
> > Could this be related to pointer trucation? The man page of dlopen tells
> > us that the return value is a pointer (hence the return value of
> > LoadLibrary has the same width). In your example you used an integer. Is
> > sizeof(Integer) = sizeof(Pointer) of your system?
> >
> > If for example, you are missing the upper four bytes of the pointer, the
> > above message makes sense.
>
> Good point:
>
> marc at puma:/home/marc/program/Test_fpc/LoadLibrary > uname -mrs
> FreeBSD 9.1-STABLE amd64
>
> marc at puma:/home/marc/program/Test_fpc/LoadLibrary > ./pointersize
> pointersize: 8
> size of integer: 2
>
> marc at puma:/home/marc/program/Test_fpc/LoadLibrary > cat pointersize.pas
> program pointersize;
> uses
> sysutils;
> begin
> writeln('pointersize: ' + inttostr(sizeof(pointer)));
> writeln('size of integer: ' + inttostr(sizeof(integer)));
> end.
Doing it right it seems to work, I've tried three libs with one of them
definitely not part of the OS but from a port:
program loadlibrary;
{$mode objfpc}{$H+}
uses
sysutils, dynlibs;
var
//libname: string = '/usr/lib/libalias.so';
//fncname: string = 'AddLink';
//libname: string = '/usr/lib/libipsec.so';
//fncname: string = 'ipsec_dump_policy';
libname: string = '/usr/local/lib/vlc/plugins/codec/libx264_plugin.so';
fncname: string = 'vlc_entry__1_1_0g';
libhandle: TLibHandle;
pfnc: pointer;
begin
libhandle := dynlibs.LoadLibrary(pchar(libname));
if (libhandle = 0) then begin
writeln('loading error: ' + GetLoadErrorStr);
halt(1);
end else
writeln('library ' + libname + ' loaded.');
pfnc := GetProcedureAddress(libhandle, pchar(fncname));
if (pfnc = NIL) then
writeln('got proc address error: ' + GetLoadErrorStr)
else begin
writeln('function ' + fncname + ' loaded.');
writeln(inttostr(qword(pfnc)));
end;
UnloadLibrary(libhandle);
end.
I did not call any of those functions, but their nakmes are found and
loaded by dlsym. For all three libraries the program worked fine.
For Fred:
You can check the names inside a dynamic liobrary using system tools:
nm -D /usr/lib/libipsec.so
nm -D /usr/local/lib/vlc/plugins/codec/libx264_plugin.so
The letters after the address tell the type of symbol, see
$ man nm
for an in detail explanation. Mostly those having a T are really inside
the library, U means unresolved and so linked fgrom another lib.
--
Marc Santhoff <M.Santhoff at web.de>
More information about the fpc-pascal
mailing list