Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 1 | From e7e504f4a90cfa395e7f8ee779f8c3ed687802ca Mon Sep 17 00:00:00 2001 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 29 Mar 2013 09:12:56 +0400 |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 4 | Subject: [PATCH 05/36] optional libstdc |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [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 |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 28 | index 916cc67b453..41619fa591c 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 29 | --- a/gcc/c-family/c.opt |
| 30 | +++ b/gcc/c-family/c.opt |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 31 | @@ -1952,6 +1952,10 @@ nostdinc++ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [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 |
| 43 | index 6c4574a837d..0e2657f00ee 100644 |
| 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 |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 55 | index 09414d8cc05..a43969bc9f0 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 56 | --- a/gcc/doc/invoke.texi |
| 57 | +++ b/gcc/doc/invoke.texi |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 58 | @@ -228,6 +228,9 @@ in the following sections. |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [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 |
| 66 | -Wabi=@var{n} -Wabi-tag -Wconversion-null -Wctor-dtor-privacy @gol |
| 67 | -Wdelete-non-virtual-dtor -Wdeprecated-copy -Wdeprecated-copy-dtor @gol |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 68 | @@ -538,7 +541,7 @@ Objective-C and Objective-C++ Dialects}. |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [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 | |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 77 | @@ -13312,6 +13315,33 @@ Specify that the program entry point is @var{entry}. The argument is |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [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 |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 112 | index a2601a6bb06..cd6c6fc95db 100644 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 113 | --- a/gcc/gcc.c |
| 114 | +++ b/gcc/gcc.c |
| 115 | @@ -1052,6 +1052,7 @@ proper position among the other output files. */ |
| 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 | |
| 123 | -- |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 124 | 2.22.1 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 125 | |