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

Optional GNU C Library support #376

Open
dunglas opened this issue Mar 11, 2024 · 12 comments
Open

Optional GNU C Library support #376

dunglas opened this issue Mar 11, 2024 · 12 comments
Assignees
Labels
enhancement New feature or request os/linux Things only for Linux OS wip Work In Process
Milestone

Comments

@dunglas
Copy link
Contributor

dunglas commented Mar 11, 2024

Currently, Musl is used, but there are many known issues with Musl.
Would it be possible to add a flag to use the static glibc instead of Musl?

@crazywhalecc crazywhalecc added help wanted Extra attention is needed question Further information is requested labels Mar 11, 2024
@dunglas
Copy link
Contributor Author

dunglas commented Mar 11, 2024

Alternatively, we may try to link everything statically except libc, which is part of POSIX anyway and should always be available: https://stackoverflow.com/a/58565307/1352334

This seems to be called "mostly-static linking": https://docs.oracle.com/en/graalvm/jdk/17/docs/reference-manual/native-image/guides/build-static-executables/#build-a-statically-linked-or-mostly-statically-linked-native-executable

@crazywhalecc
Copy link
Owner

crazywhalecc commented Mar 11, 2024

Would it be possible to add a flag to use the static glibc instead of Musl?

This is a complex issue. To sum up, the reasons why we use musl by default are as follows:

  1. musl-libc is simpler and smaller than glibc, and is especially suitable for static compilation. And thanks to @DubbleClick's musl-cross-make, we can compile musl-static binary on glibc-based distros (same as alpine).
  2. Pure static linking of glibc is not recommended, see stackoverflow.
  3. If we just use dynamic linking glibc as default ("mostly-static linking), we cannot run php binary on alpine and musl-based OS, and of course we will not be able to compile static-php-cli on alpine with this method.

If you want to dig deeper:

  1. we already have discussion about standalone (not purely static) php cli but nobody comments about this :(
  2. We can just set --cc or --cxx to change the glibc-based gcc now, but I haven't made a simple flag to enable this feature. I tested this feature but "not the most portable" problem beats me.

@crazywhalecc crazywhalecc added the os/linux Things only for Linux OS label Mar 11, 2024
@crazywhalecc
Copy link
Owner

To put it jokingly, the existence of this project is also due to the confusion of Linux libc and the fact that most early projects did not like static compilation. It would be better if Linux has default library and it provides all possibilities(dynamic and static) and is stable. LinuxBuilder is also more complex than MacOSBuilder and WindowsBuilder.

@DubbleClick
Copy link
Contributor

Just as an addition to the listed problems (espevially static glibc linking still requiring dynamic libraries, so what's even the point):

I've dabbled in dynamic linking with glibc before and ran into huge issues with different distros. It would be a lot of work to keep it working and stable for them all. There would be an advantage, mainly loading of dynamic extensions on glibc systems, but it also eliminates a major benefit of the project (compile it once, use it anywhere).

@crazywhalecc
Copy link
Owner

After #403 merged, I can make a set of env variables for building glibc version of static-php. But we also need --skip-item for docker command, patch cmake toolchain file and disable injection for musl tools. These will be added as minor version updates after the 2.2 release.

@dkarlovi
Copy link

In the meantime, I've opened php/php-src#13877 which got some traction already:

php/php-src#13925
php/php-src#13974

It's possible PHP's musl support will get substantially better over time.

@crazywhalecc
Copy link
Owner

crazywhalecc commented Apr 28, 2024

@dunglas Today I evaluated the possibility of linking static-php using glibc. Unfortunately, doing so comes at a huge loss of portability.

The main problem is not compilation, but the version of glibc. Because if we do not restrict compilation on a specific distro, the compiled static-php may require a newer glibc version, which cannot be used for older versions of the distro. A very simple example is: the results built on Debian11 cannot be used on Debian10. The result is similar to many closed source software: different binaries for each major version.

# ldd buildroot/bin/php
buildroot/bin/php: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by buildroot/bin/php)
buildroot/bin/php: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.35' not found (required by buildroot/bin/php)
buildroot/bin/php: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by buildroot/bin/php)
buildroot/bin/php: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by buildroot/bin/php)
buildroot/bin/php: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by buildroot/bin/php)
	linux-vdso.so.1 (0x00007fff69df6000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fad15277000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fad14ed9000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fad14cc1000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fad148d0000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fad17fab000)

@dunglas
Copy link
Contributor Author

dunglas commented Apr 28, 2024

Thank you very much for working on this. I agree that it's a big limitation. Let's close this issue then?

@crazywhalecc crazywhalecc added wontfix This will not be worked on and removed help wanted Extra attention is needed labels Apr 28, 2024
@crazywhalecc
Copy link
Owner

I will write the compilation variables based on glibc on doc or blog later, but obviously this will not become official support. Let's close this.

@crazywhalecc crazywhalecc closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2024
@crazywhalecc
Copy link
Owner

crazywhalecc commented Jan 14, 2025

@dunglas An interesting thing you may want to know: I only need to build Docker for a specific old glibc environment (e.g. CentOS 7 with an old toolchain, this is using glibc 2.17 as minimal glibc version), and with a patched env.ini and workarounds for some special libraries, I can build a static binary with dynamically linked glibc and have it work on almost all Linux distros (except Alpine Linux).

This may be an optional feature, as musl-libc does have a lot of issues that cannot be solved directly (I also encountered some problems with musl recently). It is true that this work may not be done as a default target, but the it shows that SPC is capable of building another results.

If you or anyone are interested, I can reopen this issue and related pr in the future.

@crazywhalecc crazywhalecc removed the wontfix This will not be worked on label Jan 14, 2025
@SerafimArts
Copy link

SerafimArts commented Jan 16, 2025

If you or anyone are interested, I can reopen this issue and related pr in the future.

Adding FFI support - solves a huge number of problems, as it provides direct access to the system.

If we exaggerate a little, then the presence of this extension makes all other extensions for PHP unnecessary, as you can write them yourself if you wish (lol).

So personally, I am interested in this issue.

@dunglas
Copy link
Contributor Author

dunglas commented Jan 16, 2025

This would help a lot FrankenPHP, I'm definitely interested!

@crazywhalecc crazywhalecc reopened this Jan 25, 2025
@crazywhalecc crazywhalecc added wip Work In Process and removed question Further information is requested labels Jan 25, 2025
@crazywhalecc crazywhalecc self-assigned this Jan 25, 2025
@crazywhalecc crazywhalecc added the enhancement New feature or request label Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request os/linux Things only for Linux OS wip Work In Process
Projects
None yet
Development

No branches or pull requests

5 participants