php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68987 Failed to compile zend.c with gcc-4.9.2
Submitted: 2015-02-05 08:07 UTC Modified: 2015-02-06 14:59 UTC
From: 191919 at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Compile Failure
PHP Version: master-Git-2015-02-05 (Git) OS: OS X
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 191919 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-02-05 08:07 UTC] 191919 at gmail dot com
Description:
------------
On my OS X Yosemite 10.10.2, gcc-4.9.2 failed to compile zend.c.

$ uname -a
Darwin localhost 14.1.0 Darwin Kernel Version 14.1.0: Mon Dec 22 23:10:38 PST 2014; root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64

$ /opt/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/opt/bin/gcc
COLLECT_LTO_WRAPPER=/opt/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../gcc-4.9.2/configure --prefix=/opt --enable-languages=c,c++,objc,obj-c++
Thread model: posix

$ CC=/opt/bin/gcc CFLAGS="-O3 -mssse3 -ftree-vectorize -funroll-loops -fomit-frame-pointer -fno-stack-protector -fno-exceptions" ./configure --prefix=/opt/php7
$ make

... (a lot of lines omitted) ...

/bin/sh /Users/xx/box/php-src/libtool --silent --preserve-dup-deps --mode=install cp ext/opcache/opcache.la /Users/xx/box/php-src/modules
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/xx/box/php-src/modules/opcache.a(shared_alloc_shm.o) has no symbols
/bin/sh /Users/xx/box/php-src/libtool --silent --preserve-dup-deps --mode=compile /opt/bin/gcc  -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -IZend/ -I/Users/xx/box/php-src/Zend/ -DPHP_ATOM_INC -I/Users/xx/box/php-src/include -I/Users/xx/box/php-src/main -I/Users/xx/box/php-src -I/Users/xx/box/php-src/ext/date/lib -I/Users/xx/box/php-src/ext/ereg/regex -I/usr/local/include/libxml2 -I/Users/xx/box/php-src/ext/sqlite3/libsqlite -I/Users/xx/box/php-src/TSRM -I/Users/xx/box/php-src/Zend    -I/usr/include -O3 -mssse3 -ftree-vectorize -funroll-loops -ffast-math -fomit-frame-pointer -fno-stack-protector -fno-exceptions -fvisibility=hidden  -c /Users/xx/box/php-src/Zend/zend.c -o Zend/zend.lo 
In file included from /Users/xx/box/php-src/Zend/zend.c:22:0:
/Users/xx/box/php-src/Zend/zend.h:86:30: error: redefinition of 'zend_error'
 # define zend_error_noreturn zend_error
                              ^
/Users/xx/box/php-src/Zend/zend.c:1214:29: note: in expansion of macro 'zend_error_noreturn'
 ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
                             ^
/Users/xx/box/php-src/Zend/zend.c:1205:15: note: previous definition of 'zend_error' was here
 ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
               ^
make: *** [Zend/zend.lo] Error 1

I checked the problem lines in zend.c:

#if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__))
void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
#elif defined(ZEND_WIN32) || defined(DARWIN)
ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
{
	va_list va;

	va_start(va, format);
	zend_error_va_list(type, format, va);
	va_end(va);
}

ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
{
	va_list va;

	va_start(va, format);
	zend_error_va_list(type, format, va);
	va_end(va);
}
/* }}} */
#endif

As defined in zend.h:

#ifdef HAVE_NORETURN
# if defined(ZEND_WIN32)
ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...);
# else
void zend_error_noreturn(int type, const char *format, ...) ZEND_NORETURN;
# endif
#else
# define zend_error_noreturn zend_error
#endif

`zend_error_noreturn` is defined as `zend_error`, so

ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)

is expanded to

ZEND_API ZEND_NORETURN void zend_error(int type, const char *format, ...)

which is already defined.



Expected result:
----------------
Compilation succeeds.

Actual result:
--------------
Compilation failed.

Patches

bug68987.patch (last revision 2015-02-06 09:41 UTC by laruence@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-05 08:48 UTC] laruence@php.net
interesting , but why no such error before...
 [2015-02-06 02:39 UTC] 191919 at gmail dot com
Perhaps because in OS X, the default compiler is clang or clang-gcc.

In this case, gcc-4.9.2 is from my own compilation (you can see the ./configure statement in the original post).

In zend_portability.h:

#if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) || __has_attribute(noreturn)
# define HAVE_NORETURN
# define ZEND_NORETURN __attribute__((noreturn))
#elif defined(ZEND_WIN32)
# define HAVE_NORETURN
# define ZEND_NORETURN __declspec(noreturn)
#else
# define ZEND_NORETURN
#endif

1. In OS X (with DARWIN defined) with clang which has __has_attribute(noreturn)'s value is true, HAVE_NORETURN is defined.
2. In OS X with gcc which does not have __has_attribute, HAVE_NORETURN is not defined.

zend.h includes zend_portability.h, and in zend.h:

#ifdef HAVE_NORETURN
# if defined(ZEND_WIN32)
ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...);
# else
void zend_error_noreturn(int type, const char *format, ...) ZEND_NORETURN;
# endif
#else
# define zend_error_noreturn zend_error
#endif

So we have zend_error_noreturn defined as zend_error.

Finally in zend.c:

#if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__))
void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
#elif defined(ZEND_WIN32) || defined(DARWIN)
ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
{
	va_list va;

	va_start(va, format);
	zend_error_va_list(type, format, va);
	va_end(va);
}

ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
{
	va_list va;

	va_start(va, format);
	zend_error_va_list(type, format, va);
	va_end(va);
}
/* }}} */
#endif

Because zend_error_noreturn has been defined to zend_error, there *IS* the duplicated definition.
 [2015-02-06 02:42 UTC] 191919 at gmail dot com
I submitted the form before finishing it.

Continue:

That's why in most cases under OS X where the compiler is clang-gcc (which has __has_attribute) or clang, the compilation will succeed, and if you have vanilla gcc, it will complain the duplicated definition of zend_error.
 [2015-02-06 09:41 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug68987.patch
Revision:   1423215715
URL:        https://bugs.php.net/patch-display.php?bug=68987&patch=bug68987.patch&revision=1423215715
 [2015-02-06 09:42 UTC] laruence@php.net
-Assigned To: +Assigned To: dmitry
 [2015-02-06 14:31 UTC] laruence@php.net
should be fixed now. thanks for reporting
 [2015-02-06 14:38 UTC] 191919 at gmail dot com
Confirmed working.

clang 3.7 svn trunk and gcc-4.9.2 on OS X 10.10.2, both worked. Didn't try under other OS.
 [2015-02-06 14:59 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 14:01:31 2025 UTC