@@ -110,26 +110,26 @@ bool setup(const str_t filepath, const char *triple) {
110110}
111111
112112str_buf_t make_content (const struct context * ctx ) {
113- #define TEMPLATE \
114- "# Automatically generated configuration file used by 'blc' compiler.\n" \
115- "# To generate new one use 'blc --configure' command.\n\n" \
116- "# Compiler version, this should match the executable version 'blc --version'.\n" \
117- "version: \"{str}\"\n\n" \
113+ #define TEMPLATE \
114+ "# Automatically generated configuration file used by 'blc' compiler.\n" \
115+ "# To generate new one use 'blc --configure' command.\n\n" \
116+ "# Compiler version, this should match the executable version 'blc --version'.\n" \
117+ "version: \"{str}\"\n\n" \
118118 "# Main API directory containing all modules and source files. This option is mandatory.\n" \
119- "lib_dir: \"{str}\"\n" \
120- "\n" \
121- "# Current default environment configuration.\n" \
122- "{s}:\n" \
123- " # Platform operating system preload file (relative to 'lib_dir').\n" \
124- " preload_file: \"{str}\"\n" \
125- " # Optional path to the linker executable, 'lld' linker is used by default on some " \
126- "platforms.\n" \
127- " linker_executable: \"{str}\"\n" \
128- " # Linker flags and options used to produce executable binaries.\n" \
129- " linker_opt_exec: \"{str}\"\n" \
130- " # Linker flags and options used to produce shared libraries.\n" \
131- " linker_opt_shared: \"{str}\"\n" \
132- " # File system location where linker should lookup for dependencies.\n" \
119+ "lib_dir: \"{str}\"\n" \
120+ "\n" \
121+ "# Current default environment configuration.\n" \
122+ "{s}:\n" \
123+ " # Platform operating system preload file (relative to 'lib_dir').\n" \
124+ " preload_file: \"{str}\"\n" \
125+ " # Optional path to the linker executable, 'lld' linker is used by default on some " \
126+ "platforms.\n" \
127+ " linker_executable: \"{str}\"\n" \
128+ " # Linker flags and options used to produce executable binaries.\n" \
129+ " linker_opt_exec: \"{str}\"\n" \
130+ " # Linker flags and options used to produce shared libraries.\n" \
131+ " linker_opt_shared: \"{str}\"\n" \
132+ " # File system location where linker should lookup for dependencies.\n" \
133133 " linker_lib_path: \"{str}\"\n\n"
134134
135135 str_buf_t tmp = get_tmp_str ();
@@ -219,6 +219,25 @@ bool x86_64_pc_linux_gnu(struct context *ctx) {
219219 }
220220 }
221221
222+ // Resolve c runtime
223+ #define FIND_AND_APPEND_CRT (N ) \
224+ { \
225+ str_buf_t crt = execute("gcc -print-file-name=" N); \
226+ if (!normalize_path(&crt)) { \
227+ builder_error("C runtime not found on the system. Defaulting to '/usr/lib/" N "'."); \
228+ str_buf_append(&runtime, make_str_from_c("/usr/lib/" N)); \
229+ } else { \
230+ str_buf_append_fmt(&runtime, "{str} ", crt); \
231+ } \
232+ put_tmp_str(crt); \
233+ }
234+
235+ FIND_AND_APPEND_CRT ("crt1.o" );
236+ FIND_AND_APPEND_CRT ("crti.o" );
237+ FIND_AND_APPEND_CRT ("crtn.o" );
238+
239+ #undef FIND_AND_APPEND_CRT
240+
222241 ctx -> linker_opt_exec = scprint (& ctx -> cache , "{str} {str}" , runtime , LINKER_OPT_EXEC );
223242 ctx -> linker_opt_shared = scprint (& ctx -> cache , "{str}" , LINKER_OPT_SHARED );
224243 ctx -> linker_lib_path = scprint (& ctx -> cache , "{str}" , lib_paths );
@@ -371,6 +390,11 @@ static bool arm64_apple_darwin(struct context *ctx) {
371390 str_buf_append_fmt (& optshared , "-macos_version_min {s32}.0 -ld_classic " , default_macos_min_version );
372391 }
373392
393+ // Resolve c runtime
394+ str_buf_append_fmt (& optexec , "{str}/usr/lib/crt1.o " , macos_sdk );
395+ str_buf_append_fmt (& optexec , "{str}/usr/lib/crti.o " , macos_sdk );
396+ str_buf_append_fmt (& optexec , "{str}/usr/lib/crtn.o " , macos_sdk );
397+
374398 str_buf_append (& optexec , LINKER_OPT_EXEC );
375399 str_buf_append (& optshared , LINKER_OPT_SHARED );
376400
0 commit comments