Bug #80197 [Com]: implicit declaration of function 'magic_stream' is invalid
| From: | php-bugs-2020 at ryandesign dot com | Date: | Wed, 02 Dec 2020 23:39:22 +0000 |
| Subject: | Bug #80197 [Com]: implicit declaration of function 'magic_stream' is invalid | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-230805@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80197&edit=1
ID: 80197
Comment by: php-bugs-2020 at ryandesign dot com
Reported by: mkoula@php.net
Summary: implicit declaration of function 'magic_stream' is
invalid
Status: Open
Type: Bug
Package: PHP options/info functions
Operating System: macOS Catalina 10.15.7
PHP Version: 8.0.0rc1
Block user comment: N
Private report: N
New Comment:
I am encountering this as well as I try to add php 8.0.0 to MacPorts. libmagic (part of file 5.39)
is also installed with MacPorts, providing /opt/local/include/magic.h. You appear to bundle a
modified libmagic with php and want to include its headers.
The problem may be specific to the versions of clang shipped with Xcode 12 and later, which have
turned implicit declaration of function into an error. It used to be just a warning.
The problem appears to be that the -I flags are in the wrong order. Here is the compile line:
/bin/sh /path/to/php-8.0.0/libtool --silent --preserve-dup-deps --mode=compile ccache /usr/bin/clang
-Iext/fileinfo/ -I/path/to/php-8.0.0/ext/fileinfo/ -I/path/to/php-8.0.0/include
-I/path/to/php-8.0.0/main -I/path/to/php-8.0.0 -I/path/to/php-8.0.0/ext/date/lib
-I/opt/local/include/libxml2 -I/opt/local/include -I/opt/local/include/editline
-I/path/to/php-8.0.0/TSRM -I/path/to/php-8.0.0/Zend -I/opt/local/include -no-cpp-precomp -Wall
-Wextra -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-sign-compare -pipe
-Os -Werror=implicit-function-declaration -arch x86_64 -fvisibility=hidden -DZEND_SIGNALS
-I/path/to/php-8.0.0/ext/fileinfo/libmagic -c /path/to/php-8.0.0/ext/fileinfo/fileinfo.c -o
ext/fileinfo/fileinfo.lo
Note that -I/opt/local/include (which comes from user-specified (or in my case MacPorts-specified)
CPPFLAGS) precedes project-local paths like -I/path/to/php-8.0.0/ext/fileinfo/libmagic. All
project-local -I flags should precede global -I flags so that you don't accidentally include
system headers instead of your local files.
This problem does not happen with php 7.4.13 or earlier. There the compile line is:
/bin/sh /path/to/php-7.4.13/libtool --silent --preserve-dup-deps --mode=compile ccache
/usr/bin/clang -I/path/to/php-7.4.13/ext/fileinfo/libmagic -Iext/fileinfo/
-I/path/to/php-7.4.13/ext/fileinfo/ -DPHP_ATOM_INC -I/path/to/php-7.4.13/include
-I/path/to/php-7.4.13/main -I/path/to/php-7.4.13 -I/path/to/php-7.4.13/ext/date/lib
-I/opt/local/include/libxml2 -I/opt/local/include -I/opt/local/include/editline
-I/path/to/php-7.4.13/TSRM -I/path/to/php-7.4.13/Zend -I/opt/local/include -no-cpp-precomp -pipe
-Os -Werror=implicit-function-declaration -arch x86_64 -fvisibility=hidden -Wall
-Wno-strict-aliasing -DZEND_SIGNALS -c /path/to/php-7.4.13/ext/fileinfo/fileinfo.c -o
ext/fileinfo/fileinfo.lo
Note how -I/path/to/php-7.4.13/ext/fileinfo/libmagic appears earlier in the compile line, before
-I/opt/local/include, thus ensuring that your modified copy of magic.h gets used instead of a
standard one that might be installed in a system directory.
I'm not sure what changed in php 8 to cause the order of -I flags to change.
Until the order of -I flags is fixed in the php build system, a workaround for the user could be to
deactivate or uninstall libmagic before installing php 8. Another workaround for the user could be
to add -isystem/opt/local/include to CPPFLAGS, which will override any existing -I/opt/local/include
to ensure /opt/local/include gets placed at the end of the search path regardless of where it
appears on the compile line.
Previous Comments:
------------------------------------------------------------------------
[2020-10-16 08:53:32] cmb@php.net
Not sure what exactly might be wrong with GD, but that libmagic
include line looks wrong to me. Isn't that a bug that should be
fixed for PHP-7.3[1] upwards?
[1] <https://github.com/php/php-src/blob/php-7.3.23/ext/fileinfo/fileinfo.c#L24>
------------------------------------------------------------------------
[2020-10-15 13:07:46] mkoula@php.net
I tried this
#include "libmagic/magic.h",
and seemed to be working but then I had similar issues in GD library in multiple files. I also used
the local links and I was able to finally compiled it, but just calling PHP in cli produces
segmentation faut.
Strage is that beta worked fine for me without issues an RC not. So I wait for another release...
------------------------------------------------------------------------
[2020-10-09 14:28:05] nikic@php.net
Maybe #include "libmagic/magic.h"?
------------------------------------------------------------------------
[2020-10-07 13:49:59] mkoula@php.net
I applied the diff change in ext/fileinfo/fileinfo.c, rerun configure and compile, but it still uses
the /opt/local/include/magic.h
Is there any way of setup/configuration to force it use this the internal libmagic and this file?
------------------------------------------------------------------------
[2020-10-07 12:20:15] cmb@php.net
> /opt/local/include/magic.h
Apparently, the build includes the system header, although
that is undesired. I think we want
ext/fileinfo/fileinfo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index 0a4ee3c34e..39343f06fc 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -19,7 +19,7 @@
#endif
#include "php.h"
-#include <magic.h>
+#include "magic.h"
/*
* HOWMANY specifies the maximum offset libmagic will look at
* this is currently hardcoded in the libmagic source but not exported
Also for PHP 7.3+.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=80197
--
Edit this bug report at https://bugs.php.net/bug.php?id=80197&edit=1