blob: 4020c9e3cf698c34bc6f83cb5d32fb1c02e9b4fc [file] [log] [blame]
Andrew Geisslerc182c622020-05-15 14:13:32 -05001From 6ddfb0bfcd1eea71acd37ab06f7a4510b9f1d12b Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 29 Mar 2013 09:12:56 +0400
Andrew Geisslerc182c622020-05-15 14:13:32 -05004Subject: [PATCH] optional libstdc
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6gcc-runtime builds libstdc++ separately from gcc-cross-*. Its configure tests using g++
7will not run correctly since by default the linker will try to link against libstdc++
8which shouldn't exist yet. We need an option to disable -lstdc++
9option whilst leaving -lc, -lgcc and other automatic library dependencies added by gcc
10driver. This patch adds such an option which only disables the -lstdc++.
11
12A "standard" gcc build uses xgcc and hence avoids this. We should ask upstream how to
13do this officially, the likely answer is don't build libstdc++ separately.
14
15RP 29/6/10
16
17Signed-off-by: Khem Raj <raj.khem@gmail.com>
18
19Upstream-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
27diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
Andrew Geisslerc182c622020-05-15 14:13:32 -050028index c49da99d395..35f712e2c84 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050029--- a/gcc/c-family/c.opt
30+++ b/gcc/c-family/c.opt
Andrew Geisslerc182c622020-05-15 14:13:32 -050031@@ -2025,6 +2025,10 @@ nostdinc++
Andrew Geissler82c905d2020-04-13 13:39:40 -050032 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
42diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c
Andrew Geisslerc182c622020-05-15 14:13:32 -050043index 0ab63bcd211..7b081e9e4f0 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050044--- 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;
54diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
Andrew Geisslerc182c622020-05-15 14:13:32 -050055index f12d8d12150..cf6cb428e7d 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050056--- a/gcc/doc/invoke.texi
57+++ b/gcc/doc/invoke.texi
Andrew Geisslerc182c622020-05-15 14:13:32 -050058@@ -230,6 +230,9 @@ in the following sections.
Andrew Geissler82c905d2020-04-13 13:39:40 -050059 -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 Geisslerc182c622020-05-15 14:13:32 -050066 -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 Geissler82c905d2020-04-13 13:39:40 -050069 -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 Geisslerc182c622020-05-15 14:13:32 -050077@@ -14407,6 +14410,33 @@ Specify that the program entry point is @var{entry}. The argument is
Andrew Geissler82c905d2020-04-13 13:39:40 -050078 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
111diff --git a/gcc/gcc.c b/gcc/gcc.c
Andrew Geisslerc182c622020-05-15 14:13:32 -0500112index b2200c5185a..f8be58ce0a6 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500113--- a/gcc/gcc.c
114+++ b/gcc/gcc.c
Andrew Geisslerc182c622020-05-15 14:13:32 -0500115@@ -1051,6 +1051,7 @@ proper position among the other output files. */
Andrew Geissler82c905d2020-04-13 13:39:40 -0500116 %(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