Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 1 | From: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 2 | Subject: [PATCH 3/5] gcc: Add --nostdlib++ option |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 3 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 4 | [gcc-runtime builds libstdc++ separately from gcc-cross-*. Its configure tests using g++ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | will not run correctly since by default the linker will try to link against libstdc++ |
| 6 | which shouldn't exist yet. We need an option to disable -lstdc++ |
| 7 | option whilst leaving -lc, -lgcc and other automatic library dependencies added by gcc |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 8 | driver. This patch adds such an option which only disables the -lstdc++.] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 9 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 10 | [A "standard" gcc build uses xgcc and hence avoids this. We should ask upstream how to |
| 11 | do this officially, the likely answer is don't build libstdc++ separately.] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 12 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 13 | OpenEmbedded/Yocto Project builds libgcc and the other gcc runtime libraries |
| 14 | separately from the compiler and slightly differently to the standard gcc build. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 15 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 16 | In general this works well but in trying to build them separately we run into |
| 17 | an issue since we're using our gcc, not xgcc and there is no way to tell configure |
| 18 | to use libgcc but not look for libstdc++. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 19 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 20 | This adds such an option allowing such configurations to work. |
| 21 | |
| 22 | 2021-10-26 Richard Purdie <richard.purdie@linuxfoundation.org> |
| 23 | |
| 24 | gcc/c-family/ChangeLog: |
| 25 | |
| 26 | * c.opt: Add --nostdlib++ option |
| 27 | |
| 28 | gcc/cp/ChangeLog: |
| 29 | |
| 30 | * g++spec.c (lang_specific_driver): Add --nostdlib++ option |
| 31 | |
| 32 | gcc/ChangeLog: |
| 33 | |
| 34 | * doc/invoke.texi: Document --nostdlib++ option |
| 35 | * gcc.c: Add --nostdlib++ option |
| 36 | |
| 37 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 38 | |
| 39 | Upstream-Status: Submitted [https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582724.html] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 40 | --- |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 41 | gcc/c-family/c.opt | 4 ++++ |
| 42 | gcc/cp/g++spec.c | 1 + |
| 43 | gcc/doc/invoke.texi | 8 +++++++- |
| 44 | gcc/gcc.c | 1 + |
| 45 | 4 files changed, 13 insertions(+), 1 deletion(-) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 46 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 47 | Index: gcc-11.2.0/gcc/c-family/c.opt |
| 48 | =================================================================== |
| 49 | --- gcc-11.2.0.orig/gcc/c-family/c.opt |
| 50 | +++ gcc-11.2.0/gcc/c-family/c.opt |
| 51 | @@ -2153,6 +2153,10 @@ nostdinc++ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 52 | C++ ObjC++ |
| 53 | Do not search standard system include directories for C++. |
| 54 | |
| 55 | +nostdlib++ |
| 56 | +Driver |
| 57 | +Do not link standard C++ runtime library |
| 58 | + |
| 59 | o |
| 60 | C ObjC C++ ObjC++ Joined Separate |
| 61 | ; Documented in common.opt |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 62 | Index: gcc-11.2.0/gcc/cp/g++spec.c |
| 63 | =================================================================== |
| 64 | --- gcc-11.2.0.orig/gcc/cp/g++spec.c |
| 65 | +++ gcc-11.2.0/gcc/cp/g++spec.c |
| 66 | @@ -159,6 +159,7 @@ lang_specific_driver (struct cl_decoded_ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 67 | switch (decoded_options[i].opt_index) |
| 68 | { |
| 69 | case OPT_nostdlib: |
| 70 | + case OPT_nostdlib__: |
| 71 | case OPT_nodefaultlibs: |
| 72 | library = -1; |
| 73 | break; |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 74 | Index: gcc-11.2.0/gcc/doc/invoke.texi |
| 75 | =================================================================== |
| 76 | --- gcc-11.2.0.orig/gcc/doc/invoke.texi |
| 77 | +++ gcc-11.2.0/gcc/doc/invoke.texi |
| 78 | @@ -239,6 +239,7 @@ in the following sections. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 79 | -fno-weak -nostdinc++ @gol |
| 80 | -fvisibility-inlines-hidden @gol |
| 81 | -fvisibility-ms-compat @gol |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 82 | +-nostdlib++ @gol |
| 83 | -fext-numeric-literals @gol |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 84 | -flang-info-include-translate@r{[}=@var{header}@r{]} @gol |
| 85 | -flang-info-include-translate-not @gol |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 86 | @@ -632,7 +633,7 @@ Objective-C and Objective-C++ Dialects}. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 87 | -pie -pthread -r -rdynamic @gol |
| 88 | -s -static -static-pie -static-libgcc -static-libstdc++ @gol |
| 89 | -static-libasan -static-libtsan -static-liblsan -static-libubsan @gol |
| 90 | --shared -shared-libgcc -symbolic @gol |
| 91 | +-shared -shared-libgcc -symbolic -nostdlib++ @gol |
| 92 | -T @var{script} -Wl,@var{option} -Xlinker @var{option} @gol |
| 93 | -u @var{symbol} -z @var{keyword}} |
| 94 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 95 | @@ -15721,6 +15722,11 @@ Specify that the program entry point is |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 96 | interpreted by the linker; the GNU linker accepts either a symbol name |
| 97 | or an address. |
| 98 | |
| 99 | +@item -nostdlib++ |
| 100 | +@opindex nostdlib++ |
| 101 | +Do not use the standard system C++ runtime libraries when linking. |
| 102 | +Only the libraries you specify will be passed to the linker. |
| 103 | + |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 104 | @item -pie |
| 105 | @opindex pie |
| 106 | Produce a dynamically linked position independent executable on targets |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 107 | Index: gcc-11.2.0/gcc/gcc.c |
| 108 | =================================================================== |
| 109 | --- gcc-11.2.0.orig/gcc/gcc.c |
| 110 | +++ gcc-11.2.0/gcc/gcc.c |
| 111 | @@ -1162,6 +1162,7 @@ proper position among the other output f |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 112 | %(mflib) " STACK_SPLIT_SPEC "\ |
| 113 | %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \ |
| 114 | %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\ |
| 115 | + %{!nostdlib++:}\ |
| 116 | %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}" |
| 117 | #endif |
| 118 | |