Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 1 | From 6ddfb0bfcd1eea71acd37ab06f7a4510b9f1d12b Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 29 Mar 2013 09:12:56 +0400 |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 4 | Subject: [PATCH] optional libstdc |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | |
| 6 | gcc-runtime builds libstdc++ separately from gcc-cross-*. Its configure tests using g++ |
| 7 | will not run correctly since by default the linker will try to link against libstdc++ |
| 8 | which shouldn't exist yet. We need an option to disable -lstdc++ |
| 9 | option whilst leaving -lc, -lgcc and other automatic library dependencies added by gcc |
| 10 | driver. This patch adds such an option which only disables the -lstdc++. |
| 11 | |
| 12 | A "standard" gcc build uses xgcc and hence avoids this. We should ask upstream how to |
| 13 | do this officially, the likely answer is don't build libstdc++ separately. |
| 14 | |
| 15 | RP 29/6/10 |
| 16 | |
| 17 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 18 | |
| 19 | Upstream-Status: Inappropriate [embedded specific] |
| 20 | --- |
| 21 | gcc/c-family/c.opt | 4 ++++ |
| 22 | gcc/cp/g++spec.c | 1 + |
| 23 | gcc/doc/invoke.texi | 32 +++++++++++++++++++++++++++++++- |
| 24 | gcc/gcc.c | 1 + |
| 25 | 4 files changed, 37 insertions(+), 1 deletion(-) |
| 26 | |
| 27 | diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 28 | index c49da99d395..35f712e2c84 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 29 | --- a/gcc/c-family/c.opt |
| 30 | +++ b/gcc/c-family/c.opt |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 31 | @@ -2025,6 +2025,10 @@ nostdinc++ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 32 | C++ ObjC++ |
| 33 | Do not search standard system include directories for C++. |
| 34 | |
| 35 | +nostdlib++ |
| 36 | +Driver |
| 37 | +Do not link standard C++ runtime library |
| 38 | + |
| 39 | o |
| 40 | C ObjC C++ ObjC++ Joined Separate |
| 41 | ; Documented in common.opt |
| 42 | diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 43 | index 0ab63bcd211..7b081e9e4f0 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 44 | --- a/gcc/cp/g++spec.c |
| 45 | +++ b/gcc/cp/g++spec.c |
| 46 | @@ -137,6 +137,7 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, |
| 47 | switch (decoded_options[i].opt_index) |
| 48 | { |
| 49 | case OPT_nostdlib: |
| 50 | + case OPT_nostdlib__: |
| 51 | case OPT_nodefaultlibs: |
| 52 | library = -1; |
| 53 | break; |
| 54 | diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 55 | index f12d8d12150..cf6cb428e7d 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 56 | --- a/gcc/doc/invoke.texi |
| 57 | +++ b/gcc/doc/invoke.texi |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 58 | @@ -230,6 +230,9 @@ in the following sections. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 59 | -fno-weak -nostdinc++ @gol |
| 60 | -fvisibility-inlines-hidden @gol |
| 61 | -fvisibility-ms-compat @gol |
| 62 | +-fvtable-verify=@r{[}std@r{|}preinit@r{|}none@r{]} @gol |
| 63 | +-fvtv-counts -fvtv-debug @gol |
| 64 | +-nostdlib++ @gol |
| 65 | -fext-numeric-literals @gol |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 66 | -Wabi-tag -Wcatch-value -Wcatch-value=@var{n} @gol |
| 67 | -Wno-class-conversion -Wclass-memaccess @gol |
| 68 | @@ -599,7 +602,7 @@ Objective-C and Objective-C++ Dialects}. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 69 | -pie -pthread -r -rdynamic @gol |
| 70 | -s -static -static-pie -static-libgcc -static-libstdc++ @gol |
| 71 | -static-libasan -static-libtsan -static-liblsan -static-libubsan @gol |
| 72 | --shared -shared-libgcc -symbolic @gol |
| 73 | +-shared -shared-libgcc -symbolic -nostdlib++ @gol |
| 74 | -T @var{script} -Wl,@var{option} -Xlinker @var{option} @gol |
| 75 | -u @var{symbol} -z @var{keyword}} |
| 76 | |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 77 | @@ -14407,6 +14410,33 @@ Specify that the program entry point is @var{entry}. The argument is |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 78 | interpreted by the linker; the GNU linker accepts either a symbol name |
| 79 | or an address. |
| 80 | |
| 81 | +@item -nostdlib++ |
| 82 | +@opindex nostdlib++ |
| 83 | +Do not use the standard system C++ runtime libraries when linking. |
| 84 | +Only the libraries you specify will be passed to the linker. |
| 85 | + |
| 86 | +@cindex @option{-lgcc}, use with @option{-nostdlib} |
| 87 | +@cindex @option{-nostdlib} and unresolved references |
| 88 | +@cindex unresolved references and @option{-nostdlib} |
| 89 | +@cindex @option{-lgcc}, use with @option{-nodefaultlibs} |
| 90 | +@cindex @option{-nodefaultlibs} and unresolved references |
| 91 | +@cindex unresolved references and @option{-nodefaultlibs} |
| 92 | +One of the standard libraries bypassed by @option{-nostdlib} and |
| 93 | +@option{-nodefaultlibs} is @file{libgcc.a}, a library of internal subroutines |
| 94 | +which GCC uses to overcome shortcomings of particular machines, or special |
| 95 | +needs for some languages. |
| 96 | +(@xref{Interface,,Interfacing to GCC Output,gccint,GNU Compiler |
| 97 | +Collection (GCC) Internals}, |
| 98 | +for more discussion of @file{libgcc.a}.) |
| 99 | +In most cases, you need @file{libgcc.a} even when you want to avoid |
| 100 | +other standard libraries. In other words, when you specify @option{-nostdlib} |
| 101 | +or @option{-nodefaultlibs} you should usually specify @option{-lgcc} as well. |
| 102 | +This ensures that you have no unresolved references to internal GCC |
| 103 | +library subroutines. |
| 104 | +(An example of such an internal subroutine is @code{__main}, used to ensure C++ |
| 105 | +constructors are called; @pxref{Collect2,,@code{collect2}, gccint, |
| 106 | +GNU Compiler Collection (GCC) Internals}.) |
| 107 | + |
| 108 | @item -pie |
| 109 | @opindex pie |
| 110 | Produce a dynamically linked position independent executable on targets |
| 111 | diff --git a/gcc/gcc.c b/gcc/gcc.c |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 112 | index b2200c5185a..f8be58ce0a6 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 113 | --- a/gcc/gcc.c |
| 114 | +++ b/gcc/gcc.c |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 115 | @@ -1051,6 +1051,7 @@ proper position among the other output files. */ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 116 | %(mflib) " STACK_SPLIT_SPEC "\ |
| 117 | %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \ |
| 118 | %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\ |
| 119 | + %{!nostdlib++:}\ |
| 120 | %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}" |
| 121 | #endif |
| 122 | |