* [PATCH] modula-2, driver: Implement handling for -static-libgm2. @ 2023-01-02 10:38 Iain Sandoe 2023-01-04 12:11 ` Gaius Mulley 0 siblings, 1 reply; 4+ messages in thread From: Iain Sandoe @ 2023-01-02 10:38 UTC (permalink / raw) To: gcc-patches; +Cc: gaiusmod2 tested on x86_64-linux-gnu, x86_64,aarch64-darwin21, OK for trunk? thanks, Iain --- 8< --- This was unimplemented so far. gcc/ChangeLog: * common.opt: Add -static-libgm2. * config/darwin.h (LINK_SPEC): Handle static-libgm2. gcc/m2/ChangeLog: * gm2spec.cc (lang_specific_driver): Handle static-libgm2. --- gcc/common.opt | 4 ++++ gcc/config/darwin.h | 7 ++++++- gcc/m2/gm2spec.cc | 24 +++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index b01f7a7a4a2..0f3910cf5f6 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3630,6 +3630,10 @@ static-libgfortran Driver ; Documented for Fortran, but always accepted by driver. +static-libgm2 +Driver +; Documented for Modula-2, but always accepted by driver. + static-libphobos Driver ; Documented for D, but always accepted by driver. diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 0ec882ffb54..a3edd7c922b 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -476,7 +476,12 @@ extern GTY(()) int darwin_ms_struct; %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\ %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\ %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\ - %{force_cpusubtype_ALL:-arch %(darwin_arch)} \ + %{static|static-libgm2:%:replace-outfile(-lm2pim libm2pim.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2iso libm2iso.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2min libm2min.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2log libm2log.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2cor libm2cor.a%s)}\ + %{force_cpusubtype_ALL:-arch %(darwin_arch)} \ %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\ LINK_SYSROOT_SPEC \ "%{mmacosx-version-min=*:-macosx_version_min %*} \ diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc index 4996fa49789..6a17114c9f3 100644 --- a/gcc/m2/gm2spec.cc +++ b/gcc/m2/gm2spec.cc @@ -585,6 +585,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* Should the driver perform a link? */ bool linking = true; + /* Should the driver link the shared gm2 libs? */ + bool shared_libgm2 = true; + /* "-lm" or "-lmath" if it appears on the command line. */ const struct cl_decoded_option *saw_math = NULL; @@ -594,7 +597,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* By default, we throw on the math library if we have one. */ int need_math = (MATH_LIBRARY[0] != '\0'); - /* 1 if we should add -lpthread to the command-line. */ + /* 1 if we should add -lpthread to the command-line. + FIXME: the default should be a configuration choice. */ int need_pthread = 1; /* True if we saw -static. */ @@ -774,6 +778,16 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif break; + case OPT_static_libgm2: + shared_libgm2 = false; +#ifdef HAVE_LD_STATIC_DYNAMIC + /* Remove -static-libgm2 from the command only if target supports + LD_STATIC_DYNAMIC. When not supported, it is left in so that a + back-end target can use outfile substitution. */ + args[i] |= SKIPOPT; +#endif + break; + case OPT_stdlib_: which_library = (stdcxxlib_kind) decoded_options[i].value; break; @@ -877,8 +891,16 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if (linking) { +#ifdef HAVE_LD_STATIC_DYNAMIC + if (allow_libraries && !shared_libgm2) + append_option (OPT_Wl_, LD_STATIC_OPTION, 1); +#endif if (allow_libraries) add_default_archives (libpath, libraries); +#ifdef HAVE_LD_STATIC_DYNAMIC + if (allow_libraries && !shared_libgm2) + append_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1); +#endif /* Add `-lstdc++' if we haven't already done so. */ #ifdef HAVE_LD_STATIC_DYNAMIC if (library > 1 && !static_link) -- 2.37.1 (Apple Git-137.1) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] modula-2, driver: Implement handling for -static-libgm2. 2023-01-02 10:38 [PATCH] modula-2, driver: Implement handling for -static-libgm2 Iain Sandoe @ 2023-01-04 12:11 ` Gaius Mulley 2023-01-04 19:41 ` Iain Sandoe 0 siblings, 1 reply; 4+ messages in thread From: Gaius Mulley @ 2023-01-04 12:11 UTC (permalink / raw) To: Iain Sandoe; +Cc: gcc-patches, iain Iain Sandoe <iains.gcc@gmail.com> writes: > tested on x86_64-linux-gnu, x86_64,aarch64-darwin21, > OK for trunk? > thanks, > Iain > > --- 8< --- > > This was unimplemented so far. > > gcc/ChangeLog: > > * common.opt: Add -static-libgm2. > * config/darwin.h (LINK_SPEC): Handle static-libgm2. > > gcc/m2/ChangeLog: > > * gm2spec.cc (lang_specific_driver): Handle static-libgm2. > --- > gcc/common.opt | 4 ++++ > gcc/config/darwin.h | 7 ++++++- > gcc/m2/gm2spec.cc | 24 +++++++++++++++++++++++- > 3 files changed, 33 insertions(+), 2 deletions(-) > yes LGTM - it was unimplemented - thanks! regards, Gaius ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] modula-2, driver: Implement handling for -static-libgm2. 2023-01-04 12:11 ` Gaius Mulley @ 2023-01-04 19:41 ` Iain Sandoe 2023-01-05 3:07 ` Gaius Mulley 0 siblings, 1 reply; 4+ messages in thread From: Iain Sandoe @ 2023-01-04 19:41 UTC (permalink / raw) To: Gaius Mulley; +Cc: GCC Patches Hi Gaius, > On 4 Jan 2023, at 12:11, Gaius Mulley <gaiusmod2@gmail.com> wrote: > > Iain Sandoe <iains.gcc@gmail.com> writes: > >> tested on x86_64-linux-gnu, x86_64,aarch64-darwin21, > > yes LGTM - it was unimplemented - thanks! My apologies, when I came to apply this I realised that I posted the wrong version of the patch - omitting the documentation changes. Here is the version with (albeit basic) documentation. Still OK for master? Iain [PATCH] modula-2, driver: Implement handling for -static-libgm2. This was unimplemented so far. gcc/ChangeLog: * common.opt: Add -static-libgm2. * config/darwin.h (LINK_SPEC): Handle static-libgm2. * doc/gm2.texi: Document static-libgm2. * gcc.cc (driver_handle_option): Allow static-libgm2. gcc/m2/ChangeLog: * gm2spec.cc (lang_specific_driver): Handle static-libgm2. * lang.opt: Add static-libgm2. --- gcc/common.opt | 4 ++++ gcc/config/darwin.h | 7 ++++++- gcc/doc/gm2.texi | 4 ++++ gcc/gcc.cc | 12 +++++++----- gcc/m2/gm2spec.cc | 24 +++++++++++++++++++++++- gcc/m2/lang.opt | 4 ++++ 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 97a78030228..d0371aec8db 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -3622,6 +3622,10 @@ static-libgfortran Driver ; Documented for Fortran, but always accepted by driver. +static-libgm2 +Driver +; Documented for Modula-2, but always accepted by driver. + static-libphobos Driver ; Documented for D, but always accepted by driver. diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index efe3187cd96..e6f76e598e6 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -447,7 +447,12 @@ extern GTY(()) int darwin_ms_struct; %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\ %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\ %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\ - %{force_cpusubtype_ALL:-arch %(darwin_arch)} \ + %{static|static-libgm2:%:replace-outfile(-lm2pim libm2pim.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2iso libm2iso.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2min libm2min.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2log libm2log.a%s)}\ + %{static|static-libgm2:%:replace-outfile(-lm2cor libm2cor.a%s)}\ + %{force_cpusubtype_ALL:-arch %(darwin_arch)} \ %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\ LINK_SYSROOT_SPEC \ "%{mmacosx-version-min=*:-macosx_version_min %*} \ diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi index 513fdd3ec7f..18cb798c6cd 100644 --- a/gcc/doc/gm2.texi +++ b/gcc/doc/gm2.texi @@ -573,6 +573,10 @@ the they provide the base modules which all other dialects utilize. The option @samp{-fno-libs=-} disables the @samp{gm2} driver from modifying the search and library paths. +@item -static-libgm2 +On systems that provide the m2 runtimes as both shared and static libraries, +this option forces the use of the static version. + @c flocation= @c Modula-2 Joined @c set all location values to a specific value (internal switch) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 91313a8516d..d629ca5e424 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -4540,12 +4540,14 @@ driver_handle_option (struct gcc_options *opts, case OPT_static_libgfortran: case OPT_static_libquadmath: case OPT_static_libphobos: + case OPT_static_libgm2: case OPT_static_libstdc__: - /* These are always valid, since gcc.cc itself understands the - first two, gfortranspec.cc understands -static-libgfortran, - d-spec.cc understands -static-libphobos, g++spec.cc - understands -static-libstdc++ and libgfortran.spec handles - -static-libquadmath. */ + /* These are always valid; gcc.cc itself understands the first two + gfortranspec.cc understands -static-libgfortran, + libgfortran.spec handles -static-libquadmath, + d-spec.cc understands -static-libphobos, + gm2spec.cc understands -static-libgm2, + and g++spec.cc understands -static-libstdc++. */ validated = true; break; diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc index b9a5c4e79bb..583723da416 100644 --- a/gcc/m2/gm2spec.cc +++ b/gcc/m2/gm2spec.cc @@ -586,6 +586,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* Should the driver perform a link? */ bool linking = true; + /* Should the driver link the shared gm2 libs? */ + bool shared_libgm2 = true; + /* "-lm" or "-lmath" if it appears on the command line. */ const struct cl_decoded_option *saw_math = NULL; @@ -595,7 +598,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* By default, we throw on the math library if we have one. */ int need_math = (MATH_LIBRARY[0] != '\0'); - /* 1 if we should add -lpthread to the command-line. */ + /* 1 if we should add -lpthread to the command-line. + FIXME: the default should be a configuration choice. */ int need_pthread = 1; /* True if we saw -static. */ @@ -775,6 +779,16 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, #endif break; + case OPT_static_libgm2: + shared_libgm2 = false; +#ifdef HAVE_LD_STATIC_DYNAMIC + /* Remove -static-libgm2 from the command only if target supports + LD_STATIC_DYNAMIC. When not supported, it is left in so that a + back-end target can use outfile substitution. */ + args[i] |= SKIPOPT; +#endif + break; + case OPT_stdlib_: which_library = (stdcxxlib_kind) decoded_options[i].value; break; @@ -875,8 +889,16 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, if (linking) { +#ifdef HAVE_LD_STATIC_DYNAMIC + if (allow_libraries && !shared_libgm2) + append_option (OPT_Wl_, LD_STATIC_OPTION, 1); +#endif if (allow_libraries) add_default_archives (libpath, libraries); +#ifdef HAVE_LD_STATIC_DYNAMIC + if (allow_libraries && !shared_libgm2) + append_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1); +#endif /* Add `-lstdc++' if we haven't already done so. */ #ifdef HAVE_LD_STATIC_DYNAMIC if (library > 1 && !static_link) diff --git a/gcc/m2/lang.opt b/gcc/m2/lang.opt index 83a5ce7eb30..43b1bbcb2af 100644 --- a/gcc/m2/lang.opt +++ b/gcc/m2/lang.opt @@ -349,4 +349,8 @@ x Modula-2 Joined specify the language from the compiler driver +static-libgm2 +Driver +Link the standard Modula-2 libraries statically in the compilation. + ; This comment is to ensure we retain the blank line above. — ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] modula-2, driver: Implement handling for -static-libgm2. 2023-01-04 19:41 ` Iain Sandoe @ 2023-01-05 3:07 ` Gaius Mulley 0 siblings, 0 replies; 4+ messages in thread From: Gaius Mulley @ 2023-01-05 3:07 UTC (permalink / raw) To: Iain Sandoe; +Cc: GCC Patches Iain Sandoe <iain@sandoe.co.uk> writes: > Hi Gaius, > >> On 4 Jan 2023, at 12:11, Gaius Mulley <gaiusmod2@gmail.com> wrote: >> >> Iain Sandoe <iains.gcc@gmail.com> writes: >> >>> tested on x86_64-linux-gnu, x86_64,aarch64-darwin21, > >> >> yes LGTM - it was unimplemented - thanks! > > My apologies, when I came to apply this I realised that I posted the wrong > version of the patch - omitting the documentation changes. > > Here is the version with (albeit basic) documentation. > Still OK for master? > Iain Hi Iain, yes LGTM thanks, Gaius > [PATCH] modula-2, driver: Implement handling for -static-libgm2. > > This was unimplemented so far. > > gcc/ChangeLog: > > * common.opt: Add -static-libgm2. > * config/darwin.h (LINK_SPEC): Handle static-libgm2. > * doc/gm2.texi: Document static-libgm2. > * gcc.cc (driver_handle_option): Allow static-libgm2. > > gcc/m2/ChangeLog: > > * gm2spec.cc (lang_specific_driver): Handle static-libgm2. > * lang.opt: Add static-libgm2. > --- > gcc/common.opt | 4 ++++ > gcc/config/darwin.h | 7 ++++++- > gcc/doc/gm2.texi | 4 ++++ > gcc/gcc.cc | 12 +++++++----- > gcc/m2/gm2spec.cc | 24 +++++++++++++++++++++++- > gcc/m2/lang.opt | 4 ++++ > 6 files changed, 48 insertions(+), 7 deletions(-) > > diff --git a/gcc/common.opt b/gcc/common.opt > index 97a78030228..d0371aec8db 100644 > --- a/gcc/common.opt > +++ b/gcc/common.opt > @@ -3622,6 +3622,10 @@ static-libgfortran > Driver > ; Documented for Fortran, but always accepted by driver. > > +static-libgm2 > +Driver > +; Documented for Modula-2, but always accepted by driver. > + > static-libphobos > Driver > ; Documented for D, but always accepted by driver. > diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h > index efe3187cd96..e6f76e598e6 100644 > --- a/gcc/config/darwin.h > +++ b/gcc/config/darwin.h > @@ -447,7 +447,12 @@ extern GTY(()) int darwin_ms_struct; > %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\ > %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\ > %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\ > - %{force_cpusubtype_ALL:-arch %(darwin_arch)} \ > + %{static|static-libgm2:%:replace-outfile(-lm2pim libm2pim.a%s)}\ > + %{static|static-libgm2:%:replace-outfile(-lm2iso libm2iso.a%s)}\ > + %{static|static-libgm2:%:replace-outfile(-lm2min libm2min.a%s)}\ > + %{static|static-libgm2:%:replace-outfile(-lm2log libm2log.a%s)}\ > + %{static|static-libgm2:%:replace-outfile(-lm2cor libm2cor.a%s)}\ > + %{force_cpusubtype_ALL:-arch %(darwin_arch)} \ > %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\ > LINK_SYSROOT_SPEC \ > "%{mmacosx-version-min=*:-macosx_version_min %*} \ > diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi > index 513fdd3ec7f..18cb798c6cd 100644 > --- a/gcc/doc/gm2.texi > +++ b/gcc/doc/gm2.texi > @@ -573,6 +573,10 @@ the they provide the base modules which all other dialects utilize. > The option @samp{-fno-libs=-} disables the @samp{gm2} driver from > modifying the search and library paths. > > +@item -static-libgm2 > +On systems that provide the m2 runtimes as both shared and static libraries, > +this option forces the use of the static version. > + > @c flocation= > @c Modula-2 Joined > @c set all location values to a specific value (internal switch) > diff --git a/gcc/gcc.cc b/gcc/gcc.cc > index 91313a8516d..d629ca5e424 100644 > --- a/gcc/gcc.cc > +++ b/gcc/gcc.cc > @@ -4540,12 +4540,14 @@ driver_handle_option (struct gcc_options *opts, > case OPT_static_libgfortran: > case OPT_static_libquadmath: > case OPT_static_libphobos: > + case OPT_static_libgm2: > case OPT_static_libstdc__: > - /* These are always valid, since gcc.cc itself understands the > - first two, gfortranspec.cc understands -static-libgfortran, > - d-spec.cc understands -static-libphobos, g++spec.cc > - understands -static-libstdc++ and libgfortran.spec handles > - -static-libquadmath. */ > + /* These are always valid; gcc.cc itself understands the first two > + gfortranspec.cc understands -static-libgfortran, > + libgfortran.spec handles -static-libquadmath, > + d-spec.cc understands -static-libphobos, > + gm2spec.cc understands -static-libgm2, > + and g++spec.cc understands -static-libstdc++. */ > validated = true; > break; > > diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc > index b9a5c4e79bb..583723da416 100644 > --- a/gcc/m2/gm2spec.cc > +++ b/gcc/m2/gm2spec.cc > @@ -586,6 +586,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, > /* Should the driver perform a link? */ > bool linking = true; > > + /* Should the driver link the shared gm2 libs? */ > + bool shared_libgm2 = true; > + > /* "-lm" or "-lmath" if it appears on the command line. */ > const struct cl_decoded_option *saw_math = NULL; > > @@ -595,7 +598,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, > /* By default, we throw on the math library if we have one. */ > int need_math = (MATH_LIBRARY[0] != '\0'); > > - /* 1 if we should add -lpthread to the command-line. */ > + /* 1 if we should add -lpthread to the command-line. > + FIXME: the default should be a configuration choice. */ > int need_pthread = 1; > > /* True if we saw -static. */ > @@ -775,6 +779,16 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, > #endif > break; > > + case OPT_static_libgm2: > + shared_libgm2 = false; > +#ifdef HAVE_LD_STATIC_DYNAMIC > + /* Remove -static-libgm2 from the command only if target supports > + LD_STATIC_DYNAMIC. When not supported, it is left in so that a > + back-end target can use outfile substitution. */ > + args[i] |= SKIPOPT; > +#endif > + break; > + > case OPT_stdlib_: > which_library = (stdcxxlib_kind) decoded_options[i].value; > break; > @@ -875,8 +889,16 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, > > if (linking) > { > +#ifdef HAVE_LD_STATIC_DYNAMIC > + if (allow_libraries && !shared_libgm2) > + append_option (OPT_Wl_, LD_STATIC_OPTION, 1); > +#endif > if (allow_libraries) > add_default_archives (libpath, libraries); > +#ifdef HAVE_LD_STATIC_DYNAMIC > + if (allow_libraries && !shared_libgm2) > + append_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1); > +#endif > /* Add `-lstdc++' if we haven't already done so. */ > #ifdef HAVE_LD_STATIC_DYNAMIC > if (library > 1 && !static_link) > diff --git a/gcc/m2/lang.opt b/gcc/m2/lang.opt > index 83a5ce7eb30..43b1bbcb2af 100644 > --- a/gcc/m2/lang.opt > +++ b/gcc/m2/lang.opt > @@ -349,4 +349,8 @@ x > Modula-2 Joined > specify the language from the compiler driver > > +static-libgm2 > +Driver > +Link the standard Modula-2 libraries statically in the compilation. > + > ; This comment is to ensure we retain the blank line above. > — ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-05 3:07 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-01-02 10:38 [PATCH] modula-2, driver: Implement handling for -static-libgm2 Iain Sandoe 2023-01-04 12:11 ` Gaius Mulley 2023-01-04 19:41 ` Iain Sandoe 2023-01-05 3:07 ` Gaius Mulley
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).