Recent

Author Topic: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue  (Read 21372 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #60 on: October 24, 2023, 07:04:17 pm »
the above symlink is really important to ensure libdl.so.2 is correctly referenced in generated ELF headers.

That symlink should be installed by [...]

should be, but is not.

Then report  immediately a bug to your distribution.

Note according to formal Unix lore, you need to run ldconfig to update caches if you manually make any change to lib directories, like the symlink. The fat penguin OS doesn't require that afaik, but others might.

Quote
i recall this being argued about some time back. now if FPC accepted numeric extensions to after the .so then this wouldn't be such a problem!

The symlink system is there for a reason. The whole idea is that the system can have a new version of libdl (e.g. .3), and then apps linking to libdl,so will still work.

If you hate Unix like systems and don't want to learn their arcane rules, don't use it.
« Last Edit: January 11, 2024, 04:32:26 pm by marcov »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #61 on: October 24, 2023, 07:05:45 pm »
Well, I guess that the compat-app should not rely on dev-packages to be installed on the legacy system itself. That is why it should link against the versioned libs. And I hope these versions are more or less stable for the last [15] years.

If you link against the symlink, the generated apps should be linked against the versioned lib. That might not work on a system with another version, but cross-system binary compatibility was never high on the *nix agenda.

This is why the symlink is in a -DEVEL package, only needed on the system that generates the binaries.

WayneSherman

  • Sr. Member
  • ****
  • Posts: 250
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #62 on: October 24, 2023, 07:08:47 pm »
That symlink should be installed by [...]
should be, but is not. i recall this being argued about some time back. now if FPC accepted numeric extensions to after the .so then this wouldn't be such a problem!

On newer OS versions I think the "libdl.so" symlink has been omitted from the dev packages since libdl was merged into libc.

https://stackoverflow.com/questions/75855053/how-to-address-crash-due-to-missing-libdl-so-on-ubuntu-22
Quote
The library is libdl.so.2 in Linux distributions (Debian, RHEL, Ubuntu, etc...). It was historically libdl.so in older operating systems and Unix variants.

Both have been coexisting for a while and causing confusion:

    On CentOS, libdl.so can be installed by sudo yum install glibc-devel
    On Debian and Ubuntu <=20, libdl.so can be installed by sudo apt-get install libc6-dev
    On Ubuntu >= 22, libdl.so no longer exists, it can't be installed by libc6-dev (nor gcc).

The dev glibc package is a transitive dependency of gcc. It's very common for gcc to be installed on Linux machines (developer machines and end-user machines alike), so it's very common for libdl.so to be accidentally available. It's not part of the base operating system and should not be expected to be available.

A comparison of files in Debian libc-dev:
Debian 10 Buster (2019) (libc-dev has libdl.a and libdl.so)
https://packages.debian.org/buster/amd64/libc6-dev/filelist

Debian 11 Bullseye (2021) (libc-dev has libdl.a and libdl.so)
https://packages.debian.org/bullseye/amd64/libc6-dev/filelist

Debian 12 Bookworm (2023) (libc-dev has libdl.a only)
https://packages.debian.org/bookworm/amd64/libc6-dev/filelist
« Last Edit: October 24, 2023, 07:18:03 pm by WayneSherman »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #63 on: October 24, 2023, 07:12:07 pm »
Note, if you know you are on a system that maps libdl to libc, try adding parameter   -XLAdl=c

Binary compatibility wise however, they will probably be two different OSes.


DonAlfredo

  • Hero Member
  • *****
  • Posts: 1781
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #65 on: October 24, 2023, 07:16:26 pm »
Quote
Note, if you know you are on a system that maps libdl to libc, try adding parameter   -XLAdl=c
That is worth a try !

WayneSherman

  • Sr. Member
  • ****
  • Posts: 250
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #66 on: October 24, 2023, 07:47:28 pm »
...really important to ensure libdl.so.2 is correctly referenced in generated ELF headers.

Yes, this allows the compiled binary to run on older systems as well as new.

Note, if you know you are on a system that maps libdl to libc, try adding parameter   -XLAdl=c

Does this generate an executable that references "libdl.so.2"?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #67 on: October 24, 2023, 08:54:31 pm »
Does this generate an executable that references "libdl.so.2"?

Basically, it should replace references to 'dl'  in

Code: Pascal  [Select][+][-]
  1. procedure xx; cdecl external 'dl' name 'xx';

to behave like they were

Code: Pascal  [Select][+][-]
  1. procedure xx; cdecl external 'c' name 'xx';

It is old functionality however (see buildfaq for details), and it has been a while since I tested it.

robert rozee

  • Full Member
  • ***
  • Posts: 182
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #68 on: October 25, 2023, 01:49:33 am »
If you hate Unix like systems and don't want to learn their arcane rules, don't use it.

not exactly a helpful comment, Marco.

the symlink created by:
Code: Bash  [Select][+][-]
  1. sudo ln -s /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so

... is ONLY needed on the system you are running FPC on, NOT on any system you are going to run your binary on. hence, either (a) FPC itself should create the symlink, or (b) our patch program should create the symlink, or (c) the FPC source should be modified to not need the symlink.

basically, your application source needs (if FPC worked correctly) to contain somewhere/anywhere the line:
Code: Pascal  [Select][+][-]
  1. procedure anything; cdecl external 'libdl.so.2';

... where the procedure name doesn't matter. the important part is the external 'libdl.so.2'. this causes the library file libdl.so.2 to be added as a "NEEDED" library to the generated ELF binary's header. the procedure name doesn't matter as long as it exists in libdl or libc.

but unfortunately FPC, when it sees 'libdl.so.2', covertly converts it to 'libdl.so'. hence we need to manually add the symlink ourself on our development system.


note that this whole argument around the symlink is a Red Herring. the FPC developers will never allow numeric extensions to library names, while adding the symlink on your development system is trivial. the symlink would probably even work well enough if just added into your project directory - no need for sudo if done that way, but then needed for each and every project directory.


cheers,
rob   :-)
« Last Edit: October 25, 2023, 02:12:23 am by robert rozee »

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #69 on: October 25, 2023, 05:15:34 am »
note that this whole argument around the symlink is a Red Herring. the FPC developers will never allow numeric extensions to library names, while adding the symlink on your development system is trivial. the symlink would probably even work well enough if just added into your project directory - no need for sudo if done that way, but then needed for each and every project directory.
As I wrote before, no. You only have to do that once.
« Last Edit: October 25, 2023, 06:11:01 am by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1781
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #70 on: October 25, 2023, 07:08:45 am »
To summarize.
Linking against the unversioned lib will result in the symlink being resolved into a versioned version.
As long as this version can be found on the target system, all is good.
As legacy Linux systems more or less have the same library versions, I propose to add the needed libs like this (pseudo-code):
Code: Pascal  [Select][+][-]
  1. for s in ['libanl.so.1','libdl.so.2','librt.so.1','libresolv.so.2','libpthread.so.0'] do
  2. begin
  3.    AddLibrary(s);
  4. end;
  5.  
The versions are my educated guess about the most used versions on old Linux systems.
If these libraries are not available on the development system (this might happen as all functions are included into libc itself), some stubs are needed or linking will fail. Stub might be as easy as a symlink to libc.

Additional.
Unversioned linking of these libs, especially libc is very important.
libc.so is often a stub combining two (or more) libraries like this (FreeBSD for Aarch64):
Code: Pascal  [Select][+][-]
  1. GROUP ( libc.so.7 libc_nonshared.a libm.so )

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #71 on: October 25, 2023, 09:23:11 am »
... is ONLY needed on the system you are running FPC on, NOT on any system you are going to run your binary on. hence, either (a) FPC itself should create the symlink, or (b) our patch program should create the symlink, or (c) the FPC source should be modified to not need the symlink.

(d) mandatory buildrequirements of FPC (general setting the system up for development, most notably glibc-devel) should add the link.

Guess what, it is (d).


DonAlfredo

  • Hero Member
  • *****
  • Posts: 1781
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #72 on: October 25, 2023, 09:36:01 am »
Success !!
Screenshot of app build with FPC 3.2.2 and Lazarus trunk on Manjaro lates with glibc 2.35.
The app runs on Ubuntu 8 dated from 2008 !!

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11941
  • FPC developer.
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #73 on: October 25, 2023, 09:45:05 am »
Did the -XLA work?

WayneSherman

  • Sr. Member
  • ****
  • Posts: 250
Re: FPC 3.2.2 / Lazarus 2.2.6 patch for GLIBC_2.34 versioning issue
« Reply #74 on: October 25, 2023, 04:04:52 pm »
Code: Pascal  [Select][+][-]
  1. ['libanl.so.1','libdl.so.2','librt.so.1','libresolv.so.2','libpthread.so.0']
The versions are my educated guess about the most used versions on old Linux systems.

Those filenames match the declarations in "lib_namesh.inc":
https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/libc/src/lib_namesh.inc?ref_type=heads

 

TinyPortal © 2005-2018