Skip to content

Commit

Permalink
build: Ensure that binaries are run against their build-time ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
debarshiray authored and HarryMichal committed Oct 21, 2021
1 parent 452dc79 commit b17f6c2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 62 deletions.
1 change: 1 addition & 0 deletions data/tmpfiles.d/toolbox.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
d /run/media 0755 root root - -
L /run/host - - - - ../
6 changes: 1 addition & 5 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',
)

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

0 comments on commit b17f6c2

Please sign in to comment.