toolchain-wrapper.mk 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 += -D__FILE__=\"\" -D__BASE_FILE__=\"\" -Wno-builtin-macro-redefined
  26. endif
  27. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_7),)
  28. TOOLCHAIN_WRAPPER_OPTS += -DBR_NEED_SOURCE_DATE_EPOCH
  29. endif
  30. endif
  31. # Disable -ftree-loop-distribute-patterns on microblaze to
  32. # workaround a compiler bug with gcc 10 and -O2, -Os or -O3.
  33. # https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=5879ab5fafedc8f6f9bfe95a4cf8501b0df90edd
  34. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97208
  35. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_10)$(BR2_microblaze),yy)
  36. TOOLCHAIN_WRAPPER_OPTS += -fno-tree-loop-distribute-patterns
  37. endif
  38. # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each flag is a
  39. # separate argument when used in execv() by the toolchain wrapper.
  40. TOOLCHAIN_WRAPPER_ARGS += \
  41. -DBR_ADDITIONAL_CFLAGS='$(foreach f,$(TOOLCHAIN_WRAPPER_OPTS),"$(f)"$(comma))'
  42. ifeq ($(BR2_CCACHE),y)
  43. TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE
  44. endif
  45. ifeq ($(BR2_x86_x1000),y)
  46. TOOLCHAIN_WRAPPER_ARGS += -DBR_OMIT_LOCK_PREFIX
  47. endif
  48. # Avoid FPU bug on XBurst CPUs
  49. ifeq ($(BR2_mips_xburst),y)
  50. # Before gcc 4.6, -mno-fused-madd was needed, after -ffp-contract is
  51. # needed
  52. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_6),y)
  53. TOOLCHAIN_WRAPPER_ARGS += -DBR_FP_CONTRACT_OFF
  54. else
  55. TOOLCHAIN_WRAPPER_ARGS += -DBR_NO_FUSED_MADD
  56. endif
  57. endif
  58. ifeq ($(BR2_CCACHE_USE_BASEDIR),y)
  59. TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_BASEDIR='"$(BASE_DIR)"'
  60. endif
  61. ifeq ($(BR2_PIC_PIE),y)
  62. TOOLCHAIN_WRAPPER_ARGS += -DBR2_PIC_PIE
  63. endif
  64. ifeq ($(BR2_RELRO_PARTIAL),y)
  65. TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_PARTIAL
  66. else ifeq ($(BR2_RELRO_FULL),y)
  67. TOOLCHAIN_WRAPPER_ARGS += -DBR2_RELRO_FULL
  68. endif
  69. define TOOLCHAIN_WRAPPER_BUILD
  70. $(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
  71. -s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
  72. toolchain/toolchain-wrapper.c \
  73. -o $(@D)/toolchain-wrapper
  74. endef
  75. define TOOLCHAIN_WRAPPER_INSTALL
  76. $(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper \
  77. $(HOST_DIR)/bin/toolchain-wrapper
  78. endef