php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76654 Build failure on Mac OS X on 32-bit Intel
Submitted: 2018-07-22 22:32 UTC Modified: 2019-01-18 12:06 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: php-bugs-2018 at ryandesign dot com Assigned: nikic (profile)
Status: Closed Package: Compile Failure
PHP Version: 7.3.0RC5 OS: Mac OS X 10.6.8
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: php-bugs-2018 at ryandesign dot com
New email:
PHP Version: OS:

 

 [2018-07-22 22:32 UTC] php-bugs-2018 at ryandesign dot com
Description:
------------
PHP 7.3.0alpha4 fails to build on Mac OS X 10.6.8 running on a Mac with a 32-bit Intel processor. Here is a log from the MacPorts automated build system:

https://build.macports.org/builders/ports-10.6_i386_legacy-builder/builds/45941/steps/install-port/logs/stdio

The error is:


Zend/zend_cpuinfo.c: In function ‘zend_cpu_startup’:
Zend/zend_cpuinfo.c:33: error: can't find a register in class ‘BREG’ while reloading ‘asm’
Zend/zend_cpuinfo.c:33: error: can't find a register in class ‘BREG’ while reloading ‘asm’
Zend/zend_cpuinfo.c:33: error: can't find a register in class ‘BREG’ while reloading ‘asm’
Zend/zend_cpuinfo.c:33: error: ‘asm’ operand has impossible constraints
Zend/zend_cpuinfo.c:33: error: ‘asm’ operand has impossible constraints
Zend/zend_cpuinfo.c:33: error: ‘asm’ operand has impossible constraints
{standard input}:27:non-relocatable subtraction expression, "_cpuinfo" minus "L00000000001$pb"
{standard input}:27:symbol: "_cpuinfo" can't be undefined in a subtraction expression
{standard input}:21:non-relocatable subtraction expression, "_cpuinfo" minus "L00000000001$pb"
{standard input}:21:symbol: "_cpuinfo" can't be undefined in a subtraction expression
{standard input}:13:non-relocatable subtraction expression, "_cpuinfo" minus "L00000000001$pb"
{standard input}:13:symbol: "_cpuinfo" can't be undefined in a subtraction expression
make: *** [Zend/zend_cpuinfo.lo] Error 1


This is a regression; PHP 7.2 and earlier built fine on Macs with 32-bit Intel processors.

PHP 7.3.0alpha4 builds fine on Mac OS X 10.6.8 and later on a Mac with a 64-bit Intel processor, and on Mac OS X 10.5.8 on a Mac with a 32-bit PowerPC processor.


Patches

zend_cpuinfo.c.patch (last revision 2018-11-15 09:18 UTC by php-bugs-2018 at ryandesign dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-24 09:40 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2018-07-24 09:40 UTC] cmb@php.net
The PR has been merged; please try with a recent Git snapshot.
 [2018-08-26 17:02 UTC] cmb@php.net
-Status: Feedback +Status: No Feedback
 [2018-08-26 17:02 UTC] cmb@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2018-09-30 04:00 UTC] php-bugs-2018 at ryandesign dot com
-Status: No Feedback +Status: Closed
 [2018-09-30 04:00 UTC] php-bugs-2018 at ryandesign dot com
Please reopen; the problem remains with 7.3.0RC2.

Here is a full build log of the failure on 10.6.8 i386:

https://build.macports.org/builders/ports-10.6_i386_legacy-builder/builds/49799/steps/install-port/logs/stdio

For comparison, here is a build log of success on 10.6.8 x86_64:

https://build.macports.org/builders/ports-10.6_x86_64_legacy-builder/builds/77655/steps/install-port/logs/stdio

And a build log of success on 10.5.8 ppc:

https://build.macports.org/builders/ports-10.5_ppc_legacy-builder/builds/75623/steps/install-port/logs/stdio
 [2018-09-30 05:02 UTC] requinix@php.net
-Status: Closed +Status: Re-Opened -Assigned To: cmb +Assigned To:
 [2018-11-15 07:12 UTC] php-bugs-2018 at ryandesign dot com
-PHP Version: 7.3.0alpha4 +PHP Version: 7.3.0RC5
 [2018-11-15 07:12 UTC] php-bugs-2018 at ryandesign dot com
I've attached a patch that compiles for me, on 32-bit Mac OS X 10.6.

What I've learned is that gcc 4.2 (at least the Apple-modified version
shipped in old Xcode) uses position-independent code (PIC) by default,
and that on i386 this compiler uses the %ebx register to store the PIC
global offset table, but the cpuid opcode overwrites %ebx, hence the
error. So %ebx needs to be preserved before calling cpuid and restored
afterward.

I've modeled my patch on the method used by cpuid.h from Xcode 5.1.1
on OS X 10.8, which is as follows:


/* PIC on i386 uses %ebx, so preserve it. */
#if __i386__
#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
    __asm("  pushl  %%ebx\n" \
          "  cpuid\n" \
          "  mov    %%ebx,%1\n" \
          "  popl   %%ebx" \
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
        : "0"(__level))

#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \
    __asm("  pushl  %%ebx\n" \
          "  cpuid\n" \
          "  mov    %%ebx,%1\n" \
          "  popl   %%ebx" \
        : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
        : "0"(__level), "2"(__count))
#else
#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
    __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
                  : "0"(__level))

#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \
    __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
                  : "0"(__level), "2"(__count))
#endif


It seems that cpuid.h is closely tied to and belongs with a
particular compiler. The cpuid.h from Xcode 9.4.1 on macOS 10.13 does
it differently, for example, but that's for a much more recent version
of clang. And since this code in PHP is only going to be used by
compilers that don't provide a cpuid.h, maybe using this old
implementation is the correct thing to do.

With my patch it compiles, but I don't know if the result is correct.
I don't know how this command is used within PHP. Is there a PHP
command I should run, or a particular test in the test suite that I
should look at, to verify it's working right?
 [2018-11-15 09:21 UTC] php-bugs-2018 at ryandesign dot com
I revised the patch to only preserve %ebx when building with PIC, after
looking at what libwebp did:

https://github.com/webmproject/libwebp/blob/a4399721759f183bcc7c1d69c2f7eba1ceb8d1a2/src/dsp/cpu.c#L30

I see that their implementation for preserving %ebx is one instruction
shorter... not sure if it's worth changing it though.

If you'd rather have this patch as a PR let me know.
 [2018-12-08 15:58 UTC] php-bugs-2018 at ryandesign dot com
I've submitted the patch as a PR: https://github.com/php/php-src/pull/3704
 [2019-01-18 12:06 UTC] nikic@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: nikic
 [2019-01-18 12:06 UTC] nikic@php.net
PR has been merged, so closing this bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC