https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63758
Bug ID: 63758 Summary: liblto_plugin.so has undefined reference to _environ on OSX Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: roland at gnu dot org Host: x86_64-apple-darwin Build: x86_64-apple-darwin11.4.2 Failure mode: .../bin/../lib/gcc/.../4.9.2/../../../../.../bin/ld: .../bin/../libexec/gcc/.../4.9.2/liblto_plugin.so: error loading plugin: dlopen(.../bin/../libexec/gcc/.../4.9.2/liblto_plugin.so, 2): Symbol not found: _environ Referenced from: .../bin/../libexec/gcc/.../4.9.2/liblto_plugin.so Expected in: flat namespace in .../bin/../libexec/gcc/.../4.9.2/liblto_plugin.so collect2:error: ld returned 1 exit status The references come from libiberty code (xmalloc.c and pex-unix.c). Using environ in a main program is fine, but it's documented on OSX that you cannot use it from a shared library. Instead, you must call the _NSGetEnviron function to return its address (which also works just as well in a main program). I have a working fix which I'll attach shortly.