Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Compiling User Stata Plugins on 64-bit Solaris


From   Brad Cable <[email protected]>
To   [email protected]
Subject   Re: st: Compiling User Stata Plugins on 64-bit Solaris
Date   Fri, 18 Apr 2014 12:11:08 -0500

What I ended up doing was creating an ADO file that wraps the plugin I ended up writing, and passing the arguments through to the plugin. Here's an example of what I did using the showargs.c file, showargs.ado:

program showargs
    gettoken arguments : 0, parse(":") quotes
    plugin call _showargs, `arguments'
end
program _showargs, plugin


To compile the showargs.c:

$ cc -shared -DSYSTEM=OPUNIX -m64 -KPIC stplugin.c showargs.c -o _showargs.plugin
or
$ gcc -shared -DSYSTEM=OPUNIX -m64 -fPIC stplugin.c showargs.c -o _showargs.plugin


Then using it:
$ echo "showargs arg1 arg2 arg3" | stata-mp -q
. showargs arg1 arg2 arg3
arg1
arg2
arg3


This actually proved useful, as the plugin I wrote needed to use some Stata calls before executing that I was able to insert into my ADO file wrapper. Perhaps that's why they did it.

The documentation says that it's okay to have the plugin name be the same as the ADO program name, however I experienced some issues where it kept attempting to cause infinite loops, so I added an underscore to the plugin file.

Hope this helps anyone in the future trying to accomplish similar things.

-Brad


On 04/15/2014 01:05 PM, Thomas, Anthony wrote:
Not sure, that's been a bit of a mystery to me as well. I suspect that
the plugin call prefix is a wrapper that handles passing arguments to
the compiled code (like the .C function in R). Without this step, your
compiled code cannot receive arguments from Stata and terminates with
an error - which Stata interprets as a "system error." The program
exists in Stata because the command "program something, plugin"
created a program handle. But that's just speculation.

On Tue, Apr 15, 2014 at 1:51 PM, Brad Cable <[email protected]> wrote:
Wow that was simple.  So why exactly does it create the command of the same
name when importing the plugin?

. hello
unrecognized command:  hello
r(199);
. program hello, plugin
. hello
r(9998);
. plugin call hello
Hello World


Thanks for your help!
-Brad


On 04/15/2014 12:28 PM, Thomas, Anthony wrote:
Hi Brad,

Got a bounce notification on previous message - so not sure if message
went through. Anyways, when you execute a plugin, try using the syntax
"plugin call myplugin <args to plugin>" that should fix your problem.

Anthony

On Tue, Apr 15, 2014 at 1:07 PM, Thomas, Anthony
<[email protected]> wrote:
Hi Brad,

I'm no expert with compilers, but to start, when you call your plugin,
you
want to use the syntax "plugin call hello <args to hello>" - see
"http://www.stata.com/plugins/#sect7.";

Anthony


On Tue, Apr 15, 2014 at 12:42 PM, Brad Cable <[email protected]> wrote:
I'm attempting to write a Stata 12 plugin for 64-bit Solaris 10 in a
non-global zone.  I have downloaded the 2 files "stplugin.h" and
"stplugin.c" from:

http://www.stata.com/plugins/

I created a "hello.c" file which contains the example test code under
section 5 on that page, but I can't seem to figure out how to compile it
correctly.

First, without -m64 it doesn't compile to the right ELF class. Second,
without -fPIC I get an error when linking the code, and with -fPIC it
compiles correctly but I get a "r(9998);" return code from Stata when
trying
to execute it.  The only thing I've found on the "r(9998);" error is
this:

http://www.stata.com/statalist/archive/2004-01/msg00650.html

Which is a bit more information, but not quite correct for my purposes
since I'm not using that compiler, processor, or operating system.

I've tried using Sun's compiler as well with the same results. Here's
some
of the output of the compiler commands I've tried:

$ gcc -shared -DSYSTEM=OPUNIX -m64 stplugin.c hello.c -o hello.plugin
Text relocation remains                         referenced
      against symbol                  offset      in file
.text (section)                     0x20        /var/tmp//ccAjvMcv.o
.text (section)                     0x20        /var/tmp//ccC7rr8G.o
_stata_                             0xf         /var/tmp//ccAjvMcv.o
_stata_                             0x12        /var/tmp//ccC7rr8G.o
.rodata (section)                   0x1a        /var/tmp//ccC7rr8G.o
ld: fatal: relocations remain against allocatable but non-writable
sections
collect2: ld returned 1 exit status


$ gcc -shared -DSYSTEM=OPUNIX -m64 -fPIC stplugin.c hello.c -o
hello.plugin
$ stata-mp -q
. program hello, plugin
. hello
r(9998);


$ cc -shared -DSYSTEM=OPUNIX -m64 stplugin.c hello.c -o hello.plugin
$ stata-mp -q
. program hello, plugin
ld.so.1: stata-mp: fatal: relocation error: R_AMD64_32: file
./hello.plugin: sy
mbol _stata_: value 0xfffffb7ffedf0000 does not fit
Could not load plugin: ./hello.plugin
r(9999);


$ cc -shared -DSYSTEM=OPUNIX -m64 -KPIC stplugin.c hello.c -o
hello.plugin
$ stata-mp -q
. program hello, plugin
. hello
r(9998);


The processors are four 8-core Intel Xeon X7560 2.27GHz CPUs.  Stata is
registered for 32 cores.

Some version info, though both compilers seem to be triggering the
"r(9998);" error so I'm not sure if this matters or not:

$ gcc --version
gcc (GCC) 3.4.3 (csl-sol210-3_4-branch+sol_rpath)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


$ cc -V
cc: Sun C 5.11 SunOS_i386 2010/08/13
usage: cc [ options ] files.  Use 'cc -flags' for details


Any help is appreciated, thanks!
-Brad
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index