Skip to content

Commit

Permalink
tests: statically link crtbegin.o and crtend.o from the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcunt committed Jan 24, 2025
1 parent 942c050 commit c5f7691
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,39 @@ endif
test_override_options = ['b_sanitize=none']

if library_type == 'static'
c_compiler = meson.get_compiler('c')
searchdirs = run_command(c_compiler.cmd_array(), '-print-search-dirs',
check: true).stdout()
searchdirs_arr = searchdirs.split('\n')
searchline = 'libraries: ='
searchpaths = ''

foreach line : searchdirs_arr
if line.startswith(searchline)
searchpaths = line.strip(searchline)
break
endif
endforeach

if searchpaths == ''
error('could not find compiler-specific library directory')
endif

searchpaths_arr = searchpaths.split(':')
crtpath = ''
fs = import('fs')
foreach path : searchpaths_arr
if fs.exists(path / 'crtbegin.o')
crtpath = path
break
endif
endforeach

if crtpath == ''
error('could not find crtbegin.o/crtend.o')
endif
test_sources += files(crtpath / 'crtbegin.o', crtpath / 'crtend.o')

libc_dep = declare_dependency(
include_directories: libc_include_dirs,
link_with: libc_static,
Expand Down

0 comments on commit c5f7691

Please sign in to comment.