Fix and document -r option
authorAllan Sandfeld Jensen <allan.jensen@qt.io>
Thu, 20 Sep 2018 19:38:24 +0000 (01:38 +0600)
committerJoseph Myers <jsm28@gcc.gnu.org>
Thu, 20 Sep 2018 19:38:24 +0000 (20:38 +0100)
The option has existed and been working for years,
make sure it implies the right extra options, and list
it in the documentation.

2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>

gcc/
* gcc.c (LINK_COMMAND_SPEC): Handle -r like -nostdlib.
(VTABLE_VERIFICATION_SPEC): Likewise.
(SANITIZER_EARLY_SPEC): Likewise.
(SANITIZER_SPEC): Likewise.
* config/darwin.h (LINK_COMMAND_SPEC): Likewise.
* doc/invoke.texi (Link Options): Document -r.

gcc/cp/
* g++spec.c (lang_specific_driver): Handle -r like -nostdlib.

gcc/fortran/
* gfortranspec.c (lang_specific_driver): Handle -r like -nostdlib.

gcc/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: Likewise.
* g++.dg/lto/20090302_0.C: Likewise.
* g++.dg/lto/pr45621_0.C: Likewise.
* g++.dg/lto/pr60567_0.C: Likewise.
* g++.dg/lto/pr62026.C: Likewise.
* gcc.dg/lto/pr45736_0.c: Likewise.
* gcc.dg/lto/pr52634_0.c: Likewise.
* gfortran.dg/lto/20091016-1_0.f90: Likewise.
* gfortran.dg/lto/pr79108_0.f90: Likewise.

From-SVN: r264451

21 files changed:
gcc/ChangeLog
gcc/config/darwin.h
gcc/cp/ChangeLog
gcc/cp/g++spec.c
gcc/doc/invoke.texi
gcc/fortran/ChangeLog
gcc/fortran/gfortranspec.c
gcc/gcc.c
gcc/go/ChangeLog
gcc/go/gospec.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ipa/pr64059.C
gcc/testsuite/g++.dg/lto/20081109-1_0.C
gcc/testsuite/g++.dg/lto/20090302_0.C
gcc/testsuite/g++.dg/lto/pr45621_0.C
gcc/testsuite/g++.dg/lto/pr60567_0.C
gcc/testsuite/g++.dg/lto/pr62026.C
gcc/testsuite/gcc.dg/lto/pr45736_0.c
gcc/testsuite/gcc.dg/lto/pr52634_0.c
gcc/testsuite/gfortran.dg/lto/20091016-1_0.f90
gcc/testsuite/gfortran.dg/lto/pr79108_0.f90

index 361dfc468a1712dffb58657cd18a3c16bfe5a19a..8be6771ce5013b988c8133db8062ec08626a6237 100644 (file)
@@ -1,3 +1,12 @@
+2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>
+
+       * gcc.c (LINK_COMMAND_SPEC): Handle -r like -nostdlib.
+       (VTABLE_VERIFICATION_SPEC): Likewise.
+       (SANITIZER_EARLY_SPEC): Likewise.
+       (SANITIZER_SPEC): Likewise.
+       * config/darwin.h (LINK_COMMAND_SPEC): Likewise.
+       * doc/invoke.texi (Link Options): Document -r.
+
 2018-09-20  Richard Biener <rguenther@suse.de>
 
        PR middle-end/87054
index cd6d65216582e7632fa45af62b2b4b47b67cdab1..87f610259c0119c11aeabe5aabd67511b080c0c5 100644 (file)
@@ -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"
 
index c5072d53334d60fd344fdf2093e3cc9562765e60..0260ff670b9a6cd8bf128c7a866a2cf306099061 100644 (file)
@@ -1,3 +1,7 @@
+2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>
+
+       * g++spec.c (lang_specific_driver): Handle -r like -nostdlib.
+
 2018-09-20  Jason Merrill  <jason@redhat.com>
 
        PR c++/87075 - ICE with constexpr array initialization.
index 443a1746da3791eb3d402fb947afa8d76fe2c049..8c81e0987f750bf7a24e9cf68a2c74969f7e0fff 100644 (file)
@@ -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:
index b3b50c266e4626fc1e562ae3436a85274f63adac..e565f8519712286592e38091342f10d22a254453 100644 (file)
@@ -521,7 +521,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
@@ -12586,6 +12586,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
index 7cbda093eee8488e9a7a4088ed5b7d0996264459..dbd05d2b23e973e3b987318829fc92d07e6db2ab 100644 (file)
@@ -1,3 +1,7 @@
+2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>
+
+       * gfortranspec.c (lang_specific_driver): Handle -r like -nostdlib.
+
 2018-09-20  Janus Weil  <janus@gcc.gnu.org>
 
        * gfortran.h (gfc_str_startswith): New macro.
index 4ba3a8dba60eda166d4accfe4bd8b13a860cf943..7aa2dd78a0504b73e1b4173052d52fae2e11f47c 100644 (file)
@@ -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:
index 8be82eaa04fd8b8b6b7a28f6e04b72d58fea8fdb..264204d7b379ae204e32864b23df623807963db9 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -980,20 +980,20 @@ proper position among the other output files.  */
 /* Linker command line options for -fsanitize= early on the command line.  */
 #ifndef SANITIZER_EARLY_SPEC
 #define SANITIZER_EARLY_SPEC "\
-%{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
+%{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
     %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \
-    %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}"
+    %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}"
 #endif
 
 /* Linker command line options for -fsanitize= late on the command line.  */
 #ifndef SANITIZER_SPEC
 #define SANITIZER_SPEC "\
-%{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\
+%{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\
     %{static:%ecannot specify -static with -fsanitize=address}}\
     %{%:sanitize(thread):" LIBTSAN_SPEC "\
     %{static:%ecannot specify -static with -fsanitize=thread}}\
     %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\
-    %{%:sanitize(leak):" LIBLSAN_SPEC "}}}"
+    %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}"
 #endif
 
 #ifndef POST_LINK_SPEC
@@ -1007,8 +1007,8 @@ proper position among the other output files.  */
 #ifndef VTABLE_VERIFICATION_SPEC
 #if ENABLE_VTABLE_VERIFY
 #define VTABLE_VERIFICATION_SPEC "\
-%{!nostdlib:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
-    %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}"
+%{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
+    %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}"
 #else
 #define VTABLE_VERIFICATION_SPEC "\
 %{fvtable-verify=none:} \
@@ -1040,7 +1040,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):\
@@ -1048,8 +1048,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
index b032a27f6f807454e4665596de84fb1a9fd74447..35129223726c0becd820cef56d2bac4491892b7e 100644 (file)
@@ -1,3 +1,7 @@
+2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>
+
+       * gospec.c (lang_specific_driver): Handle -r like -nostdlib.
+
 2018-08-27  Martin Liska  <mliska@suse.cz>
 
        * go-gcc.cc (Gcc_backend::call_expression): Use new function
index 7a10997df9b46fd05677431ee77a8b23d832f45a..d265fc986a05c6cd22817dcac14b1a6adad8b1a1 100644 (file)
@@ -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;
index a0a08a4d499856a1cb8712b3851c66a01e566cb5..bcac8dc0e89ad6d4e26135c7b169b648aa591593 100644 (file)
@@ -1,3 +1,16 @@
+2018-09-20  Allan Sandfeld Jensen  <allan.jensen@qt.io>
+
+       * g++.dg/ipa/pr64059.C: Removed now redundant -nostdlib.
+       * g++.dg/lto/20081109-1_0.C: Likewise.
+       * g++.dg/lto/20090302_0.C: Likewise.
+       * g++.dg/lto/pr45621_0.C: Likewise.
+       * g++.dg/lto/pr60567_0.C: Likewise.
+       * g++.dg/lto/pr62026.C: Likewise.
+       * gcc.dg/lto/pr45736_0.c: Likewise.
+       * gcc.dg/lto/pr52634_0.c: Likewise.
+       * gfortran.dg/lto/20091016-1_0.f90: Likewise.
+       * gfortran.dg/lto/pr79108_0.f90: Likewise.
+
 2018-09-20  Alexandre Oliva <oliva@adacore.com>
 
        PR middle-end/87054
index 0269b45458d97631c44397e6ea8e252c85e816ae..57011324889e9fc53cbf222a56a222277fda7812 100644 (file)
@@ -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;
index 3b5860011db7e03674189232654232db1623e20c..db0ba367fe8c1d13968c338672d720dd8eb8ed67 100644 (file)
@@ -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) { } };
index 3a617879e19f362731d3eed7408a4c70fe53986d..23e012704f4fbc326cc20be33a79cd7207207ef5 100644 (file)
@@ -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();
index f34b3b70fa7b4d682ed2ba9098faa03c3f81093f..2055ebfa658bb233599adf9ef5435ab90a4607da 100644 (file)
@@ -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
index 966a3c3bc7421775613f7e37c02562e0326aef42..175b3aa7a0476d39399e4f1fabecabe10d005158 100644 (file)
@@ -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 {};
index 63766a85b986e4a72c73bb22ca7b23cae0c74a38..0432e907f56f667058418f3d3ec57a02e26580ef 100644 (file)
@@ -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();
index d481c453d08fddcfd5018325209de96099ee380d..cb7811ba25850d21bb1fb4a707e5ed7d5220e3da 100644 (file)
@@ -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);
index 7aba0cd3caf03e86d25c8fc021dfe758b8f9fb6d..5e14ad9a73359bde4f8a9dfeab3382bd4392a425 100644 (file)
@@ -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 *);
index 5e96e88731ff0041b83d208bfcb0274069ec5bc6..812ae9b266dbb9fd5cb95dff26d6df842513f325 100644 (file)
@@ -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)
index 58412afc3c82a99bd26ed5c6b5eed4c4b750bd4a..9c878509a83c4953d659ec67769cdba93af89809 100644 (file)
@@ -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