[fpc-devel] (hack) calling fpc libraries from other languages on freebsd/amd64

Michal Wallace michal.wallace at gmail.com
Wed Nov 20 21:45:26 CET 2013


Hey all.

I had a problem and I fixed it in the compiler, but I'm not sure
what the ramifications of my fix are for other people.

My goal was to expose some pascal code to python, as per:

http://wiki.freepascal.org/Developing_Python_Modules_with_Pascal

This works fine for me on windows but failed on freebsd/amd64.

When I would try to load my shared library as a python module, it would
fail, saying: "Undefined Symbol: operatingsystem_parameter_envp"

This issue was reported by someone else but it was (mistakenly?) marked as
a duplicate issue and closed:

http://bugs.freepascal.org/view.php?id=15422

Anyway, the problem appears to be in this file:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/freebsd/x86_64/dllprt0.as?revision=25737&view=markup

It has the comment:

# FreeBSD RunTime dynamic loader only
# calls the functions specified by -init
# as functions without parameters
# Thus, it is not possible to retrieve argc, argv and envp
# On x86_64 CPU, using weak for the operatingsystem_parameter_XXX

# allows to bind to main program parameters,
# but this does not seem to work for i386 loader.

Then at the bottom:

/* Do not fail linkage if argc, argv and envp are not found. */
.weak operatingsystem_parameter_argc
.weak operatingsystem_parameter_argv
.weak operatingsystem_parameter_envp

My change was to comment these lines out and copy the lines from prt0.as :


.global operatingsystem_parameter_envp
.global operatingsystem_parameter_argc
.global operatingsystem_parameter_argv
.set operatingsystem_parameter_envp,operatingsystem_parameters+0
.set operatingsystem_parameter_envp,operatingsystem_parameters+0
.set operatingsystem_parameter_envp,operatingsystem_parameters+0

Then after recompiling fpc, I was able to compile a *.so file usable from
python.

But... It seems like the original .weak version was done quite
deliberately, so I suspect that if I submit a patch, it would break
things for other people. OTOH, I'd like to get a fix for my issue
into trunk.

What should I do?

-Michal
http://tangentstorm.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20131120/3f5afb59/attachment.html>


More information about the fpc-devel mailing list