nuclei_llvm.mk 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. ###
  44. else ifeq ($(STDCLIB),nostd)
  45. ### Handle cases when no standard system directories for header files
  46. COMMON_FLAGS += -nostdinc
  47. ###
  48. else ifeq ($(STDCLIB),nospec)
  49. ### Handle cases no specs configs are passed
  50. COMMON_FLAGS +=
  51. ###
  52. else
  53. LDLIBS += -lc_nano -lgcc
  54. ###
  55. endif
  56. ifneq ($(SEMIHOST),)
  57. ifneq ($(findstring libncrt,$(STDCLIB)),)
  58. LDLIBS += -lfileops_semi
  59. else
  60. LDLIBS += -lsemihost
  61. endif
  62. else
  63. ifneq ($(findstring libncrt,$(STDCLIB)),)
  64. ifneq ($(NCRTIO),)
  65. LDLIBS += -lfileops_$(NCRTIO)
  66. endif
  67. endif
  68. endif
  69. ## Link with standard c++ library
  70. LDLIBS += -lstdc++
  71. ## Heap and stack size settings
  72. ## It will define symbols only used in linker script
  73. ## __STACK_SIZE and __HEAP_SIZE are not a c marco
  74. ## they are ld symbols used by linker
  75. ifneq ($(STACKSZ),)
  76. LDFLAGS += -Wl,--defsym=__STACK_SIZE=$(STACKSZ)
  77. endif
  78. ifneq ($(HEAPSZ),)
  79. LDFLAGS += -Wl,--defsym=__HEAP_SIZE=$(HEAPSZ)
  80. endif
  81. ## SIMU=xlspike/qemu
  82. ### enable run on xlspike and qemu auto-exit if return from main
  83. ifneq ($(SIMU),)
  84. SIMULATION_MODE=SIMULATION_MODE_$(call uc, $(SIMU))
  85. COMMON_FLAGS += -DSIMULATION_MODE=$(SIMULATION_MODE)
  86. endif
  87. COMMON_FLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL)
  88. # Enable some experimental extension for llvm clang
  89. COMMON_FLAGS += -menable-experimental-extensions
  90. ## Append mtune options when RISCV_TUNE is defined
  91. ## It might be defined in SoC/<SOC>/build.mk, and can be overwritten by make
  92. ifneq ($(RISCV_TUNE),)
  93. COMMON_FLAGS +=
  94. endif
  95. # Disable auto vectorization when AUTOVEC=0
  96. # see https://llvm.org/docs/Vectorizers.html
  97. ifeq ($(AUTOVEC),0)
  98. COMMON_FLAGS += -fno-vectorize -fno-slp-vectorize
  99. endif
  100. ifneq ($(findstring newlib,$(STDCLIB)),)
  101. #LDFLAGS += -u _isatty -u _write -u _sbrk -u _read -u _close -u _fstat -u _lseek
  102. LDFLAGS += -u __on_exit_args -u __call_exitprocs
  103. endif
  104. # -nodefaultlibs to ignore the auto added -lc -lgloss in RISCV::Linker::ConstructJob of clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  105. LDFLAGS += -fuse-ld=lld -nodefaultlibs