Bug 45258 - linkage on -ldl, -lm and -lpthread should be purged from darwin build
Summary: linkage on -ldl, -lm and -lpthread should be purged from darwin build
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-11 16:30 UTC by Jack Howarth
Modified: 2011-01-10 20:27 UTC (History)
6 users (show)

See Also:
Host: *-apple-darwin*
Target: *-apple-darwin*
Build: *-apple-darwin*
Known to work:
Known to fail:
Last reconfirmed:


Attachments
proposed patch to add and use remove-outfile (801 bytes, patch)
2010-08-12 00:54 UTC, Jack Howarth
Details | Diff
final patch to add remove-outfile support for darwin. (1.32 KB, patch)
2010-08-12 03:42 UTC, Jack Howarth
Details | Diff
patch to eliminate remaining -lm and -lpthread usage in libjava build (725 bytes, patch)
2010-08-12 04:00 UTC, Jack Howarth
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jack Howarth 2010-08-11 16:30:48 UTC
Currently libjava is being improperly linked (PR java/41991) due to the presence of -lm and -lpthreads on the shared library linkages. This causes libSystem.dylib to be pushed to the front of the linkage and breaks the logic used by libgcc_ext. We should add and set defines for HAVE_LIBSYSTEM_PTHREADS and HAVE_LIBSYSTEM_LIBMATH to configure and use these for conditionals in the Makefile.am's where appropriate to avoid passing -lm and -lpthread on darwin.
Comment 1 pinskia@gmail.com 2010-08-11 17:03:10 UTC
Subject: Re:   New: linkage on -lm and -lpthread should be purged from darwin build

What about removing those in the driver?  This way it works correctly  
for other makefiles too?

On Aug 11, 2010, at 9:30 AM, "howarth at nitro dot med dot uc dot edu"  
<gcc-bugzilla@gcc.gnu.org> wrote:

> Currently libjava is being improperly linked (PR java/41991) due to  
> the
> presence of -lm and -lpthreads on the shared library linkages. This  
> causes
> libSystem.dylib to be pushed to the front of the linkage and breaks  
> the logic
> used by libgcc_ext. We should add and set defines for  
> HAVE_LIBSYSTEM_PTHREADS
> and HAVE_LIBSYSTEM_LIBMATH to configure and use these for  
> conditionals in the
> Makefile.am's where appropriate to avoid passing -lm and -lpthread  
> on darwin.
>
>
> -- 
>           Summary: linkage on -lm and -lpthread should be purged from
>                    darwin build
>           Product: gcc
>           Version: 4.6.0
>            Status: UNCONFIRMED
>          Severity: normal
>          Priority: P3
>         Component: target
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: howarth at nitro dot med dot uc dot edu
> GCC build triplet: *-apple-darwin*
>  GCC host triplet: *-apple-darwin*
> GCC target triplet: *-apple-darwin*
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45258
>
Comment 2 Jack Howarth 2010-08-12 00:54:42 UTC
Created attachment 21459 [details]
proposed patch to add and use remove-outfile

The proposed patch implements remove-outfile to parse out -lm and -lpthread from LINK_SPEC in darwin.h.
Comment 3 Jack Howarth 2010-08-12 00:57:30 UTC
Note that while the proposed patch properly parses out -lm and -lpthread from linkages done with the compiler, this is insufficient to solve the problems with libjava. The hard coded use of -lm in libjava/Makefile.am has to be fixed as well since this links directly with ld via libtool.
Comment 4 Jack Howarth 2010-08-12 03:41:41 UTC
Opps. Forgot about -ldl.
Comment 5 Jack Howarth 2010-08-12 03:42:39 UTC
Created attachment 21466 [details]
final patch to add remove-outfile support for darwin.
Comment 6 Jack Howarth 2010-08-12 04:00:59 UTC
Created attachment 21467 [details]
patch to eliminate remaining -lm and -lpthread usage in libjava build
Comment 7 Jack Howarth 2010-08-12 04:02:59 UTC
The combination of the remove_outfile.diff and libjava_lm_lpthread_cleanup.diff patches eliminates the incorrect linkage position of libSystem in the libjava shared libraries on darwin. Will regression test next on x86_64-apple-darwin10.
Comment 8 Jack Howarth 2010-08-12 04:12:05 UTC
These patches also appear to clean up the linkages on libstdc++.6.dylib and libgfortran.3.dylib so that now libSystem is properly at the end of the linkage. It will be interesting to see if these patches help eliminate the random failures I have seen with...

FAIL: tr1/2_general_utilities/shared_ptr/thread/default_weaktoshared.cc execution test

in the libstdc++ testsuite.
Comment 9 Jack Howarth 2010-08-12 05:52:16 UTC
The remove_outfile.diff patch has the additional advantage of also eliminating the gcc.dg/torture/builtin-math-7.c failures.
Comment 11 Ralf Wildenhues 2011-01-10 19:05:47 UTC
(In reply to comment #10)
> Posted patches to http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00886.html and
> http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00887.html.

Jack, based on the above, can this be closed now?  Thanks.
Comment 12 Jack Howarth 2011-01-10 19:37:15 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > Posted patches to http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00886.html and
> > http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00887.html.
> 
> Jack, based on the above, can this be closed now?  Thanks.

Ralf,
    Yes. Current gcc trunk always ends up with -lSystem last for the gcc build itself. I had been considering creating a version_compare_remove_outfile spec function to handle all the other symlinks of libSystem but this is impossible to implement. Closing as fixed.
Comment 13 mrs@gcc.gnu.org 2011-01-10 19:41:42 UTC
Author: mrs
Date: Mon Jan 10 19:41:39 2011
New Revision: 168639

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168639
Log:
2010-08-17  Jack Howarth  <howarth@bromo.med.uc.edu>
 
	PR target/45258
 	* gcc.c (spec_function): Add remove-outfile.
 	(remove_outfile_spec_function): New function.
 	* config/darwin.h (LINK_SPEC): Add removal of -ldl, -lm and -lpthread.
	* invoke.texi (replace-outfile): Document.

Modified:
    trunk/gcc/ChangeLog-2010
Comment 14 Iain Sandoe 2011-01-10 20:07:09 UTC
if we could get Java and libquadmath to intercept the new

LINK_GCC_C_SEQUENCE_SPEC

instead of re-writing the *lib sequence

it would give us a little more room to maneuver.

.. as it is when another part of the complier hijacks the *lib sequence it happens too late for the target to intervene -- anything inserted as a '-l*' is untouchable at that stage.  

if we have the option to re-write from the start of LINK_GCC_C_SEQUENCE_SPEC we're in with a chance...

otherwise .. the only solution then is to apply target-specific stuff in the lib/java builds.
Comment 15 Jack Howarth 2011-01-10 20:27:22 UTC
Iain,
   I was referring to the conceptual problems of creating a version-compare-remove-outfile spec function. For any given OS release there is a different set of symlinks for libSystem which are visible to the compiler regardless of the setting of -mmacosx-version-min=. So one would really have to have version-compare-remove-outfile look only at the running OS version to decide properly which symlinks are present to prune.