My adventures with `shl_load` on HP-UX 10.20. I'm trying to get [[BashLoadableBuiltins|bash's loadable functions]] to work on HP-UX 10.20. But HP-UX 10.20 doesn't have `dlopen` and friends, so I'm trying to get the `shl_load` family to work. They look superficially similar in nature. I even managed to hack through all the autoconf stuff, etc. and got it working... sort of. I can load the `true` and `false` builtins and observe a change in the `help true` output. But if I attempt to load any of the more complicated builtins -- the ones that actually ''do'' things -- I get unresolved symbols. It seems an `shl_load`ed library can't resolve symbols that are already part of the running program. Here is a simple program that loads a "library", in which a function calls something that's already part of the program. This is analogous to what bash is doing with its loadable builtin examples, most of which call internal bash functions. {{{#!cplusplus /* foo.c */ #include #include int localfunc(void); main() { shl_t handle; int (*rf)(void); handle = shl_load ("bar.so", BIND_IMMEDIATE | BIND_VERBOSE, 0L); if (handle == NULL) { perror ("shl_load bar.so failed"); return 1; } printf ("I am foo\n"); if (shl_findsym (&handle, "remotefunc", TYPE_UNDEFINED, (void *) &rf)) { perror ("shl_findsym remotefunc failed"); return 1; } } int localfunc(void) { printf ("I am localfunc\n"); return 0; } }}} And here's the "library" it loads: {{{#!cplusplus /* bar.c */ #include extern int localfunc(void); int remotefunc(void) { printf ("I am remotefunc\n"); localfunc(); } }}} And here's how I build and run it: {{{#!nl imadev:~/tmp$ gcc -c foo.c imadev:~/tmp$ gcc -c -fpic bar.c imadev:~/tmp$ ld -b -o bar.so bar.o imadev:~/tmp$ gcc -o foo foo.o -ldld imadev:~/tmp$ ./foo /usr/lib/dld.sl: Unresolved symbol: localfunc (code) from bar.so shl_load bar.so failed: Unresolved external }}} And this is bash doing the same thing: {{{#!nl imadev:/var/tmp/bash-4.0-shl$ enable -f examples/loadables/whoami.so whoami /usr/lib/dld.sl: Unresolved symbol: loptend (data) from examples/loadables/whoami.so /usr/lib/dld.sl: Unresolved symbol: current_user (data) from examples/loadables/whoami.so /usr/lib/dld.sl: Unresolved symbol: builtin_usage (code) from examples/loadables/whoami.so /usr/lib/dld.sl: Unresolved symbol: reset_internal_getopt (code) from examples/loadables/whoami.so /usr/lib/dld.sl: Unresolved symbol: internal_getopt (code) from examples/loadables/whoami.so /usr/lib/dld.sl: Unresolved symbol: get_current_user_info (code) from examples/loadables/whoami.so bash: enable: cannot open shared object examples/loadables/whoami.so: Unresolved external }}} I set up an analogous program using `dlopen` on a Linux box, and that worked (although I had to screw with `LD_LIBRARY_PATH` to make the load work). I'll omit it for the time being. TheBonsai tracked down some documentation that explains that you have to supply a linker argument of `-E` on HP-UX to make the main program export local symbols to the dynamically loaded libraries... so let's try that. {{{#!nl imadev:~/tmp$ gcc -Wl,-E -o foo foo.o -ldld imadev:~/tmp$ ./foo I am foo I am remotefunc I am localfunc }}} ... huh, OK. Now I guess I get to figure out how to put that into the bash build process. Maybe by manually setting LDFLAGS during `./configure` I suppose.