0005-optional-libstdc.patch 4.8 KB

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