gcc.mk 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. ################################################################################
  2. #
  3. # Common variables for the gcc-initial and gcc-final packages.
  4. #
  5. ################################################################################
  6. #
  7. # Version, site and source
  8. #
  9. GCC_VERSION = $(call qstrip,$(BR2_GCC_VERSION))
  10. ifeq ($(BR2_GCC_VERSION_ARC),y)
  11. GCC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,gcc,$(GCC_VERSION))
  12. GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
  13. else
  14. GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
  15. GCC_SOURCE = gcc-$(GCC_VERSION).tar.xz
  16. endif
  17. HOST_GCC_LICENSE = GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0
  18. HOST_GCC_LICENSE_FILES = COPYING COPYING3 COPYING.LIB COPYING3.LIB
  19. #
  20. # Xtensa special hook
  21. #
  22. define HOST_GCC_XTENSA_OVERLAY_EXTRACT
  23. $(call arch-xtensa-overlay-extract,$(@D),gcc)
  24. endef
  25. #
  26. # Apply patches
  27. #
  28. # gcc is a special package, not named gcc, but gcc-initial and
  29. # gcc-final, but patches are nonetheless stored in package/gcc in the
  30. # tree, and potentially in BR2_GLOBAL_PATCH_DIR directories as well.
  31. define HOST_GCC_APPLY_PATCHES
  32. for patchdir in \
  33. package/gcc/$(GCC_VERSION) \
  34. $(addsuffix /gcc/$(GCC_VERSION),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  35. $(addsuffix /gcc,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) ; do \
  36. if test -d $${patchdir}; then \
  37. $(APPLY_PATCHES) $(@D) $${patchdir} \*.patch || exit 1; \
  38. fi; \
  39. done
  40. endef
  41. HOST_GCC_EXCLUDES = \
  42. libjava/* libgo/*
  43. #
  44. # Create 'build' directory and configure symlink
  45. #
  46. define HOST_GCC_CONFIGURE_SYMLINK
  47. mkdir -p $(@D)/build
  48. ln -sf ../configure $(@D)/build/configure
  49. endef
  50. #
  51. # Common configuration options
  52. #
  53. HOST_GCC_COMMON_DEPENDENCIES = \
  54. host-binutils \
  55. host-gmp \
  56. host-mpc \
  57. host-mpfr \
  58. $(if $(BR2_BINFMT_FLAT),host-elf2flt)
  59. HOST_GCC_COMMON_CONF_OPTS = \
  60. --target=$(GNU_TARGET_NAME) \
  61. --with-sysroot=$(STAGING_DIR) \
  62. --enable-__cxa_atexit \
  63. --with-gnu-ld \
  64. --disable-libssp \
  65. --disable-multilib \
  66. --disable-decimal-float \
  67. --enable-plugins \
  68. --enable-lto \
  69. --with-gmp=$(HOST_DIR) \
  70. --with-mpc=$(HOST_DIR) \
  71. --with-mpfr=$(HOST_DIR) \
  72. --with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
  73. --with-bugurl="https://gitlab.com/buildroot.org/buildroot/-/issues" \
  74. --without-zstd
  75. ifeq ($(BR2_REPRODUCIBLE),y)
  76. HOST_GCC_COMMON_CONF_OPTS += --with-debug-prefix-map=$(BASE_DIR)=buildroot
  77. endif
  78. # Don't build documentation. It takes up extra space / build time,
  79. # and sometimes needs specific makeinfo versions to work. Override the check
  80. # for a modern makeinfo otherwise the configure scripts will still enable it.
  81. HOST_GCC_COMMON_CONF_ENV = \
  82. MAKEINFO=missing
  83. HOST_GCC_COMMON_MAKE_OPTS = \
  84. gcc_cv_prog_makeinfo_modern=no
  85. # Target binaries and libraries which are being built as a part of GCC
  86. # don't use Buildroot toolchain wrapper because, instead its very own "xgcc"
  87. # binary is used. And so we need to explicitly propagate ALL the flags
  88. # directly to "xgcc" and that is done via configure-time environment
  89. # variables, see below setup of HOST_GCC_COMMON_CONF_ENV.
  90. GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS) $(ARCH_TOOLCHAIN_WRAPPER_OPTS)
  91. GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS) $(ARCH_TOOLCHAIN_WRAPPER_OPTS)
  92. GCC_COMMON_TARGET_LDFLAGS = $(TARGET_LDFLAGS) $(ARCH_TOOLCHAIN_WRAPPER_OPTS)
  93. # used to fix ../../../../libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  94. ifeq ($(BR2_ENABLE_DEBUG),y)
  95. GCC_COMMON_TARGET_CFLAGS += -Wno-error
  96. endif
  97. # Propagate options used for target software building to GCC target libs
  98. HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
  99. HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
  100. HOST_GCC_COMMON_CONF_ENV += LDFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_LDFLAGS)"
  101. HOST_GCC_COMMON_CONF_ENV += AR_FOR_TARGET=gcc-ar NM_FOR_TARGET=gcc-nm RANLIB_FOR_TARGET=gcc-ranlib
  102. # libitm needs sparc V9+
  103. ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
  104. HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
  105. endif
  106. # libmpx uses secure_getenv and struct _libc_fpstate not present in musl
  107. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_MUSL)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6),yy)
  108. HOST_GCC_COMMON_CONF_OPTS += --disable-libmpx
  109. endif
  110. # quadmath support requires wchar
  111. ifeq ($(BR2_USE_WCHAR)$(BR2_TOOLCHAIN_HAS_LIBQUADMATH),yy)
  112. HOST_GCC_COMMON_CONF_OPTS += --enable-libquadmath --enable-libquadmath-support
  113. else
  114. HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath --disable-libquadmath-support
  115. endif
  116. # libsanitizer requires wordexp, not in default uClibc config. Also
  117. # doesn't build properly with musl.
  118. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
  119. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  120. endif
  121. # libsanitizer is broken for SPARC
  122. # https://bugs.busybox.net/show_bug.cgi?id=7951
  123. ifeq ($(BR2_sparc)$(BR2_sparc64),y)
  124. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  125. endif
  126. # libsanitizer is available for mips64{el} since gcc 12 but fail to build
  127. # with n32 ABI due to struct stat64 definition clash due to mixing
  128. # kernel and user headers.
  129. ifeq ($(BR2_mips64)$(BR2_mips64el):$(BR2_MIPS_NABI32),y:y)
  130. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  131. endif
  132. # libsanitizer bundled in gcc 12 fails to build for mips32 due to
  133. # mixing kernel and user struct stat.
  134. ifeq ($(BR2_mips)$(BR2_mipsel):$(BR2_TOOLCHAIN_GCC_AT_LEAST_12),y:y)
  135. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  136. endif
  137. # libsanitizer is broken for Thumb1, sanitizer_linux.cc contains unconditional
  138. # "ldr ip, [sp], #8", which causes:
  139. # ....s: Assembler messages:
  140. # ....s:4190: Error: lo register required -- `ldr ip,[sp],#8'
  141. ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB),y)
  142. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  143. endif
  144. # The logic in libbacktrace/configure.ac to detect if __sync builtins
  145. # are available assumes they are as soon as target_subdir is not
  146. # empty, i.e when cross-compiling. However, some platforms do not have
  147. # __sync builtins, so help the configure script a bit.
  148. ifeq ($(BR2_TOOLCHAIN_HAS_SYNC_4),)
  149. HOST_GCC_COMMON_CONF_ENV += target_configargs="libbacktrace_cv_sys_sync=no"
  150. endif
  151. # TLS support is not needed on uClibc/no-thread and
  152. # uClibc/linux-threads, otherwise, for all other situations (glibc,
  153. # musl and uClibc/NPTL), we need it.
  154. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_PTHREADS)$(BR2_PTHREADS_NONE),yy)
  155. HOST_GCC_COMMON_CONF_OPTS += --disable-tls
  156. else
  157. HOST_GCC_COMMON_CONF_OPTS += --enable-tls
  158. endif
  159. ifeq ($(BR2_PTHREADS_NONE),y)
  160. HOST_GCC_COMMON_CONF_OPTS += \
  161. --disable-threads \
  162. --disable-libitm \
  163. --disable-libatomic
  164. else
  165. HOST_GCC_COMMON_CONF_OPTS += --enable-threads
  166. endif
  167. # gcc 5 doesn't need cloog any more, see
  168. # https://gcc.gnu.org/gcc-5/changes.html and we don't support graphite
  169. # on GCC 4.9.x, so only isl is needed.
  170. ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
  171. HOST_GCC_COMMON_DEPENDENCIES += host-isl
  172. HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)
  173. else
  174. HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
  175. endif
  176. ifeq ($(BR2_arc),y)
  177. HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
  178. endif
  179. ifeq ($(BR2_SOFT_FLOAT),y)
  180. # only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
  181. # powerpc seems to be needing it as well
  182. ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
  183. HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
  184. endif
  185. endif
  186. # Determine arch/tune/abi/cpu options
  187. ifneq ($(GCC_TARGET_ARCH),)
  188. HOST_GCC_COMMON_CONF_OPTS += --with-arch="$(GCC_TARGET_ARCH)"
  189. endif
  190. ifneq ($(GCC_TARGET_ABI),)
  191. HOST_GCC_COMMON_CONF_OPTS += --with-abi="$(GCC_TARGET_ABI)"
  192. endif
  193. ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
  194. ifneq ($(GCC_TARGET_NAN),)
  195. HOST_GCC_COMMON_CONF_OPTS += --with-nan="$(GCC_TARGET_NAN)"
  196. endif
  197. endif
  198. ifneq ($(GCC_TARGET_FP32_MODE),)
  199. HOST_GCC_COMMON_CONF_OPTS += --with-fp-32="$(GCC_TARGET_FP32_MODE)"
  200. endif
  201. # musl/uClibc-ng does not work with biarch powerpc toolchains, we
  202. # need to configure gcc explicitly for 32 Bit for CPU's supporting
  203. # 64 Bit and 32 Bit
  204. ifneq ($(GCC_TARGET_CPU),)
  205. ifeq ($(BR2_powerpc),y)
  206. HOST_GCC_COMMON_CONF_OPTS += --with-cpu-32=$(GCC_TARGET_CPU)
  207. else
  208. HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(GCC_TARGET_CPU)
  209. endif
  210. endif
  211. ifneq ($(GCC_TARGET_FPU),)
  212. HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
  213. endif
  214. ifneq ($(GCC_TARGET_FLOAT_ABI),)
  215. HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
  216. endif
  217. ifneq ($(GCC_TARGET_SIMD),)
  218. HOST_GCC_COMMON_CONF_OPTS += --with-simd=$(GCC_TARGET_SIMD)
  219. endif
  220. ifneq ($(GCC_TARGET_MODE),)
  221. HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
  222. endif
  223. # Enable proper double/long double for SPE ABI
  224. ifeq ($(BR2_POWERPC_CPU_HAS_SPE),y)
  225. HOST_GCC_COMMON_CONF_OPTS += \
  226. --enable-obsolete \
  227. --enable-e500_double \
  228. --with-long-double-128
  229. endif
  230. # Set default to Secure-PLT to prevent run-time
  231. # generation of PLT stubs (supports RELRO and
  232. # SELinux non-exemem capabilities)
  233. ifeq ($(BR2_powerpc)$(BR2_powerpc64),y)
  234. HOST_GCC_COMMON_CONF_OPTS += --enable-secureplt
  235. endif
  236. # PowerPC64 big endian by default uses the elfv1 ABI, and PowerPC 64
  237. # little endian by default uses the elfv2 ABI. However, musl has
  238. # decided to use the elfv2 ABI for both, so we force the elfv2 ABI for
  239. # Power64 big endian when the selected C library is musl.
  240. ifeq ($(BR2_TOOLCHAIN_USES_MUSL)$(BR2_powerpc64),yy)
  241. HOST_GCC_COMMON_CONF_OPTS += \
  242. --with-abi=elfv2 \
  243. --without-long-double-128
  244. endif
  245. # Since glibc >= 2.26, poerpc64le requires double/long double which
  246. # requires at least gcc 6.2.
  247. # See sysdeps/powerpc/powerpc64le/configure.ac
  248. ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6)$(BR2_powerpc64le),yyy)
  249. HOST_GCC_COMMON_CONF_OPTS += \
  250. --with-long-double-128
  251. endif
  252. ifeq ($(BR2_s390x),y)
  253. HOST_GCC_COMMON_CONF_OPTS += \
  254. --with-long-double-128
  255. endif
  256. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
  257. # For gcc-initial, we need to tell gcc that the C library will be
  258. # providing the ssp support, as it can't guess it since the C library
  259. # hasn't been built yet.
  260. #
  261. # For gcc-final, the gcc logic to detect whether SSP support is
  262. # available or not in the C library is not working properly for
  263. # uClibc, so let's be explicit as well.
  264. HOST_GCC_COMMON_MAKE_OPTS += \
  265. gcc_cv_libc_provides_ssp=$(if $(BR2_TOOLCHAIN_HAS_SSP),yes,no)
  266. ifeq ($(BR2_CCACHE),y)
  267. HOST_GCC_COMMON_CCACHE_HASH_FILES += $($(PKG)_DL_DIR)/$(GCC_SOURCE)
  268. # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned
  269. # and unversioned patches unconditionally. Moreover, to facilitate the
  270. # addition of gcc patches in BR2_GLOBAL_PATCH_DIR, we allow them to be
  271. # stored in a sub-directory called 'gcc' even if it's not technically
  272. # the name of the package.
  273. HOST_GCC_COMMON_CCACHE_HASH_FILES += \
  274. $(sort $(wildcard \
  275. package/gcc/$(GCC_VERSION)/*.patch \
  276. $(addsuffix /$($(PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  277. $(addsuffix /$($(PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  278. $(addsuffix /gcc/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  279. $(addsuffix /gcc/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))))
  280. ifeq ($(BR2_xtensa),y)
  281. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(ARCH_XTENSA_OVERLAY_FILE)
  282. endif
  283. # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR)
  284. # and a reference to the Buildroot git revision (BR2_VERSION_FULL),
  285. # so substitute those away.
  286. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
  287. printf '%s\n' $(subst $(HOST_DIR),@HOST_DIR@,\
  288. $(subst --with-pkgversion="Buildroot $(BR2_VERSION_FULL)",,$($(PKG)_CONF_OPTS))) \
  289. | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
  290. | cut -c -64 | tr -d '\n'`\"
  291. endif # BR2_CCACHE
  292. # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
  293. # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
  294. # *-gcc-nm and should be used instead of the real programs when -flto is
  295. # used. However, we should not add the toolchain wrapper for them, and they
  296. # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
  297. # *-ranlib and *-nm.
  298. # According to gfortran manpage, it supports all options supported by gcc, so
  299. # add gfortran to the list of the program called via the Buildroot wrapper.
  300. # Avoid that a .br_real is symlinked a second time.
  301. # Also create <arch>-linux-<tool> symlinks.
  302. define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
  303. $(Q)cd $(HOST_DIR)/bin; \
  304. for i in $(GNU_TARGET_NAME)-*; do \
  305. case "$$i" in \
  306. *.br_real) \
  307. ;; \
  308. *-ar|*-ranlib|*-nm) \
  309. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  310. ;; \
  311. *cc|*cc-*|*++|*++-*|*cpp|*-gfortran|*-gdc) \
  312. rm -f $$i.br_real; \
  313. mv $$i $$i.br_real; \
  314. ln -sf toolchain-wrapper $$i; \
  315. ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  316. ln -snf $$i.br_real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.br_real; \
  317. ;; \
  318. *) \
  319. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  320. ;; \
  321. esac; \
  322. done
  323. endef
  324. include $(sort $(wildcard package/gcc/*/*.mk))