Recent

Author Topic: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found  (Read 1451 times)

fedkad

  • Full Member
  • ***
  • Posts: 159
I am running "Lazarus 2.2.0 / FPC 3.2.2 / x86_64-linux-gtk2" on Ubuntu 21.10. The code compiled under this environment, when attempted to be run on a slightly older (but, still supported) version of Linux, for example Debian 10 will give an error like this:

./my_program: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./my_program)

How can I create Linux executable code that can be run on any version of GLIBC smaller than 2.34?

Note: "objdump -T my_program | grep -i glibc" output is something like this:

0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 wcrtomb
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 wcscoll
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.34  dlerror
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 setenv
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 setlocale
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 strcoll
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.34  dlopen
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 iconv_close
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 mbrlen
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.34  dlclose
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 mbrtowc
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.34  __libc_start_main
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.34  dlsym
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 iconv
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 iconv_open
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 nl_langinfo
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 towlower
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.34  dladdr
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 __errno_location
0000000000000000      DF *UND*   0000000000000000  GLIBC_2.2.5 towupper
0000000000000000  w   DF *UND*   0000000000000000  GLIBC_2.2.5 __cxa_finalize
« Last Edit: March 28, 2022, 04:01:58 pm by fedkad »
Lazarus 2.2.0 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1983
  • Former Delphi 1-7, 10.2 user
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #1 on: March 28, 2022, 04:07:18 pm »
The obvious answer is to statically link the needed libraries rather than loading them dynamically. The most significant advantage of static linking is that the application can be certain that all its libraries are present and that they are the correct version. Static linking of libraries also allows the application to be contained in a single executable file, simplifying distribution and installation. Also with static linking, only those parts of the library that are directly and indirectly referenced by the target executable are included in the executable. With dynamic libraries, the entire library is loaded, as it is not known in advance which functions will be used by the application.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.4
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.4

PascalDragon

  • Hero Member
  • *****
  • Posts: 4164
  • Compiler Developer
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #2 on: March 29, 2022, 10:24:04 am »
How can I create Linux executable code that can be run on any version of GLIBC smaller than 2.34?

By compiling it on a system that has an older GLIBC. This is simply how things work on Linux or ELF files in general. See also Jonas Maebe's answer here.

fedkad

  • Full Member
  • ***
  • Posts: 159
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #3 on: March 29, 2022, 10:31:33 am »
Thanks for the answers. I was expecting a compile and/or link option that will prevent the usage of GLIBC 2.34.
Lazarus 2.2.0 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 891
  • Professional amateur ;-P
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #4 on: March 29, 2022, 11:07:54 am »
Hey Fedkad,

Thanks for the answers. I was expecting a compile and/or link option that will prevent the usage of GLIBC 2.34.

I've had the same issue since I'm also in Ubuntu 21.10 and I've noticed this quite a while ago.

I'm not sure the lower version `libc` is still installed in the system since I never bothered to actually go look, but if it still is, due to some relic binary that cannot link to 2.34, there could be a solution.

The solution I've thought about is to do with messing around `fpc.cfg` to have `libc` served from another folder.
I'm not quite sure if this is possible, since it would have to be passed to the lnker, but if possible, this would solve the problem.

In any case, this would be a case for the more experienced Free Pascal users on this forum to pitch in and give some suggestions of the if its possible OR how to go about it.

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.10 64b Dark Theme
http://github.com/gcarreno

dbannon

  • Hero Member
  • *****
  • Posts: 2044
    • tomboy-ng, a rewrite of the classic Tomboy
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #5 on: March 29, 2022, 11:22:55 am »
Seems strange, I build my app on an U20.04 VM and it has libc6 2.31 and the resulting binary works fine on U16.04 and its a lot older 2.23 libc6.  Thats a far bigger jump than fedkad mentions.

Is there some more significant change taken place with 2.34 ?

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

PascalDragon

  • Hero Member
  • *****
  • Posts: 4164
  • Compiler Developer
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #6 on: March 29, 2022, 01:24:06 pm »
Is there some more significant change taken place with 2.34 ?

Yes, there is. They changed how the initialization works and thus an older libc with binaries compiled for a newer libc would lead to possibly hard to debug problems, because the initializers and finalizers of the binaries wouldn't be run.

The last change with a versioned symbol was with 2.1, though that probably wouldn't affect FPC and then 2.0 which would affect FPC (thus you can't use a FPC compiled binary compiled on a system with a glibc < 2.34 with a glibc older than 2.0).

dbannon

  • Hero Member
  • *****
  • Posts: 2044
    • tomboy-ng, a rewrite of the classic Tomboy
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #7 on: March 30, 2022, 12:36:09 am »
Hmm, I am not sure DP's explanation explains fedkad experience here though.

Debian Buster was updated to 2.28 recently (March 22) and that should work fine.

fedkad, is your Buster test system up to date ?

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

fedkad

  • Full Member
  • ***
  • Posts: 159
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #8 on: March 30, 2022, 10:43:37 am »
fedkad, is your Buster test system up to date ?

No. I tested my executable at: https://distrotest.net/Debian
Lazarus 2.2.0 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

dbannon

  • Hero Member
  • *****
  • Posts: 2044
    • tomboy-ng, a rewrite of the classic Tomboy
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #9 on: March 30, 2022, 10:56:38 am »
I would recommend Virtual Box, only real downside is diskspace used by all the VMs you end up keeping.

And, maybe, a VM to build your application too ?  Thats how I work, I have a Bullseye VM where I build the SRC Debs for Debian and a U20.04 VM where I build my binary distributions, its setup to cross compile so I can make 64 and 32 bit Linux, (Debs and RPMs), Win32, RaspPi ....

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

RDL

  • Jr. Member
  • **
  • Posts: 63
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #10 on: May 13, 2022, 12:51:08 pm »
Sorry for my english, google translation!

MarkMLl

  • Hero Member
  • *****
  • Posts: 4494
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #11 on: May 13, 2022, 02:52:41 pm »
Noting what everybody else has said, but I believe that the fundamental issue is that the linker resolves/follows symlinks so the actual filename in the executable is that of the actual library.

I don't believe that's fixable, it's quite simply the way that the linker and loader work on Linux (and possibly other unices).

I've definitely seen comparable issues, although I can't recall whether they specifically involved (g)libc. Also I can't say whether they apply to unices other than Linux, since I've rarely (if ever) had multiple versions of these running and in any event it's long been my policy to try to have FPC/Lazarus on representatives of all OS variants and versions.

A related problem I had a couple of years ago was due to an ALSA version change. I worked around that by putting Docker on my development system and setting up a container with the target OS such that I could ssh in and get a shell, after which I could run Lazarus and FPC in the normal way.

So I suggest that the first thing to do is to follow through the symlink chain on both systems. I'd be very happy to be told I was wide of the mark, and that there was a simpler fix :-)

Added: If it is a library naming issue, it might be possible to fix it using patchelf

http://manpages.ubuntu.com/manpages/bionic/man1/patchelf.1.html

I've not experimented with this, and I don't know what would happen if a symlink name was patched into the ELF header.

MarkMLl
« Last Edit: May 14, 2022, 05:24:42 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4164
  • Compiler Developer
Re: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
« Reply #12 on: May 16, 2022, 01:27:26 pm »
Noting what everybody else has said, but I believe that the fundamental issue is that the linker resolves/follows symlinks so the actual filename in the executable is that of the actual library.

It's not an issue with symlinks or the name of the library. The issue is that newer libcs have a versioned symbol and according to the ELF spec when a symbol that has a version attached is used then this needs to be referenced as such in the ELF binary so that the dynamic linker can then resolve this using the correct version of the symbol, this implicitly also means that if you try to run a binary that uses such a versioned symbol on a system where the corresponding library does not have this symbol with the suitable version (or none at all) then the binary simply won't load. It's as if you'd use a symbol that doesn't exist at all.

 

TinyPortal © 2005-2018