sgerrand / alpine-pkg-glibc

A glibc compatibility layer package for Alpine Linux
2.04k stars 280 forks source link

Is alpine-pkg-glibc supports for latest alpine release 3.18 #204

Closed user21345 closed 9 months ago

user21345 commented 1 year ago

My application use below dependent libraries: linux-vdso.so.1 (0x00007ffd3c6ac000) libicuuc.so.44 => /libicuuc.so.44 (0x00007f7c6ce00000) libicui18n.so.44 => /libicui18n.so.44 (0x00007f7c6ca00000) libicudata.so.44 => /libicudata.so.44 (0x00007f7c6b800000) libnspr4.so => /libnspr4.so (0x00007f7c6b400000) libprldap60.so => /libprldap60.so (0x00007f7c6b000000) libldap60.so => /libldap60.so (0x00007f7c6ac00000) libplc4.so => /libplc4.so (0x00007f7c6a800000) libssldap60.so =>/libssldap60.so (0x00007f7c6a400000) libplds4.so => /libplds4.so (0x00007f7c6a000000) libssl3.so => /libssl3.so (0x00007f7c69c00000) libnss3.so => /libnss3.so (0x00007f7c69800000) libnssutil3.so => /libnssutil3.so (0x00007f7c69400000) libsoftokn3.so => /libsoftokn3.so (0x00007f7c69000000) libsqlite3.so => /libsqlite3.so (0x00007f7c68c00000) libssl_iw.so.3 => /libssl_iw.so.3 (0x00007f7c68800000) libcrypto_iw.so.3 => /libcrypto_iw.so.3 (0x00007f7c68200000) libnsl.so.1 => /usr/glibc-compat/lib/libnsl.so.1 (0x00007f7c6d1a1000) libpthread.so.0 => /usr/glibc-compat/lib/libpthread.so.0 (0x00007f7c6d19a000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f7c67fb2000) librt.so.1 => /usr/glibc-compat/lib/librt.so.1 (0x00007f7c6d195000) libdl.so.2 => /usr/glibc-compat/lib/libdl.so.2 (0x00007f7c6d190000) libz.so.1 => /lib/libz.so.1 (0x00007f7c6d175000) libpam.so.0 => /lib/libpam.so.0 (0x00007f7c6d166000) libcrypt.so.1 => /usr/glibc-compat/lib/libcrypt.so.1 (0x00007f7c6cdc7000) libfuse.so.2 => /usr/lib/libfuse.so.2 (0x00007f7c6c9c8000) libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f7c6d146000) libc.so.6 => /usr/glibc-compat/lib/libc.so.6 (0x00007f7c67da9000) libm.so.6 => /usr/glibc-compat/lib/libm.so.6 (0x00007f7c6c8e7000) libc.musl-x86_64.so.1 => /lib/libc.musl-x86_64.so.1 (0x00007f7c6c84c000) /lib64/ld-linux-x86-64.so.2 => /usr/glibc-compat/lib64/ld-linux-x86-64.so.2 (0x00007f7c6d1c2000)

With the above dependent libraries, if we launch the application, it gives segfault and not able to reach application main() function. Same application works in alpine 3.17.x version and gives SEGfault in alpine 3.18.

Will there be new version of alpine-pkg-glibc for alpine version 3.18?

sgerrand commented 1 year ago

I think that you're talking about two things here:

  1. Support for a glibc library which is compiled against libraries available in Alpine Linux 3.18
  2. The segmentation fault in your application

If you want support for the latter, would you please post the output of that segmentation fault error and details about the application you've built – ideally as a Dockerfile that I can use to reproduce the bug.

user21345 commented 1 year ago

Below are findings: 1) with glibc 2.33-r0 package attached crash_test given SIGSEGV on alpine version 3.18. It's working on 3.17.x and below versions. 2) with glibc 2.35-r1 package observed the same as above i.e SIGSEGV, with below workaround: mkdir -p /lib64 ln -sf /usr/glibc-compat/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

/usr/local/bin # ./crash_test Segmentation fault (core dumped)

Attached Dockerfile, crash_test.cpp and executable Dockerfile.txt Dockerfile.txt crash_test.zip

Steps to build crash_test.cpp: g++ -I . -c crash_test.cpp g++ -o crash_test crash_test.o -lpthread -lstdc++ -lrt -ldl -lz -lpam -lfuse -lnsl

NOTE: -lfuse and -lpam musl library leads to crash. if we remove -lfuse and -lpam, ./crash_test will work as expected.

user21345 commented 1 year ago

Any update on my request?

user21345 commented 1 year ago

@sgerrand: Any update on this issue?. Is the shared dockerfile helpful to reproduce the issue?.

harenber commented 1 year ago

Seing the same issue also while trying to get Jetbrains Toolbox to run. As soon as libfuse is being loaded, the application crashes. Here is an strace:

/tmp/jetbrains-toolbox-1.28.1.15219 $ strace ./jetbrains-toolbox 
execve("./jetbrains-toolbox", ["./jetbrains-toolbox"], 0x7ffce22999f0 /* 34 vars */) = 0
brk(NULL)                               = 0xa18000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffce23b5260) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/glibc-compat/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27663, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 27663, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6114555000
close(3)                                = 0
openat(AT_FDCWD, "/usr/glibc-compat/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\20\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=14416, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6114553000
mmap(NULL, 16424, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f611454e000
mmap(0x7f611454f000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f611454f000
mmap(0x7f6114550000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f6114550000
mmap(0x7f6114551000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f6114551000
close(3)                                = 0
openat(AT_FDCWD, "/usr/glibc-compat/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\20\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=14416, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 16424, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6114549000
mmap(0x7f611454a000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1000) = 0x7f611454a000
mmap(0x7f611454b000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f611454b000
mmap(0x7f611454c000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f611454c000
close(3)                                = 0
openat(AT_FDCWD, "/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\1\0\1\300\4\0\0\0\t\0\0\0\0\0\0\0"..., 48, 95792) = 48
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=100264, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 102512, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f611452f000
mmap(0x7f6114532000, 57344, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f6114532000
mmap(0x7f6114540000, 28672, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11000) = 0x7f6114540000
mmap(0x7f6114547000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f6114547000
close(3)                                = 0
openat(AT_FDCWD, "/usr/glibc-compat/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\327\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0Q\206y\333|\222;\242\300\360\354!\274KS\6"..., 68, 896) = 68
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2081544, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 2133136, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6114200000
mmap(0x7f611422c000, 1527808, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2c000) = 0x7f611422c000
mmap(0x7f61143a1000, 348160, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a1000) = 0x7f61143a1000
mmap(0x7f61143f6000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f5000) = 0x7f61143f6000
mmap(0x7f61143fc000, 52368, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f61143fc000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libc.musl-x86_64.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\363\266\5\0\0\0\0\0"..., 832) = 832
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\1\0\1\300\4\0\0\0\v\0\0\0\0\0\0\0"..., 48, 611496) = 48
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=617072, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 630944, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6114494000
mmap(0x7f61144a8000, 311296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7f61144a8000
mmap(0x7f61144f4000, 221184, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x60000) = 0x7f61144f4000
mmap(0x7f611452a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x95000) = 0x7f611452a000
mmap(0x7f611452c000, 8352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f611452c000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6114492000
arch_prctl(ARCH_SET_FS, 0x7f6114493000) = 0
set_tid_address(0x7f61144932d0)         = 11858
set_robust_list(0x7f61144932e0, 24)     = 0
rseq(0x7f61144939a0, 0x20, 0, 0x53053053) = 0
mprotect(0x7f611452a000, 4096, PROT_READ) = 0
mprotect(0x7f61143f6000, 12288, PROT_READ) = 0
mprotect(0x7f6114547000, 4096, PROT_READ) = 0
mprotect(0x7f611454c000, 4096, PROT_READ) = 0
mprotect(0x7f6114551000, 4096, PROT_READ) = 0
mprotect(0x7f6114591000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7f6114555000, 27663)           = 0
getrandom("\xa9\xf4\x25\x96\x2b\xbd\x5a\x8b", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0xa18000
brk(0xa39000)                           = 0xa39000
openat(AT_FDCWD, "/proc/self/exe", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=70332392, ...}, AT_EMPTY_PATH) = 0
read(3, "\177ELF\2\1\1\0AI\2\0\0\0\0\0\2\0>\0\1\0\0\0\220F@\0\0\0\0\0"..., 4096) = 4096
lseek(3, 0, SEEK_SET)                   = 0
read(3, "\177ELF\2\1\1\0AI\2\0\0\0\0\0\2\0>\0\1\0\0\0\220F@\0\0\0\0\0"..., 4096) = 4096
lseek(3, 184320, SEEK_SET)              = 184320
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
close(3)                                = 0
readlink("/proc/self/exe", "/tmp/jetbrains-toolbox-1.28.1.15"..., 4096) = 53
openat(AT_FDCWD, "/usr/glibc-compat/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27663, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 27663, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6114555000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libfuse.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\1\0\1\300\4\0\0\0\t\0\0\0\0\0\0\0"..., 48, 149528) = 48
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=227440, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 225632, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f611445a000
mmap(0x7f6114460000, 86016, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f6114460000
mmap(0x7f6114475000, 40960, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b000) = 0x7f6114475000
mmap(0x7f611447f000, 77824, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x25000) = 0x7f611447f000
close(3)                                = 0
mprotect(0x7f611447f000, 73728, PROT_READ) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x7030} ---
+++ killed by SIGSEGV +++
Segmentation fault

I cannot easily downgrade to 3.17 to check, as I'm running on bare metal and the machine is running other stuff.

user21345 commented 1 year ago

As workaround, u can downgrade only fuse version by adding 3.17 repositories to /etc/apk/repositories

harenber commented 1 year ago

@user21345 Thanks! That brings me a bit further, but now the Jetbrains Toolbox crashes with a SIGSEGV in its own libjvm. Setting a sticky also to the v3.17 version of linux-pam does not help against that. The strace doesn't give me any hint which Alpine package could be "problematic" for that.

However, I meanwhile figured out how to point the Jetbrains products to the OS's JVM, whic solves my current problem by avoiding using any glibc libraries.

Wyk72 commented 11 months ago

I've noticed this behaviour of glibc too: everything is fine in 3.17 and lower, everything segfaults in 3.18 and higher.

I suspect this has something to do with an Alpine 3.18 change in linker options to shrink binaries a little more.

From changelog Alpine 3.18 I read:

"DT_RELR

on x86, x86_64, and ppc64le, -Wl,-z,pack-relative-relocs is now added to the base LDFLAGS. this reduces elf (executable/shared-library) size by 10% on average.

however, these binaries are now not portable to other musl-based systems that have a musl older than 1.2.4, because older versions are incapable of loading these binaries."

I also read that this DT_RELR ELF tag is supported in glibc version 2.36 onwards:

Version 2.36

Major new features:

* Support for DT_RELR relative relocation format has been added to
  glibc.  This is a new ELF dynamic tag that improves the size of
  relative relocations in shared object files and position independent
  executables (PIE).  DT_RELR generation requires linker support for
  -z pack-relative-relocs option, which is supported for some targets
  in recent binutils versions.  Lazy binding doesn't apply to DT_RELR."

So I guess glibc 2.36+ is needed ? Just a wild guess but I think it's the root cause.

Wyk72 commented 11 months ago

I can confirm this is indeed the case.

Upgrading by-hand (i.e. overwriting the binary files into the container) witha glibc 2.37 (built with https://github.com/sgerrand/docker-glibc-builder that generates a 2.37 file) worked as expected and a glibc binary into an 3.18 Alpine container WORKED flawlessly.

A simple repack of the binary artifact would be sufficent.

user21345 commented 9 months ago

Replace glibc 2.37 binaries into alpine container solved the SIGSEGV issues and application libraries load issues. Need to regenerate glibc-compat apk's with glic 2.37 binaries.

Stiverton commented 8 months ago

I'm running into this problem as well. I don't understand how to install the glibc-bin.tar.gz that comes out of https://github.com/sgerrand/docker-glibc-builder. Can anyone help me understand?

Wyk72 commented 8 months ago

I'm running into this problem as well. I don't understand how to install the glibc-bin.tar.gz that comes out of https://github.com/sgerrand/docker-glibc-builder. Can anyone help me understand?

I simply extracted the .tar.gz archive into /tmp/ and overwritten files into /lib (glibc already installed in Alpine via the instructions in this git) with a simple cp -a , then rebooted. It worked flawlessly.

The tar.gz should be repacked into an .apk that can be installed via the standard Alpine tools, I don't know how to do it (yet) but it shouldn't be too hard, check docs.

someview commented 7 months ago

I think that you're talking about two things here:

  1. Support for a glibc library which is compiled against libraries available in Alpine Linux 3.18
  2. The segmentation fault in your application

If you want support for the latter, would you please post the output of that segmentation fault error and details about the application you've built – ideally as a Dockerfile that I can use to reproduce the bug.

Is there some progress about support apline3.18