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

Add Arch Linux toolbox image #520

Closed
wants to merge 29 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3983a29
Add Arch Linux toolbox image
Jul 31, 2020
1e694e2
Remove not needed Arch Linux packages
Jul 31, 2020
1ad280d
cmd/run: Make it more obvious when falling back to /bin/bash
debarshiray Aug 4, 2020
3b1d495
cmd/initContainer: Mount a tmpfs at /tmp to match the host
debarshiray Aug 4, 2020
884968b
Update issue templates
HarryMichal May 27, 2020
d3721f1
Add CONTRIBUTING.md
HarryMichal Jun 29, 2020
5094729
build: Install the tests
HarryMichal Jul 23, 2020
075fa00
cmd/initContainer: Add more information to errors from redirectPath
HarryMichal Aug 13, 2020
6251471
cmd/rm, pkg/podman: Move 'removeContainer' func to podman pkg
HarryMichal Jun 25, 2020
32a1d06
cmd/rmi, pkg/podman: Move 'removeImage' func to podman pkg
HarryMichal Jun 25, 2020
18dcb3b
README: Add missing parameter at the installation instructions
juanje Jul 27, 2020
86d9af9
images: Add fedora-toolbox image definition for Fedora 34
HarryMichal Aug 20, 2020
1bc3baf
build: Ensure binaries built on Fedora 33 run on Fedoras 32 & 31
debarshiray Aug 20, 2020
90f66f7
README.md: Mention that sudo(8) should work without a password
debarshiray Aug 21, 2020
efe5216
libc-wrappers: Tighten the definition of the ppc64le definition
debarshiray Aug 24, 2020
3ae818d
Silence SC2086
debarshiray Aug 24, 2020
1bd0e95
Prepare 0.0.94
debarshiray Aug 24, 2020
1f0f361
Combine pacman commands and remove unneeded packages
Aug 27, 2020
baac1a2
cmd/root: Rename a variable
debarshiray Aug 26, 2020
f78b039
cmd/root: Simplify code by using os.Create instead of syscall.Open
debarshiray Aug 26, 2020
71c0f55
cmd/root: Limit the scope of the error
debarshiray Aug 26, 2020
1cae7ae
cmd/initContainer: Try to handle config files that're absolute symlinks
HarryMichal May 27, 2020
b9064e1
profile.d: Warn if $TERM has no terminfo entry in the container
debarshiray Aug 28, 2020
b56674d
cmd/initContainer: Fix typo
martinpitt Aug 28, 2020
498ed69
Unbreak 'enter' on Fedora CoreOS
martinpitt Apr 7, 2020
7a6c9c8
cmd/initContainer: Split out the code to configure the user
debarshiray Aug 30, 2020
0bfcf8c
Unbreak 'sudo' inside toolbox containers with Podman 2.0.5
debarshiray Aug 30, 2020
750c8be
Prepare 0.0.95
debarshiray Aug 30, 2020
69afeea
pkg/utils: Update default release to 31 for non-fedora hosts
ljrk0 Aug 30, 2020
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
Prev Previous commit
Next Next commit
build: Ensure binaries built on Fedora 33 run on Fedoras 32 & 31
The /usr/bin/toolbox binary is not only used to interact with toolbox
containers and images from the host. It's also used as the entry point
of the containers by bind mounting the binary from the host into the
container. This means that the /usr/bin/toolbox binary on the host must
also work inside the container, even if they have different operating
systems.

In the past, this worked perfectly well with the POSIX shell
implementation because it got intepreted by whichever /bin/sh was
available.

The Go implementation also mostly worked so far because it's largely
statically linked, with the notable exception of the standard C
library. However, recently glibc-2.32, which is used by Fedora 33
onwards, added a new version of the pthread_sigmask symbol [1] as part
of the libpthread removal project:
  $ objdump -T /usr/bin/toolbox | grep GLIBC_2.32
  0000000000000000      DO *UND*	0000000000000000  GLIBC_2.32
    pthread_sigmask

This means that /usr/bin/toolbox binaries built against glibc-2.32 on
newer Fedoras pick up the latest version of the symbol and fail to run
against older glibcs in older Fedoras.

One way to fix this is to disable the use of any C code from Go by
using the CGO_ENABLED environment variable [2]. However, this can
negatively impact packages like "os/user" [3] and "net" [4], where the
more featureful glibc APIs will be replaced by more limited
equivalents written only in Go.

Instead, since glibc uses symbol versioning, it's better to tell the
Go toolchain to avoid linking against any symbols from glibc-2.32.

This was accomplished by a few linker tricks:

  * The GNU ld linker's --wrap flag was used when building the Go code
    to divert pthread_sigmask invocations from Go to another function
    called __wrap_pthread_sigmask.

  * A static library was added to provide this __wrap_pthread_sigmask
    function, which forwards calls to the actual pthread_sigmask API in
    glibc. This library itself was not linked with --wrap, and
    specifies the latest permissible version of the pthread_sigmask
    symbol from glibc for each architecture. Currently, the list of
    architectures covers the ones that Fedora builds for.

  * The Go cmd/link linker was switched to external mode [5]. This
    ensures that the final object file containing all the Go code gets
    linked to the standard C library and the wrapper static library by
    the GNU ld linker for the --wrap flag to kick in.

Based on ideas from Ondřej Míchal.

[1] glibc commit c6663fee4340291c
    https://sourceware.org/git/?p=glibc.git;a=commit;h=c6663fee4340291c

[2] https://golang.org/cmd/cgo/

[3] https://golang.org/pkg/os/user/

[4] https://golang.org/pkg/net/

[5] https://golang.org/src/cmd/cgo/doc.go

#529
debarshiray authored and Erazem Kokot committed Aug 27, 2020

Unverified

No user is associated with the committer email.
commit 1bc3baf43ba00defb56aeb827f05e6d7b2dc39f6
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions src/go-build-wrapper
Original file line number Diff line number Diff line change
@@ -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 "$?"
42 changes: 42 additions & 0 deletions src/libc-wrappers/libc-wrappers.c
Original file line number Diff line number Diff line change
@@ -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 <signal.h>


#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);
}
8 changes: 8 additions & 0 deletions src/libc-wrappers/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources = files(
'libc-wrappers.c',
)

libc_wrappers = static_library(
'c-wrappers',
sources,
)
4 changes: 4 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -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'),