toolchain-wrapper.mk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ################################################################################
  2. #
  3. # definition of the toolchain wrapper build commands
  4. #
  5. ################################################################################
  6. # We use --hash-style=both to increase the compatibility of the generated
  7. # binary with older platforms, except for MIPS, where the only acceptable
  8. # hash style is 'sysv'
  9. ifeq ($(findstring mips,$(HOSTARCH)),mips)
  10. TOOLCHAIN_WRAPPER_HASH_STYLE = sysv
  11. else
  12. TOOLCHAIN_WRAPPER_HASH_STYLE = both
  13. endif
  14. TOOLCHAIN_WRAPPER_ARGS = $($(PKG)_TOOLCHAIN_WRAPPER_ARGS)
  15. TOOLCHAIN_WRAPPER_ARGS += -DBR_SYSROOT='"$(STAGING_SUBDIR)"'
  16. TOOLCHAIN_WRAPPER_OPTS = \
  17. $(ARCH_TOOLCHAIN_WRAPPER_OPTS) \
  18. $(call qstrip,$(BR2_SSP_OPTION)) \
  19. $(call qstrip,$(BR2_TARGET_OPTIMIZATION))
  20. ifeq ($(BR2_REPRODUCIBLE),y)
  21. TOOLCHAIN_WRAPPER_OPTS += -Wl,--build-id=none
  22. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
  23. TOOLCHAIN_WRAPPER_OPTS += -ffile-prefix-map=$(BASE_DIR)=buildroot
  24. else
  25. TOOLCHAIN_WRAPPER_OPTS += -fdebug-prefix-map=$(BASE_DIR)=buildroot
  26. TOOLCHAIN_WRAPPER_OPTS += -D__FILE__=\"\" -D__BASE_FILE__=\"\" -Wno-builtin-macro-redefined
  27. endif
  28. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_7),)
  29. TOOLCHAIN_WRAPPER_OPTS += -DBR_NEED_SOURCE_DATE_EPOCH
  30. endif
  31. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_6),)
  32. TOOLCHAIN_WRAPPER_OPTS += -gno-record-gcc-switches
  33. endif
  34. endif
  35. # Disable -ftree-loop-distribute-patterns on microblaze to
  36. # workaround a compiler bug with gcc 10 and -O2, -Os or -O3.
  37. # https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=5879ab5fafedc8f6f9bfe95a4cf8501b0df90edd
  38. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97208
  39. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_10)$(BR2_microblaze),yy)
  40. TOOLCHAIN_WRAPPER_OPTS += -fno-tree-loop-distribute-patterns
  41. endif
  42. # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each flag is a
  43. # separate argument when used in execv() by the toolchain wrapper.
  44. TOOLCHAIN_WRAPPER_ARGS += \
  45. -DBR_ADDITIONAL_CFLAGS='$(foreach f,$(TOOLCHAIN_WRAPPER_OPTS),"$(f)"$(comma))'
  46. ifeq ($(BR2_CCACHE),y)
  47. TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE
  48. endif
  49. ifeq ($(BR2_x86_x1000),y)
  50. TOOLCHAIN_WRAPPER_ARGS += -DBR_OMIT_LOCK_PREFIX
  51. endif
  52. # Avoid FPU bug on XBurst CPUs
  53. ifeq ($(BR2_mips_xburst),y)
  54. # Before gcc 4.6, -mno-fused-madd was needed, after -ffp-contract is
  55. # needed
  56. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_6),y)
  57. TOOLCHAIN_WRAPPER_ARGS += -DBR_FP_CONTRACT_OFF
  58. else
  59. TOOLCHAIN_WRAPPER_ARGS += -DBR_NO_FUSED_MADD
  60. endif
  61. endif
  62. ifeq ($(BR2_CCACHE_USE_BASEDIR),y)
  63. TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_BASEDIR='"$(BASE_DIR)"'
  64. endif
  65. ifeq ($(BR2_PIC_PIE),y)
  66. TOOLCHAIN_WRAPPER_ARGS += -DBR2_PIC_PIE
  67. endif
  68. ifeq ($(BR2_RELRO_PARTIAL),y)
  69. TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_PARTIAL
  70. else ifeq ($(BR2_RELRO_FULL),y)
  71. TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_FULL
  72. endif
  73. define TOOLCHAIN_WRAPPER_BUILD
  74. $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
  75. -s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
  76. toolchain/toolchain-wrapper.c \
  77. -o $(@D)/toolchain-wrapper
  78. endef
  79. define TOOLCHAIN_WRAPPER_INSTALL
  80. $(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper \
  81. $(HOST_DIR)/bin/toolchain-wrapper
  82. endef