This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch][GCC] Document and fix -r (partial linking)


On Donnerstag, 23. August 2018 23:24:02 CEST Joseph Myers wrote:
> On Thu, 23 Aug 2018, Iain Sandoe wrote:
> > Joseph: As a side-comment, is there a reason that we don’t exclude
> > gomp/itm/fortran/gcov from the link for -nostdlib / -nodefaultlib?
> > 
> > If we are relying on the lib self-specs for this, then we’re not
> > succeeding since the one we build at the moment don’t include those
> > clauses.
> 
> Well, fortran/gfortranspec.c for example has
> 
>         case OPT_nostdlib:
>         case OPT_nodefaultlibs:
>         case OPT_c:
>         case OPT_S:
>         case OPT_fsyntax_only:
>         case OPT_E:
>           /* These options disable linking entirely or linking of the
>              standard libraries.  */
>           library = 0;
>           break;
> 
> and only uses libgfortran.spec if (library).  So it's certainly meant to
> avoid linking with libgfortran or its dependencies if -nostdlib.

Patch updated. I specifically edited a number of the existing tests that used 
both -r and -nostdlib and removed -nostdlib so the patch is exercised by 
existing tests. The patch bootstrapped, I didn't notice any relevant failures 
when running the test suite (though I could have missed something, I am never
comfortable reading that output).

'Allan

>From 07ed41a9afd107c5d45feb1ead7a74ca735a1bb2 Mon Sep 17 00:00:00 2001
From: Allan Sandfeld Jensen <carewolf@dragon.local>
Date: Sun, 26 Aug 2018 20:02:54 +0200
Subject: [PATCH] Fix and document -r option

The option has existed and been working for years,
make sure it implies the right extra options, and list
it in the documentation.

2018-08-26 Allan Sandfeld Jensen <allan.jensen@qt.io>

gcc/doc/
    * invoke.texi: Document -r.

gcc/
    * gcc.c (LINK_COMMAND_SPEC): Handle -r like -nostdlib.
    * config/darwin.h (LINK_COMMAND_SPEC): Handle -r like -nostdlib.
    * cp/g++spec.c (lang_specific_driver): Handle -r like -nostdlib.
    * fortran/gfortranspec.c (lang_specific_driver): Handle -r like -nostdlib.
    * go/gospec.c (lang_specific_driver): Handle -r like -nostdlib.

gcc/testsuite/
    * g++.dg/ipa/pr64059.C: Removed now redundant -nostdlib.
    * g++.dg/lto/20081109-1_0.C: Removed now redundant -nostdlib.
    * g++.dg/lto/20090302_0.C: Removed now redundant -nostdlib.
    * g++.dg/lto/pr45621_0.C: Removed now redundant -nostdlib.
    * g++.dg/lto/pr60567_0.C: Removed now redundant -nostdlib.
    * g++.dg/lto/pr62026.C: Removed now redundant -nostdlib.
    * gcc.dg/lto/pr45736_0.c: Removed now redundant -nostdlib.
    * gcc.dg/lto/pr52634_0.c: Removed now redundant -nostdlib.
    * gfortran.dg/lto/20091016-1_0.f90: Removed now redundant -nostdlib.
    * gfortran.dg/lto/pr79108_0.f90: Removed now redundant -nostdlib.

---
 gcc/config/darwin.h                            | 8 ++++----
 gcc/cp/g++spec.c                               | 1 +
 gcc/doc/invoke.texi                            | 7 ++++++-
 gcc/fortran/gfortranspec.c                     | 1 +
 gcc/gcc.c                                      | 6 +++---
 gcc/go/gospec.c                                | 1 +
 gcc/testsuite/g++.dg/ipa/pr64059.C             | 2 +-
 gcc/testsuite/g++.dg/lto/20081109-1_0.C        | 2 +-
 gcc/testsuite/g++.dg/lto/20090302_0.C          | 2 +-
 gcc/testsuite/g++.dg/lto/pr45621_0.C           | 2 +-
 gcc/testsuite/g++.dg/lto/pr60567_0.C           | 2 +-
 gcc/testsuite/g++.dg/lto/pr62026.C             | 2 +-
 gcc/testsuite/gcc.dg/lto/pr45736_0.c           | 2 +-
 gcc/testsuite/gcc.dg/lto/pr52634_0.c           | 2 +-
 gcc/testsuite/gfortran.dg/lto/20091016-1_0.f90 | 2 +-
 gcc/testsuite/gfortran.dg/lto/pr79108_0.f90    | 2 +-
 16 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index cd6d6521658..87f610259c0 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -180,20 +180,20 @@ extern GTY(()) int darwin_ms_struct;
    "%X %{s} %{t} %{Z} %{u*} \
     %{e*} %{r} \
     %{o*}%{!o:-o a.out} \
-    %{!nostdlib:%{!nostartfiles:%S}} \
+    %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
     %{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
     %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \
       %{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
     %{fgnu-tm: \
       %{static|static-libgcc|static-libstdc++|static-libgfortran: libitm.a%s; : -litm } } \
-    %{!nostdlib:%{!nodefaultlibs:\
+    %{!nostdlib:%{!r:%{!nodefaultlibs:\
       %{%:sanitize(address): -lasan } \
       %{%:sanitize(undefined): -lubsan } \
       %(link_ssp) \
       " DARWIN_EXPORT_DYNAMIC " %<rdynamic \
       %(link_gcc_c_sequence) \
-    }}\
-    %{!nostdlib:%{!nostartfiles:%E}} %{T*} %{F*} }}}}}}}"
+    }}}\
+    %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} %{F*} }}}}}}}"
 
 #define DSYMUTIL "\ndsymutil"
 
diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c
index 443a1746da3..8c81e0987f7 100644
--- a/gcc/cp/g++spec.c
+++ b/gcc/cp/g++spec.c
@@ -184,6 +184,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
 	  break;
 
 	case OPT_c:
+	case OPT_r:
 	case OPT_S:
 	case OPT_E:
 	case OPT_M:
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e4148297a87..cab186d5bf0 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -520,7 +520,7 @@ Objective-C and Objective-C++ Dialects}.
 @xref{Link Options,,Options for Linking}.
 @gccoptlist{@var{object-file-name}  -fuse-ld=@var{linker}  -l@var{library} @gol
 -nostartfiles  -nodefaultlibs  -nolibc  -nostdlib @gol
--pie  -pthread  -rdynamic @gol
+-pie  -pthread  -r  -rdynamic @gol
 -s  -static -static-pie -static-libgcc  -static-libstdc++ @gol
 -static-libasan  -static-libtsan  -static-liblsan  -static-libubsan @gol
 -shared  -shared-libgcc  -symbolic @gol
@@ -12510,6 +12510,11 @@ x86 Cygwin and MinGW targets.  On some targets this option also sets
 flags for the preprocessor, so it should be used consistently for both
 compilation and linking.
 
+@item -r
+@opindex r
+Produce a relocatable object as output. This is also known as partial
+linking.
+
 @item -rdynamic
 @opindex rdynamic
 Pass the flag @option{-export-dynamic} to the ELF linker, on targets
diff --git a/gcc/fortran/gfortranspec.c b/gcc/fortran/gfortranspec.c
index 4ba3a8dba60..7aa2dd78a05 100644
--- a/gcc/fortran/gfortranspec.c
+++ b/gcc/fortran/gfortranspec.c
@@ -243,6 +243,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
 	case OPT_nostdlib:
 	case OPT_nodefaultlibs:
 	case OPT_c:
+	case OPT_r:
 	case OPT_S:
 	case OPT_fsyntax_only:
 	case OPT_E:
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 780d4859ef3..687903cb1be 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1041,7 +1041,7 @@ proper position among the other output files.  */
     %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
    "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
    "%X %{o*} %{e*} %{N} %{n} %{r}\
-    %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \
+    %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
     %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
     VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
     %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
@@ -1049,8 +1049,8 @@ proper position among the other output files.  */
     %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
     %(mflib) " STACK_SPLIT_SPEC "\
     %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \
-    %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\
-    %{!nostdlib:%{!nostartfiles:%E}} %{T*}  \n%(post_link) }}}}}}"
+    %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\
+    %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*}  \n%(post_link) }}}}}}"
 #endif
 
 #ifndef LINK_LIBGCC_SPEC
diff --git a/gcc/go/gospec.c b/gcc/go/gospec.c
index 7a10997df9b..d265fc986a0 100644
--- a/gcc/go/gospec.c
+++ b/gcc/go/gospec.c
@@ -139,6 +139,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
 
       switch (decoded_options[i].opt_index)
 	{
+	case OPT_r:
 	case OPT_nostdlib:
 	case OPT_nodefaultlibs:
 	  library = -1;
diff --git a/gcc/testsuite/g++.dg/ipa/pr64059.C b/gcc/testsuite/g++.dg/ipa/pr64059.C
index 0269b45458d..57011324889 100644
--- a/gcc/testsuite/g++.dg/ipa/pr64059.C
+++ b/gcc/testsuite/g++.dg/ipa/pr64059.C
@@ -1,4 +1,4 @@
-// { dg-options "-r -nostdlib -O2 -flto -fno-devirtualize" }
+// { dg-options "-r -O2 -flto -fno-devirtualize" }
 // { dg-require-effective-target lto }
 
 class A;
diff --git a/gcc/testsuite/g++.dg/lto/20081109-1_0.C b/gcc/testsuite/g++.dg/lto/20081109-1_0.C
index 3b5860011db..db0ba367fe8 100644
--- a/gcc/testsuite/g++.dg/lto/20081109-1_0.C
+++ b/gcc/testsuite/g++.dg/lto/20081109-1_0.C
@@ -1,6 +1,6 @@
 // { dg-lto-do link }
 // { dg-require-effective-target fpic }
 // { dg-lto-options {{-fPIC -flto -flto-partition=1to1}} }
-// { dg-extra-ld-options "-fPIC -flto -flto-partition=1to1 -r -nostdlib -fno-exceptions -flinker-output=nolto-rel" }
+// { dg-extra-ld-options "-fPIC -flto -flto-partition=1to1 -r -fno-exceptions -flinker-output=nolto-rel" }
 void func(); class Foo { };
 void bar() { try { func(); } catch (Foo) { } };
diff --git a/gcc/testsuite/g++.dg/lto/20090302_0.C b/gcc/testsuite/g++.dg/lto/20090302_0.C
index 3a617879e19..23e012704f4 100644
--- a/gcc/testsuite/g++.dg/lto/20090302_0.C
+++ b/gcc/testsuite/g++.dg/lto/20090302_0.C
@@ -1,6 +1,6 @@
 /* { dg-lto-do link } */
 /* { dg-require-effective-target fpic } */
-/* { dg-lto-options {{-fPIC -flto -flto-partition=1to1 -r -nostdlib}} } */
+/* { dg-lto-options {{-fPIC -flto -flto-partition=1to1 -r}} } */
 /* { dg-extra-ld-options "-flinker-output=nolto-rel" } */
 struct Foo {
   bool Mumble();
diff --git a/gcc/testsuite/g++.dg/lto/pr45621_0.C b/gcc/testsuite/g++.dg/lto/pr45621_0.C
index f34b3b70fa7..2055ebfa658 100644
--- a/gcc/testsuite/g++.dg/lto/pr45621_0.C
+++ b/gcc/testsuite/g++.dg/lto/pr45621_0.C
@@ -1,5 +1,5 @@
 // { dg-lto-do assemble }
-// { dg-extra-ld-options "-O2 -fipa-cp-clone -flto -nostdlib -r -flinker-output=nolto-rel" }
+// { dg-extra-ld-options "-O2 -fipa-cp-clone -flto -r -flinker-output=nolto-rel" }
 #include "pr45621.h"
 
 void
diff --git a/gcc/testsuite/g++.dg/lto/pr60567_0.C b/gcc/testsuite/g++.dg/lto/pr60567_0.C
index 966a3c3bc74..175b3aa7a04 100644
--- a/gcc/testsuite/g++.dg/lto/pr60567_0.C
+++ b/gcc/testsuite/g++.dg/lto/pr60567_0.C
@@ -1,7 +1,7 @@
 // PR lto/60567
 // { dg-lto-do link }
 // { dg-lto-options { { -flto -fno-use-linker-plugin } } }
-// { dg-extra-ld-options "-r -nostdlib" }
+// { dg-extra-ld-options "-r" }
 
 #pragma implementation
 struct S {};
diff --git a/gcc/testsuite/g++.dg/lto/pr62026.C b/gcc/testsuite/g++.dg/lto/pr62026.C
index 63766a85b98..0432e907f56 100644
--- a/gcc/testsuite/g++.dg/lto/pr62026.C
+++ b/gcc/testsuite/g++.dg/lto/pr62026.C
@@ -1,5 +1,5 @@
 // { dg-lto-do link }
-// { dg-lto-options {{-flto -O3 -r -nostdlib}} }
+// { dg-lto-options {{-flto -O3 -r}} }
 class C;
 class F {
   virtual C m_fn1();
diff --git a/gcc/testsuite/gcc.dg/lto/pr45736_0.c b/gcc/testsuite/gcc.dg/lto/pr45736_0.c
index d481c453d08..cb7811ba258 100644
--- a/gcc/testsuite/gcc.dg/lto/pr45736_0.c
+++ b/gcc/testsuite/gcc.dg/lto/pr45736_0.c
@@ -1,5 +1,5 @@
 /* { dg-lto-do link } */
-/* { dg-lto-options {{-flto -r -nostdlib -O}} } */
+/* { dg-lto-options {{-flto -r -O}} } */
 /* { dg-extra-ld-options "-flinker-output=nolto-rel" } */
 
 extern void baz (void);
diff --git a/gcc/testsuite/gcc.dg/lto/pr52634_0.c b/gcc/testsuite/gcc.dg/lto/pr52634_0.c
index 7aba0cd3caf..5e14ad9a733 100644
--- a/gcc/testsuite/gcc.dg/lto/pr52634_0.c
+++ b/gcc/testsuite/gcc.dg/lto/pr52634_0.c
@@ -1,7 +1,7 @@
 /* { dg-require-weak "" } */
 /* { dg-require-alias "" } */
 /* { dg-lto-do link } */
-/* { dg-lto-options {{-flto -r -nostdlib -flto-partition=1to1}} */
+/* { dg-lto-options {{-flto -r -flto-partition=1to1}} */
 /* { dg-extra-ld-options "-flinker-output=nolto-rel" } */
 extern int cfliteValueCallBacks;
 void baz (int *);
diff --git a/gcc/testsuite/gfortran.dg/lto/20091016-1_0.f90 b/gcc/testsuite/gfortran.dg/lto/20091016-1_0.f90
index 5e96e88731f..812ae9b266d 100644
--- a/gcc/testsuite/gfortran.dg/lto/20091016-1_0.f90
+++ b/gcc/testsuite/gfortran.dg/lto/20091016-1_0.f90
@@ -1,5 +1,5 @@
 ! { dg-lto-do link }
-! { dg-lto-options {{-flto -g -fPIC -r -nostdlib} {-O -flto -g -fPIC -r -nostdlib}} }
+! { dg-lto-options {{-flto -g -fPIC -r} {-O -flto -g -fPIC -r}} }
 ! { dg-extra-ld-options "-flinker-output=nolto-rel" }
 
       FUNCTION makenumberstring(x)
diff --git a/gcc/testsuite/gfortran.dg/lto/pr79108_0.f90 b/gcc/testsuite/gfortran.dg/lto/pr79108_0.f90
index 58412afc3c8..9c878509a83 100644
--- a/gcc/testsuite/gfortran.dg/lto/pr79108_0.f90
+++ b/gcc/testsuite/gfortran.dg/lto/pr79108_0.f90
@@ -1,6 +1,6 @@
 ! { dg-lto-do link }
 ! { dg-lto-options {{ -Ofast -flto --param ggc-min-expand=0 --param ggc-min-heapsize=0 }} }
-! { dg-extra-ld-options "-r -nostdlib" }
+! { dg-extra-ld-options "-r" }
 
 MODULE Errorcheck_mod
 CONTAINS
-- 
2.18.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]