Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # Copyright (C) 1995-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 gmon portion of the library.
  17. #
  18. subdir := gmon
  19. include ../Makeconfig
  20. headers := \
  21. sys/gmon.h \
  22. sys/gmon_out.h \
  23. sys/profil.h \
  24. # headers
  25. routines := \
  26. gmon \
  27. mcount \
  28. prof-freq \
  29. profil \
  30. sprofil \
  31. # routines
  32. tests = \
  33. tst-gmon \
  34. tst-mcleanup \
  35. tst-mcount-overflow \
  36. tst-sprofil \
  37. # tests
  38. # clang does not support -profile to instruct linker to use lc_p
  39. ifeq ($(build-profile)$(have-test-clang),yesno)
  40. tests += tst-profile-static
  41. tests-static += tst-profile-static
  42. LDFLAGS-tst-profile-static = -profile
  43. endif
  44. tests += tst-gmon-static
  45. tests-static += tst-gmon-static
  46. ifeq (yesyes,$(have-fpie)$(build-shared))
  47. tests += tst-gmon-pie
  48. tests-pie += tst-gmon-pie
  49. ifeq (yes,$(enable-static-pie))
  50. tests += tst-gmon-static-pie
  51. tests-static += tst-gmon-static-pie
  52. endif
  53. endif
  54. # The mcount code won't work without a frame pointer nor when memcpy or
  55. # memset are called.
  56. CFLAGS-mcount.c := -fno-omit-frame-pointer
  57. ifeq (yes,$(config-cflags-cc-loop-to-function))
  58. CFLAGS-mcount.c += -fno-tree-loop-distribute-patterns
  59. endif
  60. CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg
  61. tst-gmon-no-pie = yes
  62. CRT-tst-gmon := $(csu-objpfx)g$(start-installed-name)
  63. tst-gmon-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon.data
  64. ifeq ($(run-built-tests),yes)
  65. tests-special += $(objpfx)tst-gmon-gprof.out
  66. endif
  67. CFLAGS-tst-mcount-overflow.c := -fno-omit-frame-pointer -pg
  68. tst-mcount-overflow-no-pie = yes
  69. CRT-tst-mcount-overflow := $(csu-objpfx)g$(start-installed-name)
  70. # Intentionally use invalid config where maxarcs<minarcs to check warning is printed
  71. tst-mcount-overflow-ENV := GMON_OUT_PREFIX=$(objpfx)tst-mcount-overflow.data \
  72. GLIBC_TUNABLES=glibc.gmon.minarcs=51:glibc.gmon.maxarcs=50
  73. # Send stderr into output file because we make sure expected messages are printed
  74. tst-mcount-overflow-ARGS := 2>&1 1>/dev/null | cat
  75. ifeq ($(run-built-tests),yes)
  76. tests-special += $(objpfx)tst-mcount-overflow-check.out
  77. endif
  78. CFLAGS-tst-mcleanup.c := -fno-omit-frame-pointer -pg
  79. tst-mcleanup-no-pie = yes
  80. CRT-tst-mcleanup := $(csu-objpfx)g$(start-installed-name)
  81. tst-mcleanup-ENV := GMON_OUT_PREFIX=$(objpfx)tst-mcleanup.data
  82. ifeq ($(run-built-tests),yes)
  83. tests-special += $(objpfx)tst-mcleanup.out
  84. endif
  85. CFLAGS-tst-gmon-static.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
  86. CRT-tst-gmon-static := $(csu-objpfx)g$(static-start-installed-name)
  87. tst-gmon-static-no-pie = yes
  88. tst-gmon-static-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static.data
  89. ifeq ($(run-built-tests),yes)
  90. tests-special += $(objpfx)tst-gmon-static-gprof.out
  91. endif
  92. CFLAGS-tst-gmon-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
  93. CRT-tst-gmon-pie := $(csu-objpfx)g$(start-installed-name)
  94. tst-gmon-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-pie.data
  95. ifeq ($(run-built-tests),yes)
  96. tests-special += $(objpfx)tst-gmon-pie-gprof.out
  97. endif
  98. ifeq (yes,$(enable-static-pie))
  99. CFLAGS-tst-gmon-static-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
  100. CRT-tst-gmon-static-pie := $(csu-objpfx)gr$(static-start-installed-name)
  101. tst-gmon-static-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static-pie.data
  102. ifeq ($(run-built-tests),yes)
  103. tests-special += $(objpfx)tst-gmon-static-pie-gprof.out
  104. endif
  105. endif
  106. include ../Rules
  107. # We cannot compile mcount.c with -pg because that would
  108. # create recursive calls. Just copy the normal static object.
  109. # On systems where `profil' is not a system call, the same
  110. # problem exists for the internal functions in profil.c.
  111. noprof := mcount $(sysdep_noprof)
  112. ifeq (,$(filter profil,$(unix-syscalls)))
  113. noprof += profil sprofil
  114. endif
  115. $(noprof:%=$(objpfx)%.op): %.op: %.o
  116. rm -f $@
  117. ln $< $@
  118. # GMON_OUTPUT_PREFIX only sets the output prefix. The actual file
  119. # name contains the PID as well.
  120. $(objpfx)tst-gmon.out: clean-tst-gmon-data
  121. clean-tst-gmon-data:
  122. rm -f $(objpfx)tst-gmon.data.*
  123. $(objpfx)tst-mcount-overflow.o: clean-tst-mcount-overflow-data
  124. clean-tst-mcount-overflow-data:
  125. rm -f $(objpfx)tst-mcount-overflow.data.*
  126. $(objpfx)tst-mcount-overflow-check.out: tst-mcount-overflow-check.sh $(objpfx)tst-mcount-overflow.out
  127. $(SHELL) $< $(objpfx)tst-mcount-overflow > $@; \
  128. $(evaluate-test)
  129. $(objpfx)tst-mcleanup.out: clean-tst-mcleanup-data
  130. clean-tst-mcleanup-data:
  131. rm -f $(objpfx)tst-mcleanup.data.*
  132. $(objpfx)tst-gmon-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon.out
  133. $(SHELL) $< $(GPROF) $(objpfx)tst-gmon $(objpfx)tst-gmon.data.* > $@; \
  134. $(evaluate-test)
  135. $(objpfx)tst-gmon-static.out: clean-tst-gmon-static-data
  136. clean-tst-gmon-static-data:
  137. rm -f $(objpfx)tst-gmon-static.data.*
  138. $(objpfx)tst-gmon-static-gprof.out: tst-gmon-static-gprof.sh \
  139. $(objpfx)tst-gmon-static.out
  140. $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static \
  141. $(objpfx)tst-gmon-static.data.* > $@; \
  142. $(evaluate-test)
  143. $(objpfx)tst-gmon-pie.out: clean-tst-gmon-pie-data
  144. clean-tst-gmon-pie-data:
  145. rm -f $(objpfx)tst-gmon-pie.data.*
  146. $(objpfx)tst-gmon-pie-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon-pie.out
  147. $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-pie $(objpfx)tst-gmon-pie.data.* > $@; \
  148. $(evaluate-test)
  149. $(objpfx)tst-gmon-static-pie.out: clean-tst-gmon-static-pie-data
  150. clean-tst-gmon-static-pie-data:
  151. rm -f $(objpfx)tst-gmon-static-pie.data.*
  152. $(objpfx)tst-gmon-static-pie-gprof.out: tst-gmon-static-gprof.sh \
  153. $(objpfx)tst-gmon-static-pie.out
  154. $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static-pie \
  155. $(objpfx)tst-gmon-static-pie.data.* > $@; \
  156. $(evaluate-test)