diff --git a/meson.build b/meson.build index 79443130d..57be05479 100644 --- a/meson.build +++ b/meson.build @@ -1,10 +1,15 @@ project( 'toolbox', + 'c', version: '0.0.93', license: 'ASL 2.0', meson_version: '>= 0.40.0', ) +cc = meson.get_compiler('c') +add_project_arguments('-pthread', language: 'c') +add_project_link_arguments('-pthread', language: 'c') + go = find_program('go') go_md2man = find_program('go-md2man') shellcheck = find_program('shellcheck', required: false) diff --git a/src/go-build-wrapper b/src/go-build-wrapper index 8f84277ed..f061a1c5c 100755 --- a/src/go-build-wrapper +++ b/src/go-build-wrapper @@ -16,9 +16,9 @@ # -if [ "$#" -ne 3 ]; then +if [ "$#" -ne 4 ]; then echo "go-build-wrapper: wrong arguments" >&2 - echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION]" >&2 + echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION] [libc-wrappers.a]" >&2 exit 1 fi @@ -27,5 +27,5 @@ if ! cd "$1"; then exit 1 fi -go build -trimpath -ldflags "-X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2" +go build -trimpath -ldflags "-extldflags '-Wl,--wrap,pthread_sigmask $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2" exit "$?" diff --git a/src/libc-wrappers/libc-wrappers.c b/src/libc-wrappers/libc-wrappers.c new file mode 100644 index 000000000..cb755b96e --- /dev/null +++ b/src/libc-wrappers/libc-wrappers.c @@ -0,0 +1,42 @@ +/* + * Copyright © 2020 Red Hat Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + + +#if defined __aarch64__ +__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.17"); +#elif defined __arm__ +__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.4"); +#elif defined __i386__ +__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.0"); +#elif defined __powerpc64__ +__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.17"); +#elif defined __s390x__ +__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.2"); +#elif defined __x86_64__ +__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.2.5"); +#else +#error "Please specify symbol version for pthread_sigmask" +#endif + + +int +__wrap_pthread_sigmask (int how, const sigset_t *set, sigset_t *oldset) +{ + return pthread_sigmask (how, set, oldset); +} diff --git a/src/libc-wrappers/meson.build b/src/libc-wrappers/meson.build new file mode 100644 index 000000000..3984ce449 --- /dev/null +++ b/src/libc-wrappers/meson.build @@ -0,0 +1,8 @@ +sources = files( + 'libc-wrappers.c', +) + +libc_wrappers = static_library( + 'c-wrappers', + sources, +) diff --git a/src/meson.build b/src/meson.build index 770d6dc4f..fd5ec37d3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,3 +1,5 @@ +subdir('libc-wrappers') + go_build_wrapper_file = files('go-build-wrapper') go_build_wrapper_program = find_program('go-build-wrapper') @@ -27,7 +29,9 @@ custom_target( meson.current_source_dir(), meson.current_build_dir(), meson.project_version(), + libc_wrappers.full_path(), ], + depends: libc_wrappers, input: sources, install: true, install_dir: get_option('bindir'),