Skip to content

Commit

Permalink
misc: Replace libgcc with cc-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Nov 7, 2024
1 parent 6a9f25e commit 7af6746
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
39 changes: 15 additions & 24 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
)
Expand All @@ -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()
Expand All @@ -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],
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions subprojects/cc-runtime.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
directory = cc-runtime
url = https://github.com/osdev0/cc-runtime.git
revision = trunk

0 comments on commit 7af6746

Please sign in to comment.