From 7af6746393c4cc93101876ebe692789d23f9adfe Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 7 Nov 2024 11:30:49 +0100 Subject: [PATCH] misc: Replace libgcc with cc-runtime --- meson.build | 39 ++++++++++++++----------------------- meson_options.txt | 1 - subprojects/cc-runtime.wrap | 4 ++++ 3 files changed, 19 insertions(+), 25 deletions(-) create mode 100644 subprojects/cc-runtime.wrap diff --git a/meson.build b/meson.build index ab1fa1dfe2..9abd868407 100644 --- a/meson.build +++ b/meson.build @@ -30,7 +30,6 @@ no_headers = get_option('no_headers') library_type = get_option('default_library') build_tests = get_option('build_tests') build_tests_host_libc = get_option('build_tests_host_libc') -libgcc_dependency = get_option('libgcc_dependency') internal_conf = configuration_data() mlibc_conf = configuration_data() @@ -413,27 +412,18 @@ subdir('options/bsd') rtlib_deps = [] -if not headers_only - if libgcc_dependency - libgcc = meson.get_compiler('c').find_library('gcc', required: false) - - compiler_rt_name = 'libclang_rt.builtins-' + host_machine.cpu_family() - compiler_rt = meson.get_compiler('c').find_library(compiler_rt_name, required: false) - - if not compiler_rt.found() - compiler_rt_name = 'libclang_rt.builtins' - compiler_rt = meson.get_compiler('c').find_library(compiler_rt_name, required: false) - endif - - if libgcc.found() - rtlib_deps += libgcc - elif compiler_rt.found() - rtlib_deps += compiler_rt - else - error('neither libgcc nor ' + compiler_rt_name + ' was found') - endif - endif +ccrt = static_library( + 'ccrt', + dependencies: [ccrt_dep], + c_args: [ + '-fvisibility=hidden', + '-ffunction-sections', + '-fdata-sections', + ], + override_options: ['c_std=c11'], +) +if not headers_only ld_cpp_args = [ '-fvisibility=hidden', '-fvisibility-inlines-hidden', @@ -471,13 +461,14 @@ if not headers_only cpp_args: ld_cpp_args + static_cpp_args, include_directories: rtld_include_dirs, dependencies: rtld_deps + rtlib_deps, + link_with: [ccrt], install: false ) libc_static = static_library('c', libc_all_sources, cpp_args: static_cpp_args + ['-fno-stack-protector', libc_cpp_args], include_directories: libc_include_dirs, dependencies: libc_deps + rtlib_deps, - link_with: [ld_static_lib], + link_with: [ccrt, ld_static_lib], link_whole: [libc_sublibs, ld_static_lib], install: true ) @@ -488,6 +479,7 @@ if not headers_only cpp_args: ld_cpp_args, include_directories: rtld_include_dirs, dependencies: rtld_deps + rtlib_deps, + link_with: [ccrt], install: true ) hide_everything_ld = (meson.current_source_dir() @@ -496,7 +488,7 @@ if not headers_only cpp_args: [libc_cpp_args], include_directories: libc_include_dirs, dependencies: libc_deps + rtlib_deps, - link_with: [ld_shared_lib], + link_with: [ccrt, ld_shared_lib], link_whole: libc_sublibs, link_args: ['-Wl,--version-script,' + hide_everything_ld], link_depends: [hide_everything_ld], @@ -526,7 +518,6 @@ summary_info += {'Linux option': get_option('linux_option')} summary_info += {'glibc option': get_option('glibc_option')} summary_info += {'BSD option': get_option('bsd_option')} summary_info += {'debug allocator': get_option('debug_allocator')} -summary_info += {'libgcc dependency': libgcc_dependency} summary(summary_info, bool_yn: true, section: 'mlibc options') if build_tests diff --git a/meson_options.txt b/meson_options.txt index 0902c56d90..cc08d3133c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -6,7 +6,6 @@ option('posix_option', type: 'feature', value : 'auto') option('linux_option', type: 'feature', value : 'auto') option('glibc_option', type: 'feature', value : 'auto') option('bsd_option', type: 'feature', value : 'auto') -option('libgcc_dependency', type : 'boolean', value : true) option('linux_kernel_headers', type: 'string', value : '') option('default_library_paths', type: 'array', value: []) option('debug_allocator', type : 'boolean', value : false, diff --git a/subprojects/cc-runtime.wrap b/subprojects/cc-runtime.wrap new file mode 100644 index 0000000000..d4e1e513e2 --- /dev/null +++ b/subprojects/cc-runtime.wrap @@ -0,0 +1,4 @@ +[wrap-git] +directory = cc-runtime +url = https://github.com/osdev0/cc-runtime.git +revision = trunk