0
votes

I'm creating a an apache module which is basically a shared library (not in C, but in rust, so I can't use the usual apache tooling that hides all this stuff).

When I go to link, ld is telling me there's a bunch of undefined symbols. These symbols are all defined in the executable that will be loading this shared library, namely /usr/sbin/httpd. I verified this with nm. I can't find them in any other static or shared libs.

How do I tell the linker the symbols are in httpd ?

here is an abbreviated linker command it is firing off:

"cc" "-m64" "-L" "/Users/me/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/me/dev/apacheagent-myco/target/debug/deps/apacheagentmyco.apacheagentmyco0.rcgu.o" ...<tons of .o files>  "-Wl,-exported_symbols_list,/var/folders/6h/qx6jssj16q95_h_kqjd6qt_00000gn/T/rustc.xMMi8AxcVg62/list"  "-Wl,-dead_strip" "-nodefaultlibs" "-L" <tons of rlibs>  "-l" "onig" "-framework" "Security" "-framework" "CoreFoundation" "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m" "-dynamiclib" "-Wl,-dylib" "-lapr-1" "-laprutil-1"

here are the errors:

note: Undefined symbols for architecture x86_64:
            "_ap_is_initial_req", referenced from:
                apache2::httpd::_$LT$impl$u20$apache2..wrapper..Wrapper$LT$apache2..ffi..request_rec$GT$$GT$::is_initial_req::h078b0dbdc2d2d488 in libapache2-850bd4b18832aac1.rlib(apache2-850bd4b18832aac1.apache20.rcgu.o)
            "_ap_hook_handler", referenced from:
                apacheagentmyco::apache_agent_myco_hooks::h3461197a43567639 in apacheagentmyco.apacheagentmyco7.rcgu.o
            "_ap_server_root", referenced from:
                apacheagentmyco::myco_child_init::h52c8c1513f7742ef in apacheagentmyco.apacheagentmyco7.rcgu.o
            "_ap_get_brigade", referenced from:
                apacheagentmyco::myco_apache2::apache2_body::read_body::h41bdc64c0c81a6d6 in apacheagentmyco.apacheagentmyco15.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

These symbols are all in /usr/sbin/httpd.

2
So from a shared lib, you are using symbols in the executable that calls the same shared lib? Not knowing rust, I still wonder what the linking command is. It may be an ordering of objects given to ld.AlbusMPiroglu
This is platform and toolchain specific. As a first guess, however, make sure you are compiling your module as a shared library, not an executable. On many -- but not all -- platforms, shared libraries are permitted to have undefined symbols.John Bollinger
@JohnBollinger mac doesn't allow it, but after reading your comment, I looked around and found a flag to ignore specific symbols rather than globally allowing undefined symbols: -Wl,-U,_symbol. That solved it.marathon

2 Answers

1
votes

How do I tell the linker the symbols are in httpd ?

You shouldn't need to: UNIX linkers by default assume that a shared library will have unresolved symbols.

Your problem appears to be: missing -shared flag on the link line (without it, the linker is trying to link an executable, and not a shared library that you want to link).

P.S. Using -nodefaultlibs is ill-advised. You should never use it unless you know what you are doing.

1
votes

Just for future reference in case anyone else has the same problem, I solved this by telling the linker to ignore the specific symbols.

... -Wl,-U,_ap_is_initial_req -Wl,-U,_ap_hook_handler -Wl,-U,_ap_server_root