nuclei_llvm.mk 3.3 KB

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