gcc.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 ifeq ($(BR2_GCC_VERSION_CSKY),y)
  14. GCC_SITE = $(call github,c-sky,gcc,$(GCC_VERSION))
  15. GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
  16. else
  17. GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
  18. GCC_SOURCE = gcc-$(GCC_VERSION).tar.xz
  19. endif
  20. #
  21. # Xtensa special hook
  22. #
  23. define HOST_GCC_XTENSA_OVERLAY_EXTRACT
  24. $(call arch-xtensa-overlay-extract,$(@D),gcc)
  25. endef
  26. #
  27. # Apply patches
  28. #
  29. # gcc is a special package, not named gcc, but gcc-initial and
  30. # gcc-final, but patches are nonetheless stored in package/gcc in the
  31. # tree, and potentially in BR2_GLOBAL_PATCH_DIR directories as well.
  32. define HOST_GCC_APPLY_PATCHES
  33. for patchdir in \
  34. package/gcc/$(GCC_VERSION) \
  35. $(addsuffix /gcc/$(GCC_VERSION),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  36. $(addsuffix /gcc,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) ; do \
  37. if test -d $${patchdir}; then \
  38. $(APPLY_PATCHES) $(@D) $${patchdir} \*.patch || exit 1; \
  39. fi; \
  40. done
  41. $(HOST_GCC_APPLY_POWERPC_PATCH)
  42. endef
  43. HOST_GCC_EXCLUDES = \
  44. libjava/* libgo/*
  45. #
  46. # Create 'build' directory and configure symlink
  47. #
  48. define HOST_GCC_CONFIGURE_SYMLINK
  49. mkdir -p $(@D)/build
  50. ln -sf ../configure $(@D)/build/configure
  51. endef
  52. #
  53. # Common configuration options
  54. #
  55. HOST_GCC_COMMON_DEPENDENCIES = \
  56. host-binutils \
  57. host-gmp \
  58. host-mpc \
  59. host-mpfr \
  60. $(if $(BR2_BINFMT_FLAT),host-elf2flt)
  61. HOST_GCC_COMMON_CONF_OPTS = \
  62. --target=$(GNU_TARGET_NAME) \
  63. --with-sysroot=$(STAGING_DIR) \
  64. --enable-__cxa_atexit \
  65. --with-gnu-ld \
  66. --disable-libssp \
  67. --disable-multilib \
  68. --disable-decimal-float \
  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="http://bugs.buildroot.net/" \
  74. --without-zstd
  75. # Don't build documentation. It takes up extra space / build time,
  76. # and sometimes needs specific makeinfo versions to work
  77. HOST_GCC_COMMON_CONF_ENV = \
  78. MAKEINFO=missing
  79. GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
  80. GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
  81. # used to fix ../../../../libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  82. ifeq ($(BR2_ENABLE_DEBUG),y)
  83. GCC_COMMON_TARGET_CFLAGS += -Wno-error
  84. endif
  85. # Propagate options used for target software building to GCC target libs
  86. HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
  87. HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
  88. # libitm needs sparc V9+
  89. ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
  90. HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
  91. endif
  92. # libmpx uses secure_getenv and struct _libc_fpstate not present in musl
  93. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_MUSL)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6),yy)
  94. HOST_GCC_COMMON_CONF_OPTS += --disable-libmpx
  95. endif
  96. # quadmath support requires wchar
  97. ifeq ($(BR2_USE_WCHAR)$(BR2_TOOLCHAIN_HAS_LIBQUADMATH),yy)
  98. HOST_GCC_COMMON_CONF_OPTS += --enable-libquadmath
  99. else
  100. HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath
  101. endif
  102. # Disable libsanitizer due to a build issue with gcc 7.5 and glibc 2.31.
  103. # It would require to backport the following upstream commit
  104. # https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=4abc46b51af5751d657764d0c44b8a4aeed06302
  105. # but it conflict with gcc 7.5 libsanitizer code.
  106. # Disable libsanitizer since the gcc 7.5 branch is now closed
  107. # (unmaintained) and it's not a trivial merge.
  108. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_GLIBC)$(BR2_GCC_VERSION_7_X),yy)
  109. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  110. endif
  111. # libsanitizer requires wordexp, not in default uClibc config. Also
  112. # doesn't build properly with musl.
  113. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
  114. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  115. endif
  116. # libsanitizer is broken for SPARC
  117. # https://bugs.busybox.net/show_bug.cgi?id=7951
  118. ifeq ($(BR2_sparc)$(BR2_sparc64),y)
  119. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  120. endif
  121. # TLS support is not needed on uClibc/no-thread and
  122. # uClibc/linux-threads, otherwise, for all other situations (glibc,
  123. # musl and uClibc/NPTL), we need it.
  124. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_PTHREADS)$(BR2_PTHREADS_NONE),yy)
  125. HOST_GCC_COMMON_CONF_OPTS += --disable-tls
  126. else
  127. HOST_GCC_COMMON_CONF_OPTS += --enable-tls
  128. endif
  129. ifeq ($(BR2_GCC_ENABLE_LTO),y)
  130. HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto
  131. endif
  132. ifeq ($(BR2_PTHREADS_NONE),y)
  133. HOST_GCC_COMMON_CONF_OPTS += \
  134. --disable-threads \
  135. --disable-libitm \
  136. --disable-libatomic
  137. else
  138. HOST_GCC_COMMON_CONF_OPTS += --enable-threads
  139. endif
  140. # gcc 5 doesn't need cloog any more, see
  141. # https://gcc.gnu.org/gcc-5/changes.html and we don't support graphite
  142. # on GCC 4.9.x, so only isl is needed.
  143. ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
  144. HOST_GCC_COMMON_DEPENDENCIES += host-isl
  145. HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)
  146. else
  147. HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
  148. endif
  149. ifeq ($(BR2_arc),y)
  150. HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
  151. endif
  152. ifeq ($(BR2_SOFT_FLOAT),y)
  153. # only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
  154. # powerpc seems to be needing it as well
  155. ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
  156. HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
  157. endif
  158. endif
  159. # Determine arch/tune/abi/cpu options
  160. ifneq ($(GCC_TARGET_ARCH),)
  161. HOST_GCC_COMMON_CONF_OPTS += --with-arch="$(GCC_TARGET_ARCH)"
  162. endif
  163. ifneq ($(GCC_TARGET_ABI),)
  164. HOST_GCC_COMMON_CONF_OPTS += --with-abi="$(GCC_TARGET_ABI)"
  165. endif
  166. ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
  167. ifneq ($(GCC_TARGET_NAN),)
  168. HOST_GCC_COMMON_CONF_OPTS += --with-nan="$(GCC_TARGET_NAN)"
  169. endif
  170. endif
  171. ifneq ($(GCC_TARGET_FP32_MODE),)
  172. HOST_GCC_COMMON_CONF_OPTS += --with-fp-32="$(GCC_TARGET_FP32_MODE)"
  173. endif
  174. ifneq ($(GCC_TARGET_CPU),)
  175. HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(GCC_TARGET_CPU)
  176. endif
  177. ifneq ($(GCC_TARGET_FPU),)
  178. HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
  179. endif
  180. ifneq ($(GCC_TARGET_FLOAT_ABI),)
  181. HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
  182. endif
  183. ifneq ($(GCC_TARGET_MODE),)
  184. HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
  185. endif
  186. # Enable proper double/long double for SPE ABI
  187. ifeq ($(BR2_powerpc_SPE),y)
  188. HOST_GCC_COMMON_CONF_OPTS += \
  189. --enable-e500_double \
  190. --with-long-double-128
  191. endif
  192. # Set default to Secure-PLT to prevent run-time
  193. # generation of PLT stubs (supports RELRO and
  194. # SELinux non-exemem capabilities)
  195. ifeq ($(BR2_powerpc),y)
  196. HOST_GCC_COMMON_CONF_OPTS += --enable-secureplt
  197. endif
  198. # PowerPC64 big endian by default uses the elfv1 ABI, and PowerPC 64
  199. # little endian by default uses the elfv2 ABI. However, musl has
  200. # decided to use the elfv2 ABI for both, so we force the elfv2 ABI for
  201. # Power64 big endian when the selected C library is musl.
  202. ifeq ($(BR2_TOOLCHAIN_USES_MUSL)$(BR2_powerpc64),yy)
  203. HOST_GCC_COMMON_CONF_OPTS += \
  204. --with-abi=elfv2 \
  205. --without-long-double-128
  206. endif
  207. # Since glibc >= 2.26, poerpc64le requires double/long double which
  208. # requires at least gcc 6.2.
  209. # See sysdeps/powerpc/powerpc64le/configure.ac
  210. ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6)$(BR2_powerpc64le),yyy)
  211. HOST_GCC_COMMON_CONF_OPTS += \
  212. --with-long-double-128
  213. endif
  214. ifeq ($(BR2_s390x),y)
  215. HOST_GCC_COMMON_CONF_OPTS += \
  216. --with-long-double-128
  217. endif
  218. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
  219. # For gcc-initial, we need to tell gcc that the C library will be
  220. # providing the ssp support, as it can't guess it since the C library
  221. # hasn't been built yet.
  222. #
  223. # For gcc-final, the gcc logic to detect whether SSP support is
  224. # available or not in the C library is not working properly for
  225. # uClibc, so let's be explicit as well.
  226. HOST_GCC_COMMON_MAKE_OPTS = \
  227. gcc_cv_libc_provides_ssp=$(if $(BR2_TOOLCHAIN_HAS_SSP),yes,no)
  228. ifeq ($(BR2_CCACHE),y)
  229. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(GCC_DL_DIR)/$(GCC_SOURCE)
  230. # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned
  231. # and unversioned patches unconditionally. Moreover, to facilitate the
  232. # addition of gcc patches in BR2_GLOBAL_PATCH_DIR, we allow them to be
  233. # stored in a sub-directory called 'gcc' even if it's not technically
  234. # the name of the package.
  235. HOST_GCC_COMMON_CCACHE_HASH_FILES += \
  236. $(sort $(wildcard \
  237. package/gcc/$(GCC_VERSION)/*.patch \
  238. $(addsuffix /$($(PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  239. $(addsuffix /$($(PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  240. $(addsuffix /gcc/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  241. $(addsuffix /gcc/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))))
  242. ifeq ($(BR2_xtensa),y)
  243. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(ARCH_XTENSA_OVERLAY_TAR)
  244. endif
  245. ifeq ($(ARCH),powerpc)
  246. ifneq ($(BR2_SOFT_FLOAT),)
  247. HOST_GCC_COMMON_CCACHE_HASH_FILES += package/gcc/$(GCC_VERSION)/1000-powerpc-link-with-math-lib.patch.conditional
  248. endif
  249. endif
  250. # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR)
  251. # and a reference to the Buildroot git revision (BR2_VERSION_FULL),
  252. # so substitute those away.
  253. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
  254. printf '%s\n' $(subst $(HOST_DIR),@HOST_DIR@,\
  255. $(subst --with-pkgversion="Buildroot $(BR2_VERSION_FULL)",,$($(PKG)_CONF_OPTS))) \
  256. | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
  257. | cut -c -64 | tr -d '\n'`\"
  258. endif # BR2_CCACHE
  259. # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
  260. # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
  261. # *-gcc-nm and should be used instead of the real programs when -flto is
  262. # used. However, we should not add the toolchain wrapper for them, and they
  263. # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
  264. # *-ranlib and *-nm.
  265. # According to gfortran manpage, it supports all options supported by gcc, so
  266. # add gfortran to the list of the program called via the Buildroot wrapper.
  267. # Avoid that a .br_real is symlinked a second time.
  268. # Also create <arch>-linux-<tool> symlinks.
  269. define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
  270. $(Q)cd $(HOST_DIR)/bin; \
  271. for i in $(GNU_TARGET_NAME)-*; do \
  272. case "$$i" in \
  273. *.br_real) \
  274. ;; \
  275. *-ar|*-ranlib|*-nm) \
  276. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  277. ;; \
  278. *cc|*cc-*|*++|*++-*|*cpp|*-gfortran|*-gdc) \
  279. rm -f $$i.br_real; \
  280. mv $$i $$i.br_real; \
  281. ln -sf toolchain-wrapper $$i; \
  282. ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  283. ln -snf $$i.br_real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.br_real; \
  284. ;; \
  285. *) \
  286. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  287. ;; \
  288. esac; \
  289. done
  290. endef
  291. include $(sort $(wildcard package/gcc/*/*.mk))