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

libc-wrappers: Ensure binaries built on Fedora 35 run on older Fedoras #829

Closed
wants to merge 4 commits into from
Closed
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: 3 additions & 1 deletion src/go-build-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#


readonly LIBC_WRAPPERS="--wrap,__libc_start_main,--wrap,pthread_attr_getstacksize,--wrap,pthread_create,--wrap,pthread_detach,--wrap,pthread_sigmask"

if [ "$#" -ne 4 ]; then
echo "go-build-wrapper: wrong arguments" >&2
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION] [libc-wrappers.a]" >&2
Expand All @@ -27,5 +29,5 @@ 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,$LIBC_WRAPPERS $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
exit "$?"
146 changes: 146 additions & 0 deletions src/libc-wrappers/libc-wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,155 @@
*/


#include <link.h>
#include <pthread.h>
#include <signal.h>


/*
* __libc_start_main < GLIBC_2.34
*/


struct startup_info
{
void *sda_base;
int (*main) (int, char **, char **, void *);
int (*init) (int, char **, char **, void *);
void (*fini) (void);
};

extern int __libc_start_main (int argc,
char **argv,
char **ev,
ElfW (auxv_t) * auxvec,
void (*rtld_fini) (void),
struct startup_info * stinfo,
char **stack_on_entry);


#if defined __aarch64__
__asm__(".symver __libc_start_main,__libc_start_main@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver __libc_start_main,__libc_start_main@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver __libc_start_main,__libc_start_main@GLIBC_2.0");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver __libc_start_main,__libc_start_main@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver __libc_start_main,__libc_start_main@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver __libc_start_main,__libc_start_main@GLIBC_2.2.5");
#else
#error "Please specify symbol version for __libc_start_main"
#endif


int
__wrap___libc_start_main (int argc,
char **argv,
char **ev,
ElfW (auxv_t) * auxvec,
void (*rtld_fini) (void),
struct startup_info * stinfo,
char **stack_on_entry)
{
return __libc_start_main (argc, argv, ev, auxvec, rtld_fini, stinfo, stack_on_entry);
}


/*
* pthread_attr_getstacksize < GLIBC_2.34
*/


#if defined __aarch64__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.1");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.2.5");
#else
#error "Please specify symbol version for pthread_attr_getstacksize"
#endif


int
__wrap_pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
{
return pthread_attr_getstacksize (attr, stacksize);
}


/*
* pthread_create < GLIBC_2.34
*/


#if defined __aarch64__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.1");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver pthread_create,pthread_create@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.2.5");
#else
#error "Please specify symbol version for pthread_create"
#endif


int
__wrap_pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
{
return pthread_create(thread, attr, start_routine, arg);
}


/*
* pthread_detach < GLIBC_2.34
*/


#if defined __aarch64__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.0");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.2.5");
#else
#error "Please specify symbol version for pthread_detach"
#endif


int
__wrap_pthread_detach (pthread_t thread)
{
return pthread_detach (thread);
}


/*
* pthread_sigmask < GLIBC_2.32
*/


#if defined __aarch64__
__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.17");
#elif defined __arm__
Expand Down