blob: b856c5dea36784eaf98dd706444522a918f74676 [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From: Richard Purdie <richard.purdie@linuxfoundation.org>
2Subject: [PATCH 3/5] gcc: Add --nostdlib++ option
Andrew Geissler82c905d2020-04-13 13:39:40 -05003
Andrew Geisslereff27472021-10-29 15:35:00 -05004[gcc-runtime builds libstdc++ separately from gcc-cross-*. Its configure tests using g++
Andrew Geissler82c905d2020-04-13 13:39:40 -05005will not run correctly since by default the linker will try to link against libstdc++
6which shouldn't exist yet. We need an option to disable -lstdc++
7option whilst leaving -lc, -lgcc and other automatic library dependencies added by gcc
Andrew Geisslereff27472021-10-29 15:35:00 -05008driver. This patch adds such an option which only disables the -lstdc++.]
Andrew Geissler82c905d2020-04-13 13:39:40 -05009
Andrew Geisslereff27472021-10-29 15:35:00 -050010[A "standard" gcc build uses xgcc and hence avoids this. We should ask upstream how to
11do this officially, the likely answer is don't build libstdc++ separately.]
Andrew Geissler82c905d2020-04-13 13:39:40 -050012
Andrew Geisslereff27472021-10-29 15:35:00 -050013OpenEmbedded/Yocto Project builds libgcc and the other gcc runtime libraries
14separately from the compiler and slightly differently to the standard gcc build.
Andrew Geissler82c905d2020-04-13 13:39:40 -050015
Andrew Geisslereff27472021-10-29 15:35:00 -050016In general this works well but in trying to build them separately we run into
17an issue since we're using our gcc, not xgcc and there is no way to tell configure
18to use libgcc but not look for libstdc++.
Andrew Geissler82c905d2020-04-13 13:39:40 -050019
Andrew Geisslereff27472021-10-29 15:35:00 -050020This adds such an option allowing such configurations to work.
21
222021-10-26 Richard Purdie <richard.purdie@linuxfoundation.org>
23
24gcc/c-family/ChangeLog:
25
26 * c.opt: Add --nostdlib++ option
27
28gcc/cp/ChangeLog:
29
30 * g++spec.c (lang_specific_driver): Add --nostdlib++ option
31
32gcc/ChangeLog:
33
34 * doc/invoke.texi: Document --nostdlib++ option
35 * gcc.c: Add --nostdlib++ option
36
37Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
38
39Upstream-Status: Submitted [https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582724.html]
Andrew Geissler82c905d2020-04-13 13:39:40 -050040---
Andrew Geisslereff27472021-10-29 15:35:00 -050041 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 Geissler82c905d2020-04-13 13:39:40 -050046
Andrew Geisslereff27472021-10-29 15:35:00 -050047Index: 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 Geissler82c905d2020-04-13 13:39:40 -050052 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 Geisslereff27472021-10-29 15:35:00 -050062Index: 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 Geissler82c905d2020-04-13 13:39:40 -050067 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 Geisslereff27472021-10-29 15:35:00 -050074Index: 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 Geissler82c905d2020-04-13 13:39:40 -050079 -fno-weak -nostdinc++ @gol
80 -fvisibility-inlines-hidden @gol
81 -fvisibility-ms-compat @gol
Andrew Geissler82c905d2020-04-13 13:39:40 -050082+-nostdlib++ @gol
83 -fext-numeric-literals @gol
Andrew Geisslerc926e172021-05-07 16:11:35 -050084 -flang-info-include-translate@r{[}=@var{header}@r{]} @gol
85 -flang-info-include-translate-not @gol
Andrew Geisslereff27472021-10-29 15:35:00 -050086@@ -632,7 +633,7 @@ Objective-C and Objective-C++ Dialects}.
Andrew Geissler82c905d2020-04-13 13:39:40 -050087 -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 Geisslereff27472021-10-29 15:35:00 -050095@@ -15721,6 +15722,11 @@ Specify that the program entry point is
Andrew Geissler82c905d2020-04-13 13:39:40 -050096 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 Geissler82c905d2020-04-13 13:39:40 -0500104 @item -pie
105 @opindex pie
106 Produce a dynamically linked position independent executable on targets
Andrew Geisslereff27472021-10-29 15:35:00 -0500107Index: 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 Geissler82c905d2020-04-13 13:39:40 -0500112 %(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