Re: [PATCH v2] C++ : Add the -stdlib= option.
Hi Iain, could you add a note about this change to the gcc-11/changes.html page? There are probably some people who would be interested in this who could use a note about it. Thanks On Tue, Dec 22, 2020 at 3:53 PM Jason Merrill via Gcc-patches wrote: > > On 12/22/20 3:39 PM, Iain Sandoe wrote: > > Hi Jason, > > > > Jason Merrill wrote: > > > >> On 11/11/20 3:58 PM, Iain Sandoe wrote: > > > >>> This option allows the user to specify alternate C++ runtime libraries, > >>> for example when a platform uses libc++ as the installed C++ runtime. > >>> It is the same spelling as a clang option that allows that to use > >>> libstdc++. > >>> I have had this patch for some time now (more than a year) on Darwin > >>> branches. > >>> > > > >>> + /* Which standard library to link. > >>> + 1 = libstdc++ > >>> + 2 = libc++. */ > >>> + int which_library = 1; > >> > >> Even if this variable is an int, let's introduce an enum for comparing it > >> to specific values. > > > > done - it is also noted that it must track the enum in the opt file. > > > >>> @@ -264,6 +293,8 @@ lang_specific_driver (struct cl_decoded_option > >>> **in_decoded_options, > >>> /* Add one for shared_libgcc or extra static library. */ > >>> num_args = argc + added + need_math + (library > 0) * 4 + 1; > >>> + if (which_library > 1 && LIBCXXABI != NULL) > >>> +num_args += 4; > >> > >> Why does libc++ need more args than libstdc++? Please add a comment. > > > > done (JFTR, it’s because libc++ doesn’t include the abi library for most > > platforms, so that also has to be > > appended to the link line). > > > >>> +#ifdef GPLUSPLUS_LIBCXX_INCLUDE_DIR > >>> +/* Pick up libc++ include files, if we have -stdlib=libc++. */ > >>> +{ GPLUSPLUS_LIBCXX_INCLUDE_DIR, "G++", 2, 1, > >> > >> If you're going to give cplusplus a non-boolean value, the comment in > >> cppdefault.h needs to reflect that. > > > > done. > > > > (re-)tested on x86_64-darwin{11,16,17,19, 20} with the installed libc++ and > > x86_64-linux-gnu with an > > LLVM-9 build. Bootstrapped and smoke-tested for libc++ (regular testing > > for libstdc++). > > > > OK for master now? > > OK. > > > thanks > > Iain > > > > revised patch > > > > > > This option allows the user to specifiy alternate C++ runtime libraries, > > for example when a platform uses libc++ as the installed C++ runtime. > > > > We introduce the command line option: -stdlib= which is the user-facing > > mechanism to select the C++ runtime to be used when compiling and linking > > code. This is the same option spelling as that used by clang to allow the > > use of libstdc++. > > > > The availability (and thus function) of the option are a configure-time > > choice using the configuration control: > > --with-gxx-libcxx-include-dir= > > > > Specification of the path for the libc++ headers, enables the -stdlib= > > option (using the path as given), default values are set when the path > > is unconfigured. > > > > If --with-gxx-libcxx-include-dir is given together with --with-sysroot=, > > then we test to see if the include path starts with the sysroot and, if so, > > record the sysroot-relative component as the local path. At runtime, we > > prepend the sysroot that is actually active. > > > > At link time, we use the C++ runtime in force and (if that is libc++) also > > append the libc++abi ABI library. As for other cases, if a target sets the > > name pointer for the ABI library to NULL the G++ driver will omit it from > > the link line. > > > > gcc/ChangeLog: > > > > * configure.ac: Add gxx-libcxx-include-dir handled > > in the same way as the regular cxx header directory. > > * Makefile.in: Regenerated. > > * config.in: Likewise. > > * configure: Likewise. > > * cppdefault.c: Pick up libc++ headers if the option > > is enabled. > > * cppdefault.h (struct default_include): Amend comments > > to reflect the extended use of the cplusplus field. > > * incpath.c (add_standard_paths): Allow for multiple > > c++ header include path variants. > > * doc/invoke.texi: Document the -stdlib= option. > > > > gcc/c-family/ChangeLog: > > > > * c.opt: Add -stdlib= option and enumerations for > > libstdc++ and libc++. > > > > gcc/cp/ChangeLog: > > > > * g++spec.c (LIBCXX, LIBCXX_PROFILE, LIBCXX_STATIC): New. > > (LIBCXXABI, LIBCXXABI_PROFILE, LIBCXXABI_STATIC): New. > > (enum stdcxxlib_kind): New. > > (lang_specific_driver): Allow selection amongst multiple > > c++ runtime libraries. > > --- > > gcc/Makefile.in | 6 > > gcc/c-family/c.opt | 14 + > > gcc/config.in | 6 > > gcc/configure | 57 -- > > gcc/configure.ac| 44 +++ > > gcc/cp/g++spec.c| 74 - > > gcc/cppdefault.c| 5 +++ > > gcc/cppdefault.h| 7 - > >
Re: [PATCH v2] C++ : Add the -stdlib= option.
On 12/22/20 3:39 PM, Iain Sandoe wrote: Hi Jason, Jason Merrill wrote: On 11/11/20 3:58 PM, Iain Sandoe wrote: This option allows the user to specify alternate C++ runtime libraries, for example when a platform uses libc++ as the installed C++ runtime. It is the same spelling as a clang option that allows that to use libstdc++. I have had this patch for some time now (more than a year) on Darwin branches. + /* Which standard library to link. + 1 = libstdc++ + 2 = libc++. */ + int which_library = 1; Even if this variable is an int, let's introduce an enum for comparing it to specific values. done - it is also noted that it must track the enum in the opt file. @@ -264,6 +293,8 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, /* Add one for shared_libgcc or extra static library. */ num_args = argc + added + need_math + (library > 0) * 4 + 1; + if (which_library > 1 && LIBCXXABI != NULL) +num_args += 4; Why does libc++ need more args than libstdc++? Please add a comment. done (JFTR, it’s because libc++ doesn’t include the abi library for most platforms, so that also has to be appended to the link line). +#ifdef GPLUSPLUS_LIBCXX_INCLUDE_DIR +/* Pick up libc++ include files, if we have -stdlib=libc++. */ +{ GPLUSPLUS_LIBCXX_INCLUDE_DIR, "G++", 2, 1, If you're going to give cplusplus a non-boolean value, the comment in cppdefault.h needs to reflect that. done. (re-)tested on x86_64-darwin{11,16,17,19, 20} with the installed libc++ and x86_64-linux-gnu with an LLVM-9 build. Bootstrapped and smoke-tested for libc++ (regular testing for libstdc++). OK for master now? OK. thanks Iain revised patch This option allows the user to specifiy alternate C++ runtime libraries, for example when a platform uses libc++ as the installed C++ runtime. We introduce the command line option: -stdlib= which is the user-facing mechanism to select the C++ runtime to be used when compiling and linking code. This is the same option spelling as that used by clang to allow the use of libstdc++. The availability (and thus function) of the option are a configure-time choice using the configuration control: --with-gxx-libcxx-include-dir= Specification of the path for the libc++ headers, enables the -stdlib= option (using the path as given), default values are set when the path is unconfigured. If --with-gxx-libcxx-include-dir is given together with --with-sysroot=, then we test to see if the include path starts with the sysroot and, if so, record the sysroot-relative component as the local path. At runtime, we prepend the sysroot that is actually active. At link time, we use the C++ runtime in force and (if that is libc++) also append the libc++abi ABI library. As for other cases, if a target sets the name pointer for the ABI library to NULL the G++ driver will omit it from the link line. gcc/ChangeLog: * configure.ac: Add gxx-libcxx-include-dir handled in the same way as the regular cxx header directory. * Makefile.in: Regenerated. * config.in: Likewise. * configure: Likewise. * cppdefault.c: Pick up libc++ headers if the option is enabled. * cppdefault.h (struct default_include): Amend comments to reflect the extended use of the cplusplus field. * incpath.c (add_standard_paths): Allow for multiple c++ header include path variants. * doc/invoke.texi: Document the -stdlib= option. gcc/c-family/ChangeLog: * c.opt: Add -stdlib= option and enumerations for libstdc++ and libc++. gcc/cp/ChangeLog: * g++spec.c (LIBCXX, LIBCXX_PROFILE, LIBCXX_STATIC): New. (LIBCXXABI, LIBCXXABI_PROFILE, LIBCXXABI_STATIC): New. (enum stdcxxlib_kind): New. (lang_specific_driver): Allow selection amongst multiple c++ runtime libraries. --- gcc/Makefile.in | 6 gcc/c-family/c.opt | 14 + gcc/config.in | 6 gcc/configure | 57 -- gcc/configure.ac| 44 +++ gcc/cp/g++spec.c| 74 - gcc/cppdefault.c| 5 +++ gcc/cppdefault.h| 7 - gcc/doc/invoke.texi | 10 ++ gcc/incpath.c | 6 ++-- 10 files changed, 216 insertions(+), 13 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 178e4eaa513..6847022f108 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -679,6 +679,9 @@ build_tooldir = $(exec_prefix)/$(target_noncanonical) # Directory in which the compiler finds target-independent g++ includes. gcc_gxx_include_dir = @gcc_gxx_include_dir@ gcc_gxx_include_dir_add_sysroot = @gcc_gxx_include_dir_add_sysroot@ +# Directory in which the compiler finds libc++ includes. +gcc_gxx_libcxx_include_dir = @gcc_gxx_libcxx_include_dir@ +gcc_gxx_libcxx_include_dir_add_sysroot = @gcc_gxx_libcxx_include_dir_add_sysroot@ # Directory
[PATCH v2] C++ : Add the -stdlib= option.
Hi Jason, Jason Merrill wrote: > On 11/11/20 3:58 PM, Iain Sandoe wrote: >> This option allows the user to specify alternate C++ runtime libraries, >> for example when a platform uses libc++ as the installed C++ runtime. >> It is the same spelling as a clang option that allows that to use libstdc++. >> I have had this patch for some time now (more than a year) on Darwin >> branches. >> >> + /* Which standard library to link. >> + 1 = libstdc++ >> + 2 = libc++. */ >> + int which_library = 1; > > Even if this variable is an int, let's introduce an enum for comparing it to > specific values. done - it is also noted that it must track the enum in the opt file. >> @@ -264,6 +293,8 @@ lang_specific_driver (struct cl_decoded_option >> **in_decoded_options, >> /* Add one for shared_libgcc or extra static library. */ >> num_args = argc + added + need_math + (library > 0) * 4 + 1; >> + if (which_library > 1 && LIBCXXABI != NULL) >> +num_args += 4; > > Why does libc++ need more args than libstdc++? Please add a comment. done (JFTR, it’s because libc++ doesn’t include the abi library for most platforms, so that also has to be appended to the link line). >> +#ifdef GPLUSPLUS_LIBCXX_INCLUDE_DIR >> +/* Pick up libc++ include files, if we have -stdlib=libc++. */ >> +{ GPLUSPLUS_LIBCXX_INCLUDE_DIR, "G++", 2, 1, > > If you're going to give cplusplus a non-boolean value, the comment in > cppdefault.h needs to reflect that. done. (re-)tested on x86_64-darwin{11,16,17,19, 20} with the installed libc++ and x86_64-linux-gnu with an LLVM-9 build. Bootstrapped and smoke-tested for libc++ (regular testing for libstdc++). OK for master now? thanks Iain revised patch This option allows the user to specifiy alternate C++ runtime libraries, for example when a platform uses libc++ as the installed C++ runtime. We introduce the command line option: -stdlib= which is the user-facing mechanism to select the C++ runtime to be used when compiling and linking code. This is the same option spelling as that used by clang to allow the use of libstdc++. The availability (and thus function) of the option are a configure-time choice using the configuration control: --with-gxx-libcxx-include-dir= Specification of the path for the libc++ headers, enables the -stdlib= option (using the path as given), default values are set when the path is unconfigured. If --with-gxx-libcxx-include-dir is given together with --with-sysroot=, then we test to see if the include path starts with the sysroot and, if so, record the sysroot-relative component as the local path. At runtime, we prepend the sysroot that is actually active. At link time, we use the C++ runtime in force and (if that is libc++) also append the libc++abi ABI library. As for other cases, if a target sets the name pointer for the ABI library to NULL the G++ driver will omit it from the link line. gcc/ChangeLog: * configure.ac: Add gxx-libcxx-include-dir handled in the same way as the regular cxx header directory. * Makefile.in: Regenerated. * config.in: Likewise. * configure: Likewise. * cppdefault.c: Pick up libc++ headers if the option is enabled. * cppdefault.h (struct default_include): Amend comments to reflect the extended use of the cplusplus field. * incpath.c (add_standard_paths): Allow for multiple c++ header include path variants. * doc/invoke.texi: Document the -stdlib= option. gcc/c-family/ChangeLog: * c.opt: Add -stdlib= option and enumerations for libstdc++ and libc++. gcc/cp/ChangeLog: * g++spec.c (LIBCXX, LIBCXX_PROFILE, LIBCXX_STATIC): New. (LIBCXXABI, LIBCXXABI_PROFILE, LIBCXXABI_STATIC): New. (enum stdcxxlib_kind): New. (lang_specific_driver): Allow selection amongst multiple c++ runtime libraries. --- gcc/Makefile.in | 6 gcc/c-family/c.opt | 14 + gcc/config.in | 6 gcc/configure | 57 -- gcc/configure.ac| 44 +++ gcc/cp/g++spec.c| 74 - gcc/cppdefault.c| 5 +++ gcc/cppdefault.h| 7 - gcc/doc/invoke.texi | 10 ++ gcc/incpath.c | 6 ++-- 10 files changed, 216 insertions(+), 13 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 178e4eaa513..6847022f108 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -679,6 +679,9 @@ build_tooldir = $(exec_prefix)/$(target_noncanonical) # Directory in which the compiler finds target-independent g++ includes. gcc_gxx_include_dir = @gcc_gxx_include_dir@ gcc_gxx_include_dir_add_sysroot = @gcc_gxx_include_dir_add_sysroot@ +# Directory in which the compiler finds libc++ includes. +gcc_gxx_libcxx_include_dir = @gcc_gxx_libcxx_include_dir@ +gcc_gxx_libcxx_include_dir_add_sysroot = @gcc_gxx_libcxx_include_dir_add_sysroot@ # Directory to