Skip to content

Unable to build PHP 8.3.0 alpha 1 / fileinfo extension #11408

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

Closed
drupol opened this issue Jun 9, 2023 · 14 comments
Closed

Unable to build PHP 8.3.0 alpha 1 / fileinfo extension #11408

drupol opened this issue Jun 9, 2023 · 14 comments

Comments

@drupol
Copy link
Contributor

drupol commented Jun 9, 2023

Description

Hello,

I'm trying to provide PHP 8.3.0 in the Nix ecosystem and I'm unable to compile PHP 8.3.0 alpha1. The issue seems to come from the fileinfo extension, see the attached log.

Here's the output of the test 57547:

$ cat ./php-8.3.0alpha1/ext/fileinfo/tests/bug57547.out
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: ./php-8.3.0alpha1/ext/fileinfo/tests/bug57547.out
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ Warning: PHP Startup: Invalid library (maybe not a PHP library) '/build/php-8.3.0alpha1/ext/fileinfo/modules//fileinfo.so' in Unknown on line 0
   2   │ 
   3   │ Warning: PHP Startup: Invalid library (maybe not a PHP library) 'fileinfo.so' in Unknown on line 0
   4   │ 
   5   │ Fatal error: Uncaught Error: Class "finfo" not found in /build/php-8.3.0alpha1/ext/fileinfo/tests/bug57547.php:6
   6   │ Stack trace:
   7   │ #0 {main}
   8   │   thrown in /build/php-8.3.0alpha1/ext/fileinfo/tests/bug57547.php on line 6
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$
$ file ./php-8.3.0alpha1/ext/fileinfo/modules/fileinfo.so
./php-8.3.0alpha1/ext/fileinfo/modules/fileinfo.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped
$ ldd ./php-8.3.0alpha1/ext/fileinfo/modules/fileinfo.so
        linux-vdso.so.1 (0x00007ffe6c1d0000)
        libc.so.6 => /nix/store/flf14c3ibr83jsa070j25hg5gjapydhl-glibc-2.37-8/lib/libc.so.6 (0x00007f22d50fc000)
        /nix/store/flf14c3ibr83jsa070j25hg5gjapydhl-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007f22d5a9f000)
$
$ readelf -a ./php-8.3.0alpha1/ext/fileinfo/modules/fileinfo.so

(See gist)

PHP Version

PHP 8.3.0

Operating System

NixOS

@ramsey
Copy link
Member

ramsey commented Jun 9, 2023

While no external libraries should be required to build the fileinfo extension, I do find this line from your logs interesting:

php-fileinfo> ./configure: line 5508: /usr/bin/file: No such file or directory

This command (and the accompanying libmagic library) is normally available on all Unix-like distributions. I'm not sure why it's missing. Install it, and see if that fixes the issue.

https://www.darwinsys.com/file/

@jtojnar
Copy link

jtojnar commented Jun 9, 2023

That error occurs because configure scripts generated with old versions of Autotools look specifically for /usr/bin/file (which Nix does not have) rather than looking it up on PATH. But that can be safely ignored most of the time.

Either way, I suspect this is something Nix specific and OP should check out what the “invalid” library is:

Warning: PHP Startup: Invalid library (maybe not a PHP library) '/build/php-8.3.0alpha1/ext/fileinfo/modules//fileinfo.so' in Unknown on line 0

@ramsey
Copy link
Member

ramsey commented Jun 9, 2023

The "invalid library" is fileinfo.so. It's invalid because it wasn't built properly, presumably because the system is missing something that PHP's build system expects.

@ramsey
Copy link
Member

ramsey commented Jun 9, 2023

Never mind about my "missing libmagic/file" assumption. PHP ships with libmagic, so it doesn't need any anything from the system. https://github.com/php/php-src/tree/master/ext/fileinfo

I was hoping it was a missing system dependency, since that'd be easier to fix. 😄

@nielsdos
Copy link
Member

nielsdos commented Jun 9, 2023

Note: I don't use Nix, but I can't reproduce this on my distro (built as shared object).
I agree something must've gone wrong with your fileinfo.so build. Does it always happen or was this a one-time?
You can try to execute file <location to fileinfo.so> to see if the file is corrupted (similarly check if readelf complains).

@drupol
Copy link
Contributor Author

drupol commented Jun 9, 2023

I updated the OP with the information requested, I will come back on the computer a bit later to dig a bit deeper. In the meantime, if you have a clue, let me know.

@nielsdos
Copy link
Member

nielsdos commented Jun 9, 2023

I see your .dynsym section doesn't contain an export for get_module which is the reason the extension loading fails. I just checked and my fileinfo.so build on my machine does. Not sure yet what could cause this tbh.

@LeSuisse
Copy link
Contributor

I took a bit of time to bisect the issue using the Nix derivation, it seems to be present since these commits:
6219d7f
a24727a
a3dd514

The exact cause of the build issue is not yet clear to me.

@nielsdos
Copy link
Member

Thanks for sticking through!
Could you please try this patch for me? This tries two things: force load the config; and also force the output of the get_module part.

diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index a6f3e64db6..19eda44ec4 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -14,6 +14,9 @@
   +----------------------------------------------------------------------+
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include "php.h"
 
 #include "libmagic/magic.h"
@@ -133,9 +136,9 @@ zend_module_entry fileinfo_module_entry = {
 };
 /* }}} */
 
-#ifdef COMPILE_DL_FILEINFO
+//#ifdef COMPILE_DL_FILEINFO
 ZEND_GET_MODULE(fileinfo)
-#endif
+//#endif
 
 /* {{{ PHP_MINFO_FUNCTION */
 PHP_MINFO_FUNCTION(fileinfo)

If this works, does the following then also work (after you reverted the above patch)?

diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index a6f3e64db6..c3047233db 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -14,6 +14,9 @@
   +----------------------------------------------------------------------+
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include "php.h"
 
 #include "libmagic/magic.h"

@drupol
Copy link
Contributor Author

drupol commented Jun 22, 2023

Dear @nielsdos, I just tested with the first and the issue is still there.

I also tested with 8.3.0-alpha2 with no difference.

@nielsdos
Copy link
Member

Thanks for testing. Are you able to share your config.h and the configure command line you used? This would help us reproduce the issue on our systems.
I will only be able to continue looking at this in the evening though.

@drupol
Copy link
Contributor Author

drupol commented Jun 22, 2023

Here's the config.h

/tmp/nix-build-php-fileinfo-8.3.0.drv-1/php-8.3.0alpha2/ext/fileinfo/config.h
/* config.h.  Generated from config.h.in by configure.  */
/* config.h.in.  Generated from configure.ac by autoheader.  */

/* Whether to build fileinfo as dynamic module */
#define COMPILE_DL_FILEINFO 1

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the `strndup' function. */
#define HAVE_STRNDUP 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to 1 if you have the `utimes' function. */
#define HAVE_UTIMES 1

/* Define to the address where bug reports for this package should be sent. */
/* #undef PACKAGE_BUGREPORT */

/* Define to the full name of this package. */
/* #undef PACKAGE_NAME */

/* Define to the full name and version of this package. */
/* #undef PACKAGE_STRING */

/* Define to the one symbol short name of this package. */
/* #undef PACKAGE_TARNAME */

/* Define to the home page for this package. */
/* #undef PACKAGE_URL */

/* Define to the version of this package. */
/* #undef PACKAGE_VERSION */

/* Define to 1 if all of the C90 standard headers exist (not just the ones
   required in a freestanding environment). This macro is provided for
   backward compatibility; new code need not use it. */
#define STDC_HEADERS 1

@drupol
Copy link
Contributor Author

drupol commented Jun 22, 2023

I succeeded to build the extension, I was applying not applying the patch correctly the first time.

I confirm that both patches are working.

nielsdos added a commit to nielsdos/php-src that referenced this issue Jun 22, 2023
On some configurations, the COMPILE_DL_FILEINFO must come from the
config.h file. If the COMPILE_DL_FILEINFO macro is not set, the build
won't include the ZEND_GET_MODULE block necessary for building this
extension as a shared object.
@nielsdos
Copy link
Member

Thanks @drupol I've submitted a PR to fix this, the fix will be in the next alpha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants