Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

compiling on one debian version and linking on different version of debian

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
Чебурашка
Posts: 5
Joined: 2023-05-17 06:35

compiling on one debian version and linking on different version of debian

#1 Post by Чебурашка »

Hello, while I am not a debian beginner, I am new in this forum, perhaps this question has already been asked.
Thanks for anyone who helps.

I have a situation where I am developing some softwares written in free pascal (both executables and .so libraries), under debian 11.5 amd64, where I develop compile and run successfully.
This software is the supposed to run also on:

1. debian 9.6 i386
2. debian 6.0.8 i386

At first I tried to compile the software directly on these two older version, but soon I realized that I was using features of the compiler in deb 11.5 that are not available in the older compiler versions present in the older debians.

Due to this impossibility, since I got aware that free pascal compiler relies on GNU assembler and GNU linker, I decided to try another path:

1. install a deb11.5 i386 where the free pascal compiler version is the same as in the deb 11.5 amd64
2. compile the software on the deb 11.5 i386 without linking it (free pascal compiler achieves this with the option "-s")
3. copying the compiler resulting .o files on the two older distributions
4. copy from the deb 11.5 i386 to the two older distributions some of the .o files related to the free pascal rtl available in the deb 11.5 i386
5. fix some paths here and there because it seems there have been some minor rearrangements in the /usr directory structures (I just made a handful of ln -s)
6. link the .o files into the final target.

I succeded in doing this, in the sense that the linker does the job with no error message and the executable/library is successfully created, for what I could see they seem to operate correclty.

The question is: is the method described senseful? and the fact that the linking process succeds without error is an indication or even a guarantee that the resulting exe/.so is sound?

Thank you

Aki
Global Moderator
Global Moderator
Posts: 2816
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 68 times
Been thanked: 382 times

Re: compiling on one debian version and linking on different version of debian

#2 Post by Aki »

Hello,
Чебурашка wrote: 2023-05-17 06:58 [..] I am developing some softwares written in free pascal (both executables and .so libraries), under debian 11.5 amd64, where I develop compile and run successfully. This software is the supposed to run also on:
1. debian 9.6 i386
2. debian 6.0.8 i386
At first I tried to compile the software directly on these two older version, but soon I realized that I was using features of the compiler in deb 11.5 that are not available in the older compiler versions present in the older debians.
[..]
For Debian 9 (codenamed "Stretch"), the Free Pascal compiler is available in Debian repositories [1] and the most effective choice would be to compile the pascal source code using a Debian 9 installation (if the program compiles).

Debian 6 (codenamed "Squeeze") is currently out of support from Debian project [2], but all programs are archived here [3] and the Free Pascal compiler 2.4.0-2 is available in the repository. Therefore, in this case the most effective choice would be to compile the pascal source code using a Debian 6 installation (if the program compiles).

Alternatively, you could try to statically link the executable embedding all used libraries in Debian 11. This way you could generate in Debian 11 a single catch-all executable you can try to use with Debian 9 and Debian 6. In this case, you need to statically link all libraries used by your program depends on other external libraries, they could not work. I don't know if the executable binary format (ELF) used by Debian 11 is compatible with the one used by Debian 9 and 6, either.

Is the source code of your program freely available and, if yes, where ?

---
[1] https://packages.debian.org/search?searchon=names&keywords=fpc
[2] https://wiki.debian.org/DebianReleases
[3] http://archive.debian.org/debian/dists/squeeze/
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

User avatar
Чебурашка
Posts: 5
Joined: 2023-05-17 06:35

Re: compiling on one debian version and linking on different version of debian

#3 Post by Чебурашка »

Aki wrote: 2023-05-17 08:45 For Debian 9 (codenamed "Stretch"), the Free Pascal compiler is available in Debian repositories [1] and the most effective choice would be to compile the pascal source code using a Debian 9 installation (if the program compiles).

Unfortunately it doesn't compile as deb 11 sports fpc 3.2.0 and I am using features of it not present in older fpc present in 9 and 6.

Debian 6 (codenamed "Squeeze") is currently out of support from Debian project [2], but all programs are archived here [3] and the Free Pascal compiler 2.4.0-2 is available in the repository. Therefore, in this case the most effective choice would be to compile the pascal source code using a Debian 6 installation (if the program compiles).
Unfortunately it doesn't compile on older deb, as explained. I use some constructs (generics) introduced in more recent fpc version.
Aki wrote: 2023-05-17 08:45 Alternatively, you could try to statically link the executable embedding all used libraries in Debian 11.
I tried to link statically but it seems fpc does not make it. Prob I need to inspect more, because this was initially the safest path (except that it would be necessary to make sure resulting exe/.so works with older kernels).
Aki wrote: 2023-05-17 08:45 I don't know if the executable binary format (ELF) used by Debian 11 is compatible with the one used by Debian 9 and 6, either.
I don't know either. I was just asking if the fact the I get no linker complain is enough to guarantee that linking process was sound or if there could be other issues despite the absence of linker error messages or warnings.
Aki wrote: 2023-05-17 08:45 Is the source code of your program freely available and, if yes, where ?
Right now not, but I think this software is by no means interesting to anybody as is intended to manage some information produced by a industrial machines produced by the company I work for. Unless people have this machines I cannot figure out what they could do with this software.

Anyway I do not exclude that I could make public some parts of it that could be reused in future.
Thanks

User avatar
kent_dorfman766
Posts: 529
Joined: 2022-12-16 06:34
Location: socialist states of america
Has thanked: 56 times
Been thanked: 69 times

Re: compiling on one debian version and linking on different version of debian

#4 Post by kent_dorfman766 »

It's generally a bad practice to develop software on a higher version platform and expect it to run on an older version. You always want to develop on the "least common denominator", and make tweaks where necessary for the code to run on the newer systems as well.

So, what you are needing to do is called "backporting". install the necessary compilers on the older systems and build them natively for those versions.

Random_Troll
Posts: 444
Joined: 2023-02-07 13:35
Been thanked: 105 times

Re: compiling on one debian version and linking on different version of debian

#5 Post by Random_Troll »

Чебурашка wrote: 2023-05-17 09:37
Aki wrote: 2023-05-17 08:45 Alternatively, you could try to statically link the executable embedding all used libraries in Debian 11.
I tried to link statically but it seems fpc does not make it. Prob I need to inspect more, because this was initially the safest path (except that it would be necessary to make sure resulting exe/.so works with older kernels).
Static linking won't work with glibc: https://stackoverflow.com/questions/574 ... iscouraged

Can you use musl libc instead? That's designed for static linking.
Jeder nach seinen Fähigkeiten, jedem nach seinen Bedürfnissen.

User avatar
Чебурашка
Posts: 5
Joined: 2023-05-17 06:35

Re: compiling on one debian version and linking on different version of debian

#6 Post by Чебурашка »

kent_dorfman766 wrote: 2023-05-17 16:04 It's generally a bad practice to develop software on a higher version platform and expect it to run on an older version. You always want to develop on the "least common denominator", and make tweaks where necessary for the code to run on the newer systems as well.
Unfortunately I need to manage a legacy system which is compiled also with Kylix (2002).
kent_dorfman766 wrote: 2023-05-17 16:04 So, what you are needing to do is called "backporting". install the necessary compilers on the older systems and build them natively for those versions.
As I said, I was not able to install the newer compilers versions on older debians, otherwise I would never have posted here.

The point is that I did not find anybody so far that was able to tell if there are incompatibilities to the ELF format when .o is copied from 11 to 9 or 6. Also I did not find anybody telling me if receiving no error/warning from ld is sufficient to say that the resulting exe/.so is a sound one. I know that these are not a trivial questions, otherwise if I knew the answers, I would not even have posted here.

User avatar
Чебурашка
Posts: 5
Joined: 2023-05-17 06:35

Re: compiling on one debian version and linking on different version of debian

#7 Post by Чебурашка »

Random_Troll wrote: 2023-05-17 16:26
Чебурашка wrote: 2023-05-17 09:37
Aki wrote: 2023-05-17 08:45 Alternatively, you could try to statically link the executable embedding all used libraries in Debian 11.
I tried to link statically but it seems fpc does not make it. Prob I need to inspect more, because this was initially the safest path (except that it would be necessary to make sure resulting exe/.so works with older kernels).
Static linking won't work with glibc: https://stackoverflow.com/questions/574 ... iscouraged

Can you use musl libc instead? That's designed for static linking.
This is an interesting suggestion. I'will give a deeper look at that.
Thanks

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: compiling on one debian version and linking on different version of debian

#8 Post by stevepusser »

Almost sounds like a situation where universal package formats like AppImage, snap, or flatpaks could come in handy.

Or a schroot of the newer system on the older one could run them. Isn't there some systemd sort of thing that can do that also?
MX Linux packager and developer

User avatar
Чебурашка
Posts: 5
Joined: 2023-05-17 06:35

Re: compiling on one debian version and linking on different version of debian

#9 Post by Чебурашка »

stevepusser wrote: 2023-05-20 19:02 Almost sounds like a situation where universal package formats like AppImage, snap, or flatpaks could come in handy.

Or a schroot of the newer system on the older one could run them. Isn't there some systemd sort of thing that can do that also?
Thanks,
I did a manual chroot with a debostrapped more recent distribution on the deb 9. Everything was working.
Instead it wasn't possible to do the same on deb 6 as kernel is too old for the requested distribution.
Chroot is fine, except that is to be done manually.

I beleve that the best would be to statically linked output or have some automation that creates a fully self standing set of files to be copyed on he target. The only problem is that being executables and so libraries, sooner or later they might end up in not being supported by the kernel if it is too old.

I will keep on studying the problem.

Thanks

Post Reply