Makefile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. # Copyright (C) 1998-2026 Free Software Foundation, Inc.
  2. # Copyright The GNU Toolchain Authors.
  3. # This file is part of the GNU C Library.
  4. # The GNU C Library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. # The GNU C Library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Lesser General Public License for more details.
  12. # You should have received a copy of the GNU Lesser General Public
  13. # License along with the GNU C Library; if not, see
  14. # <https://www.gnu.org/licenses/>.
  15. #
  16. # Sub-makefile for debug portion of the library.
  17. #
  18. subdir := debug
  19. include ../Makeconfig
  20. headers := execinfo.h
  21. # Note that ptsname_r_chk and getlogin_r are not here, but in
  22. # login/Makefile instead. If that subdir is omitted from the
  23. # build, its _FORTIFY_SOURCE support will be too.
  24. routines = \
  25. $(static-only-routines) \
  26. ____longjmp_chk \
  27. asprintf_chk \
  28. backtrace \
  29. backtracesyms \
  30. backtracesymsfd \
  31. chk_fail \
  32. confstr_chk \
  33. dprintf_chk \
  34. explicit_bzero_chk \
  35. fdelt_chk \
  36. fgets_chk \
  37. fgets_u_chk \
  38. fgetws_chk \
  39. fgetws_u_chk \
  40. fortify_fail \
  41. fprintf_chk \
  42. fread_chk \
  43. fread_u_chk \
  44. fwprintf_chk \
  45. getcwd_chk \
  46. getdomainname_chk \
  47. getgroups_chk \
  48. gethostname_chk \
  49. gets_chk \
  50. getwd_chk \
  51. inet_ntop_chk \
  52. inet_pton_chk \
  53. longjmp_chk \
  54. mbsnrtowcs_chk \
  55. mbsrtowcs_chk \
  56. mbstowcs_chk \
  57. memcpy_chk \
  58. memmove_chk \
  59. mempcpy_chk \
  60. memset_chk \
  61. memset_explicit_chk \
  62. noophooks \
  63. obprintf_chk \
  64. poll_chk \
  65. ppoll_chk \
  66. pread64_chk \
  67. pread_chk \
  68. printf_chk \
  69. read_chk \
  70. readlink_chk \
  71. readlinkat_chk \
  72. readonly-area \
  73. readonly-area-fallback \
  74. realpath_chk \
  75. recv_chk \
  76. recvfrom_chk \
  77. snprintf_chk \
  78. sprintf_chk \
  79. stack_chk_fail \
  80. stpcpy_chk \
  81. stpncpy_chk \
  82. strcat_chk \
  83. strcpy_chk \
  84. strlcat_chk \
  85. strlcpy_chk \
  86. strncat_chk \
  87. strncpy_chk \
  88. swprintf_chk \
  89. ttyname_r_chk \
  90. vasprintf_chk \
  91. vdprintf_chk \
  92. vfprintf_chk \
  93. vfwprintf_chk \
  94. vobprintf_chk \
  95. vprintf_chk \
  96. vsnprintf_chk \
  97. vsprintf_chk \
  98. vswprintf_chk \
  99. vwprintf_chk \
  100. wcpcpy_chk \
  101. wcpncpy_chk \
  102. wcrtomb_chk \
  103. wcscat_chk \
  104. wcscpy_chk \
  105. wcslcat_chk \
  106. wcslcpy_chk \
  107. wcsncat_chk \
  108. wcsncpy_chk \
  109. wcsnrtombs_chk \
  110. wcsrtombs_chk \
  111. wcstombs_chk \
  112. wctomb_chk \
  113. wmemcpy_chk \
  114. wmemmove_chk \
  115. wmempcpy_chk \
  116. wmemset_chk \
  117. wprintf_chk \
  118. # routines
  119. static-only-routines := stack_chk_fail_local
  120. # Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local
  121. # is an alias of __stack_chk_fail in stack_chk_fail.o.
  122. elide-routines.o := stack_chk_fail_local
  123. # Building the stack-protector failure routines with stack protection
  124. # is not required since we have already failed a stack check and are
  125. # exiting the process. However, the local aliases which jump to the
  126. # real routines should still be compiled with stack protection
  127. # (stack_chk_fail_local.c), so that the statically linked parts of the
  128. # library have the expected flags.
  129. CFLAGS-stack_chk_fail.c += $(no-stack-protector)
  130. CFLAGS-backtrace.c += -fno-omit-frame-pointer -funwind-tables
  131. CFLAGS-sprintf_chk.c += $(libio-mtsafe)
  132. CFLAGS-snprintf_chk.c += $(libio-mtsafe)
  133. CFLAGS-vsprintf_chk.c += $(libio-mtsafe)
  134. CFLAGS-vsnprintf_chk.c += $(libio-mtsafe)
  135. CFLAGS-asprintf_chk.c += $(libio-mtsafe)
  136. CFLAGS-vasprintf_chk.c += $(libio-mtsafe)
  137. CFLAGS-obprintf_chk.c += $(libio-mtsafe)
  138. CFLAGS-dprintf_chk.c += $(libio-mtsafe) -fexceptions
  139. CFLAGS-vdprintf_chk.c += $(libio-mtsafe) -fexceptions
  140. CFLAGS-printf_chk.c += $(libio-mtsafe) -fexceptions
  141. CFLAGS-fprintf_chk.c += $(libio-mtsafe) -fexceptions
  142. CFLAGS-vprintf_chk.c += $(libio-mtsafe) -fexceptions
  143. CFLAGS-vfprintf_chk.c += $(libio-mtsafe) -fexceptions
  144. CFLAGS-gets_chk.c += $(libio-mtsafe) -fexceptions
  145. CFLAGS-fgets_chk.c += $(libio-mtsafe) -fexceptions
  146. CFLAGS-fgets_u_chk.c += $(libio-mtsafe) -fexceptions
  147. CFLAGS-fread_chk.c += $(libio-mtsafe) -fexceptions
  148. CFLAGS-fread_u_chk.c += $(libio-mtsafe) -fexceptions
  149. CFLAGS-swprintf_chk.c += $(libio-mtsafe)
  150. CFLAGS-vswprintf_chk.c += $(libio-mtsafe)
  151. CFLAGS-wprintf_chk.c += $(libio-mtsafe) -fexceptions
  152. CFLAGS-fwprintf_chk.c += $(libio-mtsafe) -fexceptions
  153. CFLAGS-vwprintf_chk.c += $(libio-mtsafe) -fexceptions
  154. CFLAGS-vfwprintf_chk.c += $(libio-mtsafe) -fexceptions
  155. CFLAGS-fgetws_chk.c += $(libio-mtsafe) -fexceptions
  156. CFLAGS-fgetws_u_chk.c += $(libio-mtsafe) -fexceptions
  157. CFLAGS-read_chk.c += -fexceptions -fasynchronous-unwind-tables
  158. CFLAGS-pread_chk.c += -fexceptions -fasynchronous-unwind-tables
  159. CFLAGS-pread64_chk.c += -fexceptions -fasynchronous-unwind-tables
  160. CFLAGS-recv_chk.c += -fexceptions -fasynchronous-unwind-tables
  161. CFLAGS-recvfrom_chk.c += -fexceptions -fasynchronous-unwind-tables
  162. # Need to make sure the settings here override what configure might have
  163. # set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is:
  164. # <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS>
  165. CFLAGS-tst-longjmp_chk.c += -fexceptions -fasynchronous-unwind-tables
  166. CPPFLAGS-tst-longjmp_chk.c += $(no-fortify-source) -D_FORTIFY_SOURCE=1
  167. CFLAGS-tst-longjmp_chk2.c += -fexceptions -fasynchronous-unwind-tables
  168. CPPFLAGS-tst-longjmp_chk2.c += $(no-fortify-source) -D_FORTIFY_SOURCE=1
  169. CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables
  170. CPPFLAGS-tst-longjmp_chk3.c += $(no-fortify-source) -D_FORTIFY_SOURCE=1
  171. CPPFLAGS-tst-realpath-chk.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  172. CPPFLAGS-tst-chk-cancel.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  173. CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  174. CFLAGS-tst-sprintf-fortify-rdonly-mod.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  175. CFLAGS-tst-sprintf-fortify-rdonly-dlopen.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  176. CFLAGS-tst-sprintf-fortify-rdonly-static.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  177. CFLAGS-tst-fortify-syslog.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  178. CFLAGS-tst-fortify-wide.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
  179. LDFLAGS-tst-sprintf-fortify-rdonly-static += $(relro-LDFLAGS)
  180. $(objpfx)tst-sprintf-fortify-rdonly: $(objpfx)tst-sprintf-fortify-rdonly-mod.so
  181. $(objpfx)tst-sprintf-fortify-rdonly.out: \
  182. $(objpfx)tst-sprintf-fortify-rdonly-dlopen.so
  183. $(objpfx)tst-sprintf-fortify-rdonly-static: \
  184. $(objpfx)tst-sprintf-fortify-rdonly-dlopen.o
  185. $(objpfx)tst-sprintf-fortify-rdonly-static.out: \
  186. $(objpfx)tst-sprintf-fortify-rdonly-dlopen.so
  187. tst-sprintf-fortify-rdonly-static-ENV = \
  188. LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)/elf
  189. # _FORTIFY_SOURCE tests.
  190. # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
  191. # preprocessor conditions based on tst-fortify.c.
  192. #
  193. # To add a new test condition, define a cflags-$(cond) make variable to set
  194. # CFLAGS for the file.
  195. tests-all-chk = tst-fortify
  196. tests-c-def-chk =
  197. tests-cc-def-chk =
  198. tests-c-time64-chk =
  199. tests-cc-time64-chk =
  200. CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error
  201. # No additional flags for the default tests.
  202. define cflags-default
  203. endef
  204. define cflags-lfs
  205. CFLAGS-tst-fortify-$(1)-lfs-$(2)-$(3).$(1) += -D_FILE_OFFSET_BITS=64
  206. endef
  207. define cflags-nongnu
  208. CFLAGS-tst-fortify-$(1)-nongnu-$(2)-$(3).$(1) += -D_LARGEFILE64_SOURCE=1
  209. endef
  210. src-chk-nongnu = \#undef _GNU_SOURCE
  211. # We know these tests have problems with format strings, this is what
  212. # we are testing. Disable that warning. They are also testing
  213. # deprecated functions (notably gets) so disable that warning as well.
  214. # And they also generate warnings from warning attributes, which
  215. # cannot be disabled via pragmas, so require -Wno-error to be used.
  216. define gen-chk-test
  217. tests-$(1)-$(4)-chk += tst-fortify-$(1)-$(2)-$(3)-$(4)
  218. CFLAGS-tst-fortify-$(1)-$(2)-$(3)-$(4).$(1) += $(no-fortify-source) -D_FORTIFY_SOURCE=$(3) \
  219. -Wno-format \
  220. -Wno-deprecated-declarations \
  221. -Wno-error
  222. $(eval $(call cflags-$(2),$(1),$(3),$(4)))
  223. $(objpfx)tst-fortify-$(1)-$(2)-$(3)-$(4).$(1): tst-fortify.c Makefile
  224. ( echo "/* Autogenerated from Makefile. */"; \
  225. echo "$(src-chk-$(2))"; \
  226. echo "#include \"tst-fortify.c\"" ) > $$@.tmp
  227. mv $$@.tmp $$@
  228. endef
  229. chk-extensions = c cc
  230. chk-types = default lfs nongnu
  231. # 64 bit time_t implies LFS.
  232. chk-types-time64 = default nongnu
  233. chk-levels = 1 2 3
  234. $(foreach e,$(chk-extensions), \
  235. $(foreach t,$(chk-types), \
  236. $(foreach l,$(chk-levels), \
  237. $(eval $(call gen-chk-test,$(e),$(t),$(l),def)))))
  238. tests-all-chk += $(tests-c-def-chk) $(tests-cc-def-chk)
  239. $(foreach e,$(chk-extensions), \
  240. $(foreach t,$(chk-types-time64), \
  241. $(foreach l,$(chk-levels), \
  242. $(eval $(call gen-chk-test,$(e),$(t),$(l),time64)))))
  243. tests-all-time64-chk += $(tests-c-time64-chk) $(tests-cc-time64-chk)
  244. define link-cc
  245. LDLIBS-$(1) = -lstdc++
  246. endef
  247. $(foreach t,$(tests-cc-def-chk), $(eval $(call link-cc,$(t))))
  248. $(foreach t,$(tests-cc-time64-chk), $(eval $(call link-cc,$(t))))
  249. # backtrace_symbols only works if we link with -rdynamic. backtrace
  250. # requires unwind tables on most architectures.
  251. CFLAGS-tst-backtrace2.c += -funwind-tables
  252. CFLAGS-tst-backtrace3.c += -funwind-tables
  253. CFLAGS-tst-backtrace4.c += -funwind-tables
  254. CFLAGS-tst-backtrace5.c += -funwind-tables
  255. CFLAGS-tst-backtrace6.c += -funwind-tables
  256. LDFLAGS-tst-backtrace2 = -rdynamic
  257. LDFLAGS-tst-backtrace3 = -rdynamic
  258. LDFLAGS-tst-backtrace4 = -rdynamic
  259. LDFLAGS-tst-backtrace5 = -rdynamic
  260. LDFLAGS-tst-backtrace6 = -rdynamic
  261. $(objpfx)tst-backtrace1: $(shared-thread-library)
  262. # When SFrame is enabled, make sure the dwarf unwinder is also exercised.
  263. ifeq ($(enable-gsframe),yes)
  264. dw_unwind_pair := \
  265. tst-backtrace1-nosframe:tst-backtrace1 \
  266. tst-backtrace2-nosframe:tst-backtrace2 \
  267. tst-backtrace3-nosframe:tst-backtrace3 \
  268. tst-backtrace4-nosframe:tst-backtrace4 \
  269. tst-backtrace5-nosframe:tst-backtrace5 \
  270. tst-backtrace6-nosframe:tst-backtrace6
  271. first_column = $(foreach pair,$(dw_unwind_pair),$(word 1,$(subst :, ,$(pair))))
  272. tests-dw-unwind = $(patsubst %,$(objpfx)%.out,$(first_column))
  273. ifeq ($(run-built-tests),yes)
  274. tests-special += $(tests-dw-unwind)
  275. endif
  276. endif
  277. define make-strip-rule
  278. $(objpfx)$(word 1,$(subst :, ,$(1))): $(objpfx)$(word 2,$(subst :, ,$(1)))
  279. $(STRIP) --remove-section=.sframe $$< -o $$@
  280. endef
  281. $(foreach pair,$(dw_unwind_pair),$(eval $(call make-strip-rule,$(pair))))
  282. define make-run-rule
  283. $(objpfx)$(word 1,$(subst :, ,$(1))).out: /dev/null $(objpfx)$(word 1,$(subst :, ,$(1)))
  284. $$(make-test-out) > $$@; $$(evaluate-test)
  285. endef
  286. $(foreach pair,$(dw_unwind_pair),$(eval $(call make-run-rule,$(pair))))
  287. CFLAGS-tst-ssp-1.c += -fstack-protector-all
  288. # Disable compiler optimizations around vsprintf (the function under test).
  289. CFLAGS-tst-sprintf-fortify-unchecked.c = \
  290. -fno-builtin-vsprintf -fno-builtin-__vsprintf_chk
  291. tests = \
  292. $(tests-all-chk) \
  293. backtrace-tst \
  294. test-stpcpy_chk \
  295. test-strcpy_chk \
  296. tst-backtrace1 \
  297. tst-backtrace2 \
  298. tst-backtrace3 \
  299. tst-backtrace4 \
  300. tst-backtrace5 \
  301. tst-backtrace6 \
  302. tst-fortify-wide \
  303. tst-longjmp_chk \
  304. tst-longjmp_chk2 \
  305. tst-longjmp_chk3 \
  306. tst-realpath-chk \
  307. tst-sprintf-fortify-rdonly \
  308. tst-sprintf-fortify-rdonly-static \
  309. tst-sprintf-fortify-unchecked \
  310. # tests
  311. tests-static = \
  312. tst-sprintf-fortify-rdonly-static \
  313. # tests-static
  314. tests-time64 += \
  315. $(tests-all-time64-chk) \
  316. # tests-time64
  317. tests-container += \
  318. tst-fortify-syslog \
  319. # tests-container
  320. modules-names += \
  321. tst-sprintf-fortify-rdonly-dlopen \
  322. tst-sprintf-fortify-rdonly-mod \
  323. # modules-names
  324. ifeq ($(have-ssp),yes)
  325. tests += tst-ssp-1
  326. endif
  327. ifeq ($(have-thread-library), yes)
  328. tests += tst-chk-cancel
  329. endif
  330. ifeq (,$(CXX))
  331. tests-unsupported = $(tests-cc-def-chk) $(tests-cc-time64-chk)
  332. endif
  333. extra-libs = libpcprofile
  334. extra-libs-others = $(extra-libs)
  335. libpcprofile-routines = pcprofile
  336. libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes))
  337. others = pcprofiledump
  338. install-bin = pcprofiledump
  339. install-bin-script = xtrace
  340. generated += xtrace
  341. include ../Rules
  342. ifeq ($(run-built-tests),yes)
  343. LOCALES := de_DE.UTF-8
  344. include ../gen-locales.mk
  345. define chk-gen-locales
  346. $(objpfx)$(1).out: $(gen-locales)
  347. endef
  348. $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
  349. $(foreach t, $(tests-all-time64-chk), $(eval $(call chk-gen-locales,$(t))))
  350. endif
  351. sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
  352. $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o
  353. $(objpfx)xtrace: xtrace.sh
  354. rm -f $@.new
  355. sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
  356. -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
  357. -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
  358. && rm -f $@ && mv $@.new $@ && chmod +x $@
  359. $(objpfx)tst-chk-cancel: $(shared-thread-library)