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

build: Ensure that binaries are run against their build-time ABI #897

Merged
merged 2 commits into from
Oct 21, 2021
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
3 changes: 2 additions & 1 deletion data/tmpfiles.d/toolbox.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
d /run/media 0755 root root
d /run/media 0755 root root - -
L /run/host - - - - ../
8 changes: 2 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
project(
'toolbox',
'c',
version: '0.0.99.2',
license: 'ASL 2.0',
meson_version: '>= 0.42.0',
meson_version: '>= 0.53.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')
patchelf = find_program('patchelf')
shellcheck = find_program('shellcheck', required: false)
skopeo = find_program('skopeo', required: false)

Expand Down
1 change: 1 addition & 0 deletions playbooks/setup-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- golang-github-cpuguy83-md2man
- meson
- ninja-build
- patchelf
- podman
- skopeo
- systemd
Expand Down
17 changes: 14 additions & 3 deletions src/go-build-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#


if [ "$#" -ne 4 ]; then
if [ "$#" -ne 3 ]; then
echo "go-build-wrapper: wrong arguments" >&2
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION] [libc-wrappers.a]" >&2
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION]" >&2
exit 1
fi

Expand All @@ -27,5 +27,16 @@ if ! cd "$1"; then
exit 1
fi

go build -trimpath -ldflags "-extldflags '-Wl,--wrap,pthread_sigmask $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
go build -trimpath -ldflags "-extldflags '-Wl,-rpath,/run/host/usr/lib -Wl,-rpath,/run/host/usr/lib64' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"

if ! interpreter=$(patchelf --print-interpreter "$2/toolbox"); then
echo "go-build-wrapper: failed to read PT_INTERP from $2/toolbox" >&2
exit 1
fi

if ! patchelf --set-interpreter "/run/host$interpreter" "$2/toolbox"; then
echo "go-build-wrapper: failed to change PT_INTERP of $2/toolbox to /run/host$interpreter" >&2
exit 1
fi

exit "$?"
42 changes: 0 additions & 42 deletions src/libc-wrappers/libc-wrappers.c

This file was deleted.

8 changes: 0 additions & 8 deletions src/libc-wrappers/meson.build

This file was deleted.

4 changes: 0 additions & 4 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
subdir('libc-wrappers')

go_build_wrapper_file = files('go-build-wrapper')
go_build_wrapper_program = find_program('go-build-wrapper')

Expand Down Expand Up @@ -28,9 +26,7 @@ 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'),
Expand Down