From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20409 invoked by alias); 6 Nov 2014 00:14:17 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20378 invoked by uid 48); 6 Nov 2014 00:14:14 -0000 From: "roland at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/63758] New: liblto_plugin.so has undefined reference to _environ on OSX Date: Thu, 06 Nov 2014 00:14:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: roland at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cf_gcchost cf_gccbuild Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-11/txt/msg00325.txt.bz2 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.