php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76825 Undefined symbols ___cpuid_count
Submitted: 2018-08-31 02:35 UTC Modified: 2018-10-26 15:58 UTC
From: php-bugs-2018 at ryandesign dot com Assigned: cmb (profile)
Status: Closed Package: Compile Failure
PHP Version: 7.3.0beta3 OS: Mac OS X 10.7.5
Private report: No CVE-ID: None
 [2018-08-31 02:35 UTC] php-bugs-2018 at ryandesign dot com
Description:
------------
Hello, php 7.3.0beta3 fails to build on Mac OS X 10.7.5 using the clang 425.0.28 compiler that ships with Xcode 4.6.3:


Zend/zend_cpuinfo.c:34:2: warning: implicit declaration of function '__cpuid_count' is invalid in C99 [-Wimplicit-function-declaration]
        __cpuid_count(func, subfunc, cpuinfo->eax, cpuinfo->ebx, cpuinfo->ecx, cpuinfo->edx);
        ^

...

Undefined symbols for architecture x86_64:
  "___cpuid_count", referenced from:
      _zend_cpu_startup in zend_cpuinfo.o


On Mac OS X 10.6.8 using the Apple gcc 4.2.1 compiler that ships with Xcode 3.2.6, there is a different but seemingly related error:


Zend/zend_cpuinfo.c:32:19: error: cpuid.h: No such file or directory


The commit that probably introduced this problem is https://github.com/php/php-src/commit/1a078117b5ae862b18ef5362accef4b4d0a6b7c4

Using a newer compiler does work around the problem, but requiring users to install or possibly even build a newer compiler can be an imposition. It looks like php used to have some custom assembly that was replaced with a call to __cpuid_count, and there was discussion in https://github.com/php/php-src/pull/3395 about whether the old code should be retained as a fallback, and it was decided not to do so until someone reported a build failure; this ticket is that build failure report.


Patches

check-cpuid-count (last revision 2018-10-17 11:59 UTC by cmb@php.net)

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-31 10:55 UTC] cmb@php.net
I don't understand the compile failure under Clang, since the
respective code is guarded by `defined(__GNUC__)`[1].

Anyhow, we should use feature detection (AC_TRY_LINK) instead of
inferring by compiler, in my opinion.

[1] <https://github.com/php/php-src/blob/php-7.3.0beta3/Zend/zend_cpuinfo.c#L31-L35>
 [2018-08-31 10:58 UTC] php-bugs-2018 at ryandesign dot com
clang defines __GNUC__. clang identifies itself as gcc 4.2.1. If you want to check if it's actually clang, you could check for __clang__.
 [2018-09-04 09:28 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3497b75b732723b2f8d0745336d9fcaccb2e3dd7
Log: Fixed bug #76825 (Undefined symbols ___cpuid_count)
 [2018-09-04 09:28 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2018-10-05 02:33 UTC] php-bugs-2018 at ryandesign dot com
The problem is still there in 7.3.0RC2.

The system does have cpuid.h, but this cpuid.h does not have __cpuid_count.

Here is a fresh build log from PHP 7.3.0RC2:

https://build.macports.org/builders/ports-10.7_x86_64_legacy-builder/builds/78703/steps/install-port/logs/stdio
 [2018-10-05 09:54 UTC] cmb@php.net
-Status: Closed +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-10-05 09:54 UTC] cmb@php.net
Does it work for you if you remove the HAVE_CPUID_H part[1] (plus
the respective #endif[2])?

[1] <https://github.com/php/php-src/blob/php-7.3.0RC2/Zend/zend_cpuinfo.c#L32-L37>
[2] <https://github.com/php/php-src/blob/php-7.3.0RC2/Zend/zend_cpuinfo.c#L45>
 [2018-10-15 19:32 UTC] php-bugs-2018 at ryandesign dot com
-Status: Feedback +Status: Assigned
 [2018-10-15 19:32 UTC] php-bugs-2018 at ryandesign dot com
Yes, if I edit Zend/zend_cpuinfo.c and change "# ifdef HAVE_CPUID_H" to "# if 0" then it builds and runs. So I think it just needs a more specific check for the existence of __cpuid_count and not just the existence of cpuid.h.
 [2018-10-17 11:59 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: check-cpuid-count
Revision:   1539777596
URL:        https://bugs.php.net/patch-display.php?bug=76825&patch=check-cpuid-count&revision=1539777596
 [2018-10-17 12:00 UTC] cmb@php.net
-Status: Assigned +Status: Feedback
 [2018-10-17 12:00 UTC] cmb@php.net
Please check the attached check-cpuid-count patch.
 [2018-10-26 14:36 UTC] php-bugs-2018 at ryandesign dot com
-Status: Feedback +Status: Assigned
 [2018-10-26 14:36 UTC] php-bugs-2018 at ryandesign dot com
Sorry for the delay. The configure test says __cpuid_count
is available, though it's obviously not. Here's what
config.log says about it:


configure:5874: checking whether __cpuid_count is available
configure:5896: /usr/bin/clang -c -pipe -Os -arch x86_64 -fvisibility=hidden -I/opt/local/include -no-cpp-precomp conftest.c >&5
conftest.c:34:3: warning: implicit declaration of function '__cpuid_count' is invalid in C99 [-Wimplicit-function-declaration]
  __cpuid_count(0, 0, eax, ebx, ecx, edx);
  ^
1 warning generated.
configure:5896: $? = 0
configure:5907: result: yes


It looks like the problem is that the compiler is being
invoked using the "-c" flag, which skips the link phase
which is where the error occurs. I can reproduce this
with a small test program:


$ clang -c test.c; echo $?
test.c:5:1: warning: implicit declaration of function '__cpuid_count' is invalid in C99 [-Wimplicit-function-declaration]
__cpuid_count(0, 0, eax, ebx, ecx, edx);
^
1 warning generated.
0


$ clang test.c; echo $?
test.c:5:1: warning: implicit declaration of function '__cpuid_count' is invalid in C99 [-Wimplicit-function-declaration]
__cpuid_count(0, 0, eax, ebx, ecx, edx);
^
1 warning generated.
Undefined symbols for architecture x86_64:
  "___cpuid_count", referenced from:
      _main in test-eIiJ3P.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1
 [2018-10-26 14:46 UTC] cmb@php.net
> It looks like the problem is that the compiler is being invoked
> using the "-c" flag, which skips the link phase which is where
> the error occurs.

Then we'll have to replace the `AC_COMPILE_IFELSE` with
`AC_LINK_IFELSE`.  Can you please try that?
 [2018-10-26 15:58 UTC] php-bugs-2018 at ryandesign dot com
Yes, it works with AC_LINK_IFELSE. Thanks!
 [2018-11-05 17:26 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7625f972db10fe1a69757b97c6dec57ea049129b
Log: Fix #76825: Undefined symbols ___cpuid_count
 [2018-11-05 17:26 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Dec 13 22:01:26 2018 UTC