summaryrefslogtreecommitdiff
path: root/3rd-party/picolibc.patch
blob: fdaf59fd604edd9fb876b50413b955646c7daa8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 391d2360c..a466455a8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,7 +59,7 @@ endif()
 set(CMAKE_SYSTEM_SUB_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
 
 if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686" OR
-    ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") 
+    ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
   set(CMAKE_SYSTEM_PROCESSOR "x86")
 endif()
 
@@ -512,6 +512,24 @@ CHECK_INCLUDE_FILE(xtensa/config/core-isa.h _XTENSA_HAVE_CONFIG_CORE_ISA_H)
 
 configure_file(picolibc.h.in "${PICOLIBC_INCLUDE}/picolibc.h")
 
+set(DEFAULT_FLASH_ADDR 0x00000000)
+set(DEFAULT_FLASH_SIZE 0x00400000)
+set(DEFAULT_RAM_ADDR   0x20000000)
+set(DEFAULT_RAM_SIZE   0x00200000)
+set(DEFAULT_STACK_SIZE 0x00001000)
+set(DEFAULT_ALIGNMENT  8)
+
+set(BFD_START "")
+set(BFD_END "")
+set(LLD_START "/* For ld.lld: ")
+set(LLD_END "*/")
+set(TLS_PHDRS "tls_init PT_TLS;
+tls PT_TLS;")
+set(TLS_INIT_SEG "tls_init")
+
+configure_file(picolibc.ld.in "${PROJECT_BINARY_DIR}/picolibc.ld" @ONLY)
+set(PICOLIBC_LD "${PROJECT_BINARY_DIR}/picolibc.ld")
+
 set(INCLUDEDIR include)
 set(LIBDIR .)
 if(PICOLIBC_TLS)
@@ -524,7 +542,8 @@ set(ADDITIONAL_LIBS "")
 set(SPECS_EXTRA "")
 set(SPECS_ISYSTEM "-isystem ${PROJECT_BINARY_DIR}/${include}")
 set(SPECS_LIBPATH "-L${PROJECT_BINARY_DIR}")
-set(SPECS_STARTFILE "${PROJECT_BINARY_DIR}/crt0.o")
+set(SPECS_STARTFILE "@SPECS_STARTFILE@")
+
 string(APPEND SPECS_PRINTF "%{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=__f_vfprintf}"
   " %{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfscanf=__f_vfscanf}"
   " %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfprintf=__d_vfprintf}"
@@ -536,7 +555,13 @@ string(APPEND SPECS_PRINTF "%{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=__f
   )
 set(PREFIX "${PROJECT_BINARY_DIR}")
 
-configure_file(picolibc.specs.in "${PROJECT_BINARY_DIR}/picolibc.specs" @ONLY)
+configure_file(picolibc.specs.in "${PROJECT_BINARY_DIR}/picolibc.specs.in2" @ONLY)
+
+add_custom_command(
+	OUTPUT  "${PROJECT_BINARY_DIR}/picolibc.specs"
+	DEPENDS "${PROJECT_BINARY_DIR}/picolibc.specs.in2" picocrt
+	COMMAND sed "s,@SPECS_STARTFILE@,$<TARGET_OBJECTS:picocrt>,g" <"${PROJECT_BINARY_DIR}/picolibc.specs.in2" >"${PROJECT_BINARY_DIR}/picolibc.specs"
+)
 
 set(PICOLIBC_COMPILE_OPTIONS
   "-nostdlib"
@@ -571,7 +596,8 @@ picolibc_supported_compile_options(
   "-fsignaling-nans"
   )
 
-add_library(c STATIC)
+add_library(c STATIC
+	"${PROJECT_BINARY_DIR}/picolibc.specs")
 
 target_compile_options(c PRIVATE ${PICOLIBC_COMPILE_OPTIONS})
 
@@ -586,6 +612,8 @@ define_property(GLOBAL PROPERTY PICOLIBC_HEADERS
 
 add_subdirectory(newlib)
 
+add_subdirectory(picocrt)
+
 install(TARGETS c
   LIBRARY DESTINATION lib
   PUBLIC_HEADER DESTINATION include)
@@ -597,7 +625,6 @@ if(TESTS)
   # semihosting-based tests
 
   add_subdirectory(semihost)
-  add_subdirectory(picocrt)
 
   set(PICOCRT_OBJ $<TARGET_OBJECTS:picocrt>)
   set(PICOCRT_SEMIHOST_OBJ $<TARGET_OBJECTS:picocrt-semihost>)