Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsb: don't provide __dso_handle for static builds #1218

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions options/lsb/generic/dso_exit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ extern "C" void __cxa_finalize(void *dso) {
}
}

// In static builds, these should be provided by the crtbegin.o/crtend.o that
// is linked into the executable.
#ifndef MLIBC_STATIC_BUILD
// This is referenced by the compiler when generating constructors for global
// C++ objects so that it can call __cxa_finalize with a unique argument.
extern "C" { [[gnu::visibility("hidden")]] void *__dso_handle; }
Expand All @@ -56,6 +59,7 @@ extern "C" { [[gnu::visibility("hidden")]] void *__dso_handle; }
// In normal programs this call to __cxa_finalize is provided by libgcc.
__cxa_finalize(&__dso_handle);
}
#endif

void __mlibc_do_finalize() {
// Invoke any handlers registered with atexit (NOT associated with a DSO).
Expand Down
35 changes: 35 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ extra_cflags_test_cases = {
}

test_sources = []
test_objects = []
test_link_args = []
test_c_args = ['-D_GNU_SOURCE', '-fno-builtin']
use_pie = false
Expand All @@ -167,6 +168,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_objects += [crtpath / 'crtbegin.o', crtpath / 'crtend.o']

lzcunt marked this conversation as resolved.
Show resolved Hide resolved
libc_dep = declare_dependency(
include_directories: libc_include_dirs,
link_with: libc_static,
Expand Down Expand Up @@ -222,6 +256,7 @@ foreach test_name : all_test_cases
should_fail = fail_test_cases.contains(test_name)
exec = executable(test_exec_name, [test_name + '.c', test_sources],
dependencies: libc_dep,
objects: test_objects,
build_rpath: meson.build_root(),
override_options: test_override_options,
c_args: test_c_args,
Expand Down
Loading