On Mittwoch, 1. August 2018 18:32:30 CEST Joseph Myers wrote: > On Wed, 1 Aug 2018, Allan Sandfeld Jensen wrote: > > gcc/ > > > > * gcc.c: Correct default specs for -r > > I don't follow why your changes (which would need describing for each > individual spec changed) are corrections. > > > /* config.h can define LIB_SPEC to override the default libraries. */ > > #ifndef LIB_SPEC > > > > -#define LIB_SPEC "%{!shared:%{g*:-lg} > > %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" +#define LIB_SPEC > > "%{!shared|!r:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"> > > #endif > > '!' binds more closely than '|' in specs. That is, !shared|!r means the > following specs are used unless both -shared and -r are specified, which > seems nonsensical to me. I'd expect something more like "shared|r:;" to > expand to nothing if either -shared or -r is passed and to what follows if > neither is passed. > > And that ignores that this LIB_SPEC value in gcc.c is largely irrelevant, > as it's generally overridden by targets - and normally for targets using > ELF shared libraries, for example, -lc *does* have to be used when linking > with -shared. > > I think you're changing the wrong place for this. If you want -r to be > usable with GCC without using -nostdlib (which is an interesting > question), you actually need to change LINK_COMMAND_SPEC (also sometimes > overridden for targets) to handle -r more like -nostdlib -nostartfiles. > Okay, so like this?
>From 9de68f2ef0b77a0c0bcf0d83232e7fc34b006406 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen <allan.jen...@qt.io> Date: Wed, 1 Aug 2018 18:07:05 +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-07-29 Allan Sandfeld Jensen <allan.jen...@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 --- gcc/config/darwin.h | 8 ++++---- gcc/doc/invoke.texi | 7 ++++++- gcc/gcc.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 980ad9b4057..6ad657a4958 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -178,20 +178,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/doc/invoke.texi b/gcc/doc/invoke.texi index 6047d82065a..7da30bd9d99 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -518,7 +518,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 @@ -12444,6 +12444,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/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 -- 2.17.0