From c92d2ae78cb82baaa40e7b25ecf1e7c24a8d373b Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 1 Apr 2004 16:55:23 +0000 Subject: [PATCH] gcc.c (init_gcc_specs): If HAVE_LD_AS_NEEDED, link with -lgcc --as-needed -lgcc_s --no-as-needed by default. * gcc.c (init_gcc_specs): If HAVE_LD_AS_NEEDED, link with -lgcc --as-needed -lgcc_s --no-as-needed by default. * configure.in (HAVE_LD_AS_NEEDED): Check for ld --as-needed. * configure: Rebuilt. * config.in: Rebuilt. * Makefile.in (stage1-start): Copy also libgcc_s*$(SHLIB_EXT). (stage2-start, stage3-start, stage4-start): Likewise. (stageprofile-start, stagefeedback-start): Likewise. Co-Authored-By: Jakub Jelinek From-SVN: r80304 --- gcc/ChangeLog | 12 ++++++++++++ gcc/Makefile.in | 12 ++++++++---- gcc/config.in | 3 +++ gcc/configure | 21 +++++++++++++++++++++ gcc/configure.in | 18 ++++++++++++++++++ gcc/gcc.c | 7 +++++++ 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 08cb57f20adf..70da46697eed 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2004-04-01 Alan Modra + Jakub Jelinek + + * gcc.c (init_gcc_specs): If HAVE_LD_AS_NEEDED, link with + -lgcc --as-needed -lgcc_s --no-as-needed by default. + * configure.in (HAVE_LD_AS_NEEDED): Check for ld --as-needed. + * configure: Rebuilt. + * config.in: Rebuilt. + * Makefile.in (stage1-start): Copy also libgcc_s*$(SHLIB_EXT). + (stage2-start, stage3-start, stage4-start): Likewise. + (stageprofile-start, stagefeedback-start): Likewise. + 2004-04-01 Jakub Jelinek PR c++/14755 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index e10f243b5baf..4d10ffbd7b55 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -3560,7 +3560,7 @@ stage1-start: -if [ -f as$(exeext) ] ; then (cd stage1 && $(LN_S) ../as$(exeext) .) ; else true ; fi -if [ -f ld$(exeext) ] ; then (cd stage1 && $(LN_S) ../ld$(exeext) .) ; else true ; fi -if [ -f collect-ld$(exeext) ] ; then (cd stage1 && $(LN_S) ../collect-ld$(exeext) .) ; else true ; fi - -rm -f stage1/libgcc.a stage1/libgcc_eh.a + -rm -f stage1/libgcc.a stage1/libgcc_eh.a stage1/libgcc_s*$(SHLIB_EXT) -cp libgcc.a stage1 -if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage1/libgcc.a; \ @@ -3569,6 +3569,7 @@ stage1-start: if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage1/libgcc_eh.a; \ else true; fi; fi + -cp libgcc_s*$(SHLIB_EXT) stage1/ -for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \ cp stage1/$${f} . ; \ else true; \ @@ -3589,7 +3590,7 @@ stage2-start: -if [ -f as$(exeext) ] ; then (cd stage2 && $(LN_S) ../as$(exeext) .) ; else true ; fi -if [ -f ld$(exeext) ] ; then (cd stage2 && $(LN_S) ../ld$(exeext) .) ; else true ; fi -if [ -f collect-ld$(exeext) ] ; then (cd stage2 && $(LN_S) ../collect-ld$(exeext) .) ; else true ; fi - -rm -f stage2/libgcc.a stage2/libgcc_eh.a + -rm -f stage2/libgcc.a stage2/libgcc_eh.a stage2/libgcc_s*$(SHLIB_EXT) -cp libgcc.a stage2 -if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage2/libgcc.a; \ @@ -3598,6 +3599,7 @@ stage2-start: if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage2/libgcc_eh.a; \ else true; fi; fi + -cp libgcc_s*$(SHLIB_EXT) stage2/ -for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \ cp stage2/$${f} . ; \ else true; \ @@ -3618,7 +3620,7 @@ stage3-start: -if [ -f as$(exeext) ] ; then (cd stage3 && $(LN_S) ../as$(exeext) .) ; else true ; fi -if [ -f ld$(exeext) ] ; then (cd stage3 && $(LN_S) ../ld$(exeext) .) ; else true ; fi -if [ -f collect-ld$(exeext) ] ; then (cd stage3 && $(LN_S) ../collect-ld$(exeext) .) ; else true ; fi - -rm -f stage3/libgcc.a stage3/libgcc_eh.a + -rm -f stage3/libgcc.a stage3/libgcc_eh.a stage3/libgcc_s*$(SHLIB_EXT) -cp libgcc.a stage3 -if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage3/libgcc.a; \ @@ -3627,6 +3629,7 @@ stage3-start: if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage3/libgcc_eh.a; \ else true; fi; fi + -cp libgcc_s*$(SHLIB_EXT) stage3/ -for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \ cp stage3/$${f} . ; \ else true; \ @@ -3647,7 +3650,7 @@ stage4-start: -if [ -f as$(exeext) ] ; then (cd stage4 && $(LN_S) ../as$(exeext) .) ; else true ; fi -if [ -f ld$(exeext) ] ; then (cd stage4 && $(LN_S) ../ld$(exeext) .) ; else true ; fi -if [ -f collect-ld$(exeext) ] ; then (cd stage4 && $(LN_S) ../collect-ld$(exeext) .) ; else true ; fi - -rm -f stage4/libgcc.a stage4/libgcc_eh.a + -rm -f stage4/libgcc.a stage4/libgcc_eh.a stage4/libgcc_s*$(SHLIB_EXT) -cp libgcc.a stage4 -if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage4/libgcc.a; \ @@ -3656,6 +3659,7 @@ stage4-start: if $(RANLIB_TEST_FOR_TARGET) ; then \ $(RANLIB_FOR_TARGET) stage4/libgcc_eh.a; \ else true; fi; fi + -cp libgcc_s*$(SHLIB_EXT) stage4/ -for f in .. $(EXTRA_MULTILIB_PARTS); do if [ x$${f} != x.. ]; then \ cp stage4/$${f} . ; \ else true; \ diff --git a/gcc/config.in b/gcc/config.in index faa2f7828031..748e7afb1f60 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -617,6 +617,9 @@ /* Define if your linker supports --eh-frame-hdr option. */ #undef HAVE_LD_EH_FRAME_HDR +/* Define if your linker supports --as-needed and --no-as-needed options. */ +#undef HAVE_LD_AS_NEEDED + /* Define if your MIPS libgloss linker scripts consistently include STARTUP directives. */ #undef HAVE_MIPS_LIBGLOSS_STARTUP_DIRECTIVES diff --git a/gcc/configure b/gcc/configure index 4e6d58304674..729e4dbcc633 100755 --- a/gcc/configure +++ b/gcc/configure @@ -8119,6 +8119,27 @@ EOF fi echo "$ac_t""$gcc_cv_ld_eh_frame_hdr" 1>&6 +echo $ac_n "checking linker --as-needed support""... $ac_c" 1>&6 +echo "configure:8250: checking linker --as-needed support" >&5 +gcc_cv_ld_as_needed=no +if test x$gcc_cv_gld_major_version != x -a x$gcc_cv_gld_minor_version != x; then + if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 16 -o "$gcc_cv_gld_major_version" -gt 2 && grep 'EMUL = elf' ../ld/Makefile > /dev/null; then + gcc_cv_ld_as_needed=yes + fi +elif test x$gcc_cv_ld != x; then + # Check if linker supports --as-needed and --no-as-needed options + if $gcc_cv_ld --help 2>/dev/null | grep as-needed > /dev/null; then + gcc_cv_ld_as_needed=yes + fi +fi +if test x"$gcc_cv_ld_as_needed" = xyes; then + cat >> confdefs.h <<\EOF +#define HAVE_LD_AS_NEEDED 1 +EOF + +fi +echo "$ac_t""$gcc_cv_ld_as_needed" 1>&6 + # Miscellaneous target-specific checks. case "$target" in mips*-*-*) diff --git a/gcc/configure.in b/gcc/configure.in index 3858dc0901e4..d3f0484020b0 100644 --- a/gcc/configure.in +++ b/gcc/configure.in @@ -2438,6 +2438,24 @@ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then fi AC_MSG_RESULT($gcc_cv_ld_eh_frame_hdr) +AC_MSG_CHECKING(linker --as-needed support) +gcc_cv_ld_as_needed=no +if test x$gcc_cv_gld_major_version != x -a x$gcc_cv_gld_minor_version != x; then + if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 16 -o "$gcc_cv_gld_major_version" -gt 2 && grep 'EMUL = elf' ../ld/Makefile > /dev/null; then + gcc_cv_ld_as_needed=yes + fi +elif test x$gcc_cv_ld != x; then + # Check if linker supports --as-needed and --no-as-needed options + if $gcc_cv_ld --help 2>/dev/null | grep as-needed > /dev/null; then + gcc_cv_ld_as_needed=yes + fi +fi +if test x"$gcc_cv_ld_as_needed" = xyes; then + AC_DEFINE(HAVE_LD_AS_NEEDED, 1, +[Define if your linker supports --as-needed and --no-as-needed options.]) +fi +AC_MSG_RESULT($gcc_cv_ld_as_needed) + # Miscellaneous target-specific checks. case "$target" in mips*-*-*) diff --git a/gcc/gcc.c b/gcc/gcc.c index 1de6e4264ff0..8753cd6c3c0b 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -1468,6 +1468,12 @@ init_gcc_specs (obstack, shared_name, static_name, eh_name) buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}%{!static:%{!static-libgcc:", +#ifdef HAVE_LD_AS_NEEDED + "%{!shared-libgcc:", static_name, + " --as-needed ", shared_name, " --no-as-needed}" + "%{shared-libgcc:", shared_name, "%{!shared: ", static_name, + "}", +#else "%{!shared:%{!shared-libgcc:", static_name, " ", eh_name, "}%{shared-libgcc:", shared_name, " ", static_name, "}}%{shared:", @@ -1476,6 +1482,7 @@ init_gcc_specs (obstack, shared_name, static_name, eh_name) "}%{!shared-libgcc:", static_name, "}", #else shared_name, +#endif #endif "}}}", NULL); -- 2.47.2