nuclei_llvm.mk 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. COMPILE_PREFIX ?= riscv64-unknown-elf-
  2. CC := $(COMPILE_PREFIX)clang
  3. CXX := $(COMPILE_PREFIX)clang++
  4. OBJDUMP := $(COMPILE_PREFIX)objdump
  5. OBJCOPY := $(COMPILE_PREFIX)objcopy
  6. # use gnu gdb to debug or upload
  7. GDB := $(COMPILE_PREFIX)gdb
  8. AR := llvm-ar
  9. SIZE := llvm-size
  10. OPENOCD := openocd
  11. # Handle standard c library selection variable STDCLIB
  12. ifneq ($(findstring newlib,$(STDCLIB)),)
  13. ### Handle cases when STDCLIB variable has newlib in it
  14. ifeq ($(STDCLIB),newlib_full)
  15. LDLIBS += -lc -lgcc
  16. else ifeq ($(STDCLIB),newlib_fast)
  17. LDLIBS += -lc_nano -lgcc
  18. STDCLIB_LDFLAGS += -u _printf_float -u _scanf_float
  19. COMMON_FLAGS += -isystem=/include/newlib-nano
  20. else ifeq ($(STDCLIB),newlib_small)
  21. LDLIBS += -lc_nano -lgcc
  22. STDCLIB_LDFLAGS += -u _printf_float
  23. COMMON_FLAGS += -isystem=/include/newlib-nano
  24. else ifeq ($(STDCLIB),newlib_nano)
  25. LDLIBS += -lc_nano -lgcc
  26. # work around for relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]; references _printf_float when compile with rv64
  27. # so with this change below, newlib_nano = newlib_small now
  28. STDCLIB_LDFLAGS += -u _printf_float
  29. COMMON_FLAGS += -isystem=/include/newlib-nano
  30. else
  31. LDLIBS += -lc_nano -lgcc
  32. # work around for relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]; references _printf_float when compile with rv64
  33. STDCLIB_LDFLAGS += -u _printf_float
  34. COMMON_FLAGS += -isystem=/include/newlib-nano
  35. endif
  36. ###
  37. else ifneq ($(findstring libncrt,$(STDCLIB)),)
  38. ### Handle cases when STDCLIB variable has libncrt in it
  39. LDLIBS += -l$(patsubst lib%,%,$(STDCLIB))
  40. ifneq ($(NCRTHEAP),)
  41. LDLIBS += -lheapops_$(NCRTHEAP)
  42. endif
  43. # https://github.com/llvm/llvm-project/pull/82084/files#r2387373311
  44. COMMON_FLAGS += -isystem=/include/libncrt
  45. ###
  46. else ifeq ($(STDCLIB),nostd)
  47. ### Handle cases when no standard system directories for header files
  48. COMMON_FLAGS += -nostdinc
  49. ###
  50. else ifeq ($(STDCLIB),nospec)
  51. ### Handle cases no specs configs are passed
  52. COMMON_FLAGS +=
  53. ###
  54. else
  55. LDLIBS += -lc_nano -lgcc
  56. ###
  57. endif
  58. ifneq ($(SEMIHOST),)
  59. ifneq ($(findstring libncrt,$(STDCLIB)),)
  60. LDLIBS += -lfileops_semi
  61. else
  62. LDLIBS += -lsemihost
  63. endif
  64. else
  65. ifneq ($(findstring libncrt,$(STDCLIB)),)
  66. ifneq ($(NCRTIO),)
  67. LDLIBS += -lfileops_$(NCRTIO)
  68. endif
  69. endif
  70. endif
  71. ## Link with standard c++ library
  72. LDLIBS += -lstdc++
  73. ## Heap and stack size settings
  74. ## It will define symbols only used in linker script
  75. ## __STACK_SIZE and __HEAP_SIZE are not a c marco
  76. ## they are ld symbols used by linker
  77. ifneq ($(STACKSZ),)
  78. LDFLAGS += -Wl,--defsym=__STACK_SIZE=$(STACKSZ)
  79. endif
  80. ifneq ($(HEAPSZ),)
  81. LDFLAGS += -Wl,--defsym=__HEAP_SIZE=$(HEAPSZ)
  82. endif
  83. ## SIMU=xlspike/qemu
  84. ### enable run on xlspike and qemu auto-exit if return from main
  85. ifneq ($(SIMU),)
  86. SIMULATION_MODE=SIMULATION_MODE_$(call uc, $(SIMU))
  87. COMMON_FLAGS += -DSIMULATION_MODE=$(SIMULATION_MODE)
  88. endif
  89. COMMON_FLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL)
  90. # Enable some experimental extension for llvm clang
  91. COMMON_FLAGS += -menable-experimental-extensions
  92. ## Append mtune options when RISCV_TUNE is defined
  93. ## It might be defined in SoC/<SOC>/build.mk, and can be overwritten by make
  94. ifneq ($(RISCV_TUNE),)
  95. COMMON_FLAGS +=
  96. endif
  97. # Disable auto vectorization when AUTOVEC=0
  98. # see https://llvm.org/docs/Vectorizers.html
  99. ifeq ($(AUTOVEC),0)
  100. COMMON_FLAGS += -fno-vectorize -fno-slp-vectorize
  101. endif
  102. ifneq ($(findstring newlib,$(STDCLIB)),)
  103. #LDFLAGS += -u _isatty -u _write -u _sbrk -u _read -u _close -u _fstat -u _lseek
  104. LDFLAGS += -u __on_exit_args -u __call_exitprocs
  105. endif
  106. # -nodefaultlibs to ignore the auto added -lc -lgloss in RISCV::Linker::ConstructJob of clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  107. LDFLAGS += -fuse-ld=lld -nodefaultlibs