OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

359 lines
14 KiB

  1. From 95f5a9a866695da4e038aa4e6ccbbfd5d9cf63b7 Mon Sep 17 00:00:00 2001
  2. From: Joseph Myers <joseph@codesourcery.com>
  3. Date: Tue, 3 Jul 2012 19:14:59 +0000
  4. Subject: [PATCH] Avoid use of libgcc_s and libgcc_eh when building glibc.
  5. ---
  6. ChangeLog | 47 ++++++++++++++++++++++++++++++
  7. Makeconfig | 68 ++++++++++++++++++++++++++++++++++++++------
  8. Rules | 45 ++++++++++++++++++++++-------
  9. elf/Makefile | 6 +++-
  10. elf/static-stubs.c | 46 +++++++++++++++++++++++++++++
  11. ports/ChangeLog.arm | 7 ++++
  12. ports/sysdeps/arm/Makefile | 8 +++++
  13. 7 files changed, 206 insertions(+), 21 deletions(-)
  14. create mode 100644 elf/static-stubs.c
  15. diff --git a/Makeconfig b/Makeconfig
  16. index 417fa50..859b588 100644
  17. --- a/Makeconfig
  18. +++ b/Makeconfig
  19. @@ -415,9 +415,9 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
  20. LDFLAGS-rtld += $(hashstyle-LDFLAGS)
  21. endif
  22. -# Command for linking programs with the C library.
  23. +# Commands for linking programs with the C library.
  24. ifndef +link
  25. -+link = $(CC) -nostdlib -nostartfiles -o $@ \
  26. ++link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
  27. $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
  28. $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
  29. $(addprefix $(csu-objpfx),$(start-installed-name)) \
  30. @@ -426,7 +426,10 @@ ifndef +link
  31. $(start-installed-name))\
  32. $(+preinit) $(link-extra-libs) \
  33. $(common-objpfx)libc% $(+postinit),$^) \
  34. - $(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
  35. + $(link-extra-libs)
  36. ++link-after-libc = $(+postctor) $(+postinit)
  37. ++link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
  38. ++link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
  39. endif
  40. # Command for linking PIE programs with the C library.
  41. ifndef +link-pie
  42. @@ -443,7 +446,7 @@ ifndef +link-pie
  43. endif
  44. # Command for statically linking programs with the C library.
  45. ifndef +link-static
  46. -+link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
  47. ++link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
  48. $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
  49. $(addprefix $(csu-objpfx),$(static-start-installed-name)) \
  50. $(+preinit) $(+prector) \
  51. @@ -451,7 +454,12 @@ ifndef +link-static
  52. $(start-installed-name))\
  53. $(+preinit) $(link-extra-libs-static) \
  54. $(common-objpfx)libc% $(+postinit),$^) \
  55. - $(link-extra-libs-static) $(link-libc-static) $(+postctor) $(+postinit)
  56. + $(link-extra-libs-static) $(link-libc-static)
  57. ++link-static-after-libc = $(+postctor) $(+postinit)
  58. ++link-static = $(+link-static-before-libc) $(link-libc-static) \
  59. + $(+link-static-after-libc)
  60. ++link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
  61. + $(+link-static-after-libc)
  62. endif
  63. # Command for statically linking bounded-pointer programs with the C library.
  64. ifndef +link-bounded
  65. @@ -475,10 +483,12 @@ ifeq (yes,$(build-shared))
  66. # We need the versioned name of libc.so in the deps of $(others) et al
  67. # so that the symlink to libc.so is created before anything tries to
  68. # run the linked programs.
  69. -link-libc = -Wl,-rpath-link=$(rpath-link) \
  70. +link-libc-before-gnulib = -Wl,-rpath-link=$(rpath-link) \
  71. $(common-objpfx)libc.so$(libc.so-version) \
  72. $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
  73. - $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed) $(gnulib)
  74. + $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed)
  75. +link-libc = $(link-libc-before-gnulib) $(gnulib)
  76. +link-libc-tests = $(link-libc-before-gnulib) $(gnulib-tests)
  77. # This is how to find at build-time things that will be installed there.
  78. rpath-dirs = math elf dlfcn nss nis rt resolv crypt
  79. rpath-link = \
  80. @@ -488,6 +498,7 @@ else
  81. nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
  82. resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
  83. link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
  84. +link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
  85. endif
  86. endif
  87. @@ -513,8 +524,43 @@ endif
  88. # The static libraries.
  89. link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
  90. +link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
  91. link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a
  92. +# How to link against libgcc. Some libgcc functions, such as those
  93. +# for "long long" arithmetic or software floating point, can always be
  94. +# built without use of C library headers and do not have any global
  95. +# state so can safely be linked statically into any executable or
  96. +# shared library requiring them; these functions are in libgcc.a.
  97. +# Other functions, relating to exception handling, may require C
  98. +# library headers to build and it may not be safe to have more than
  99. +# one copy of them in a process; these functions are only in
  100. +# libgcc_s.so and libgcc_eh.a.
  101. +#
  102. +# To avoid circular dependencies when bootstrapping, it is desirable
  103. +# to avoid use of libgcc_s and libgcc_eh in building glibc. Where any
  104. +# glibc functionality (in particular, thread cancellation) requires
  105. +# exception handling, this is implemented through dlopen of libgcc_s
  106. +# to avoid unnecessary dependencies on libgcc_s by programs not using
  107. +# that functionality; executables built with glibc do not use
  108. +# exception handling other than through thread cancellation.
  109. +#
  110. +# Undefined references to functions from libgcc_eh or libgcc_s may
  111. +# arise for code built with -fexceptions. In the case of statically
  112. +# linked programs installed by glibc, unwinding will never actually
  113. +# occur at runtime and the use of elf/static-stubs.c to resolve these
  114. +# references is safe. In the case of statically linked test programs
  115. +# and test programs built with -fexceptions, unwinding may occur in
  116. +# some cases and it is preferable to link with libgcc_eh or libgcc_s
  117. +# so that the testing is as similar as possible to how programs will
  118. +# be built with the installed glibc.
  119. +#
  120. +# Some architectures have architecture-specific systems for exception
  121. +# handling that may involve undefined references to
  122. +# architecture-specific functions. On those architectures,
  123. +# gnulib-arch and static-gnulib-arch may be defined in sysdeps
  124. +# makefiles to use additional libraries for linking executables and
  125. +# shared libraries built by glibc.
  126. ifndef gnulib
  127. ifneq ($(have-cc-with-libunwind),yes)
  128. libunwind =
  129. @@ -522,8 +568,12 @@ else
  130. libunwind = -lunwind
  131. endif
  132. libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
  133. -gnulib := -lgcc $(libgcc_eh)
  134. -static-gnulib := -lgcc -lgcc_eh $(libunwind)
  135. +gnulib-arch =
  136. +gnulib = -lgcc $(gnulib-arch)
  137. +gnulib-tests := -lgcc $(libgcc_eh)
  138. +static-gnulib-arch =
  139. +static-gnulib = -lgcc $(static-gnulib-arch)
  140. +static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
  141. libc.so-gnulib := -lgcc
  142. endif
  143. +preinit = $(addprefix $(csu-objpfx),crti.o)
  144. diff --git a/Rules b/Rules
  145. index 3c61a29..17d938e 100644
  146. --- a/Rules
  147. +++ b/Rules
  148. @@ -1,5 +1,4 @@
  149. -# Copyright (C) 1991-2000,2002,2003,2004,2005,2006,2011
  150. -# Free Software Foundation, Inc.
  151. +# Copyright (C) 1991-2012 Free Software Foundation, Inc.
  152. # This file is part of the GNU C Library.
  153. # The GNU C Library is free software; you can redistribute it and/or
  154. @@ -103,29 +102,46 @@ xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-bp.out)
  155. endif
  156. ifeq ($(build-programs),yes)
  157. -binaries-all = $(others) $(sysdep-others) $(tests) $(xtests) $(test-srcs)
  158. -binaries-static = $(others-static) $(tests-static) $(xtests-static)
  159. +binaries-all-notests = $(others) $(sysdep-others)
  160. +binaries-all-tests = $(tests) $(xtests) $(test-srcs)
  161. +binaries-all = $(binaries-all-notests) $(binaries-all-tests)
  162. +binaries-static-notests = $(others-static)
  163. +binaries-static-tests = $(tests-static) $(xtests-static)
  164. +binaries-static = $(binaries-static-notests) $(binaries-static-tests)
  165. ifeq (yesyes,$(have-fpie)$(build-shared))
  166. binaries-pie = $(others-pie) $(tests-pie) $(xtests-pie)
  167. else
  168. binaries-pie =
  169. endif
  170. else
  171. -binaries-all = $(tests) $(xtests) $(test-srcs)
  172. +binaries-all-notests =
  173. +binaries-all-tests = $(tests) $(xtests) $(test-srcs)
  174. +binaries-all = $(binaries-all-tests)
  175. +binaries-static-notests =
  176. +binaries-static-tests =
  177. binaries-static =
  178. binaries-pie =
  179. endif
  180. -binaries-shared = $(filter-out $(binaries-pie) $(binaries-static), \
  181. - $(binaries-all))
  182. +binaries-shared-tests = $(filter-out $(binaries-pie) $(binaries-static), \
  183. + $(binaries-all-tests))
  184. +binaries-shared-notests = $(filter-out $(binaries-pie) $(binaries-static), \
  185. + $(binaries-all-notests))
  186. -ifneq "$(strip $(binaries-shared))" ""
  187. -$(addprefix $(objpfx),$(binaries-shared)): %: %.o \
  188. +ifneq "$(strip $(binaries-shared-notests))" ""
  189. +$(addprefix $(objpfx),$(binaries-shared-notests)): %: %.o \
  190. $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  191. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  192. $(+link)
  193. endif
  194. +ifneq "$(strip $(binaries-shared-tests))" ""
  195. +$(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
  196. + $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  197. + $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  198. + $(+link-tests)
  199. +endif
  200. +
  201. ifneq "$(strip $(binaries-pie))" ""
  202. $(addprefix $(objpfx),$(binaries-pie)): %: %.o \
  203. $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  204. @@ -133,13 +149,20 @@ $(addprefix $(objpfx),$(binaries-pie)): %: %.o \
  205. $(+link-pie)
  206. endif
  207. -ifneq "$(strip $(binaries-static))" ""
  208. -$(addprefix $(objpfx),$(binaries-static)): %: %.o \
  209. +ifneq "$(strip $(binaries-static-notests))" ""
  210. +$(addprefix $(objpfx),$(binaries-static-notests)): %: %.o \
  211. $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
  212. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  213. $(+link-static)
  214. endif
  215. +ifneq "$(strip $(binaries-static-tests))" ""
  216. +$(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
  217. + $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
  218. + $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  219. + $(+link-static-tests)
  220. +endif
  221. +
  222. ifeq ($(build-bounded),yes)
  223. binaries-bounded = $(addsuffix -bp,$(tests) $(xtests) $(test-srcs))
  224. $(addprefix $(objpfx),$(binaries-bounded)): %-bp: %.ob \
  225. diff --git a/elf/Makefile b/elf/Makefile
  226. index 0c26ce5..9054199 100644
  227. --- a/elf/Makefile
  228. +++ b/elf/Makefile
  229. @@ -71,6 +71,8 @@ others = sprof sln pldd
  230. install-bin = sprof pldd
  231. others-static = sln
  232. install-rootsbin = sln
  233. +sln-modules := static-stubs
  234. +extra-objs += $(sln-modules:=.o)
  235. ifeq (yes,$(use-ldconfig))
  236. ifeq (yes,$(build-shared))
  237. @@ -78,7 +80,7 @@ others-static += ldconfig
  238. others += ldconfig
  239. install-rootsbin += ldconfig
  240. -ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
  241. +ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs
  242. extra-objs += $(ldconfig-modules:=.o)
  243. endif
  244. endif
  245. @@ -411,6 +413,8 @@ $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
  246. $(objpfx)sprof: $(libdl)
  247. +$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o)
  248. +
  249. $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
  250. $(objpfx)pldd: $(pldd-modules:%=$(objpfx)%.o)
  251. diff --git a/elf/static-stubs.c b/elf/static-stubs.c
  252. new file mode 100644
  253. index 0000000..6c5eebc
  254. --- /dev/null
  255. +++ b/elf/static-stubs.c
  256. @@ -0,0 +1,46 @@
  257. +/* Stub implementations of functions to link into statically linked
  258. + programs without needing libgcc_eh.
  259. + Copyright (C) 2012 Free Software Foundation, Inc.
  260. + This file is part of the GNU C Library.
  261. +
  262. + The GNU C Library is free software; you can redistribute it and/or
  263. + modify it under the terms of the GNU Lesser General Public
  264. + License as published by the Free Software Foundation; either
  265. + version 2.1 of the License, or (at your option) any later version.
  266. +
  267. + The GNU C Library is distributed in the hope that it will be useful,
  268. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  269. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  270. + Lesser General Public License for more details.
  271. +
  272. + You should have received a copy of the GNU Lesser General Public
  273. + License along with the GNU C Library; if not, see
  274. + <http://www.gnu.org/licenses/>. */
  275. +
  276. +/* Avoid backtrace (and so _Unwind_Backtrace) dependencies from
  277. + sysdeps/unix/sysv/linux/libc_fatal.c. */
  278. +#include <sysdeps/posix/libc_fatal.c>
  279. +
  280. +#include <stdlib.h>
  281. +#include <unwind.h>
  282. +
  283. +/* These programs do not use thread cancellation, so _Unwind_Resume
  284. + and the personality routine are never actually called. */
  285. +
  286. +void
  287. +_Unwind_Resume (struct _Unwind_Exception *exc __attribute__ ((unused)))
  288. +{
  289. + abort ();
  290. +}
  291. +
  292. +_Unwind_Reason_Code
  293. +__gcc_personality_v0 (int version __attribute__ ((unused)),
  294. + _Unwind_Action actions __attribute__ ((unused)),
  295. + _Unwind_Exception_Class exception_class
  296. + __attribute__ ((unused)),
  297. + struct _Unwind_Exception *ue_header
  298. + __attribute__ ((unused)),
  299. + struct _Unwind_Context *context __attribute__ ((unused)))
  300. +{
  301. + abort ();
  302. +}
  303. diff --git a/ports/ChangeLog.arm b/ports/ChangeLog.arm
  304. index c411e1c..71e8b1b 100644
  305. --- a/ports/ChangeLog.arm
  306. +++ b/ports/ChangeLog.arm
  307. @@ -1,3 +1,10 @@
  308. +2012-07-03 Joseph Myers <joseph@codesourcery.com>
  309. +
  310. + * sysdeps/arm/Makefile (gnulib-arch): New variable.
  311. + (static-gnulib-arch): Likewise.
  312. + [subdir = elf] ($(objpfx)libgcc-stubs.a): New rule.
  313. + [subdir = elf] (lib-noranlib): Depend on $(objpfx)libgcc-stubs.a.
  314. +
  315. 2012-06-12 Joseph Myers <joseph@codesourcery.com>
  316. * sysdeps/unix/sysv/linux/arm/setcontext.S (__startcontext): Use
  317. diff --git a/ports/sysdeps/arm/Makefile b/ports/sysdeps/arm/Makefile
  318. index 5fd5136..3bdb6b3 100644
  319. --- a/ports/sysdeps/arm/Makefile
  320. +++ b/ports/sysdeps/arm/Makefile
  321. @@ -1,8 +1,16 @@
  322. +gnulib-arch = $(elfobjdir)/libgcc-stubs.a
  323. +static-gnulib-arch = $(elfobjdir)/libgcc-stubs.a
  324. +
  325. ifeq ($(subdir),elf)
  326. sysdep-dl-routines += tlsdesc dl-tlsdesc
  327. sysdep_routines += aeabi_unwind_cpp_pr1 find_exidx tlsdesc dl-tlsdesc
  328. sysdep-rtld-routines += aeabi_unwind_cpp_pr1 tlsdesc dl-tlsdesc
  329. shared-only-routines += aeabi_unwind_cpp_pr1
  330. +
  331. +$(objpfx)libgcc-stubs.a: $(objpfx)aeabi_unwind_cpp_pr1.os
  332. + $(build-extra-lib)
  333. +
  334. +lib-noranlib: $(objpfx)libgcc-stubs.a
  335. endif
  336. ifeq ($(subdir),csu)
  337. --
  338. 1.7.3.4