21.11.2013 0:45, Michal Wallace пишет:
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 
<http://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?


Studying sources of FreeBSD dynamic loader reveals that, although it does not pass argc, argv and envp to the initialization function in .init section, it *does* pass them to procedures pointed to from .init_array section. Generally, .init_array is considered as a replacement for .init. Therefore, the correct solution would be to change initialization to use .init_array and remove all associated hacks.

Regards,
Sergei
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to