Skip to content

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

Closed

Description

@drupol

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

Activity

  1. ramsey commented on Jun 9, 2023

    @ramsey
    Member

    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/

  2. jtojnar commented on Jun 9, 2023

    @jtojnar

    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
    
  3. ramsey commented on Jun 9, 2023

    @ramsey
    Member

    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.

  4. ramsey commented on Jun 9, 2023

    @ramsey
    Member

    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. 😄

  5. ndossche commented on Jun 9, 2023

    @ndossche
    Member

    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).

  6. drupol commented on Jun 9, 2023

    @drupol
    ContributorAuthor

    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.

  7. ndossche commented on Jun 9, 2023

    @ndossche
    Member

    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.

  8. LeSuisse commented on Jun 21, 2023

    @LeSuisse
    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.

  9. ndossche commented on Jun 22, 2023

    @ndossche
    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"
    
  10. drupol commented on Jun 22, 2023

    @drupol
    ContributorAuthor

    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.

  11. ndossche commented on Jun 22, 2023

    @ndossche
    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.

  12. drupol commented on Jun 22, 2023

    @drupol
    ContributorAuthor

    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
    
  13. drupol commented on Jun 22, 2023

    @drupol
    ContributorAuthor

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

    I confirm that both patches are working.

  14. added a commit that references this issue on Jun 22, 2023
    149d7e6
  15. ndossche commented on Jun 22, 2023

    @ndossche
    Member

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

  16. added a commit that references this issue on Jan 31, 2024
    b0ba368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions