View Issue Details

IDProjectCategoryView StatusLast Update
0002007XdebugInstallationpublic2021-09-16 08:47
Reporterryandesign Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status acknowledgedResolutionopen 
Platformx86_64OSOS XOS Version10.11
Product Version3.0.4 
Target Version3.1dev 
Summary0002007: xdebug 3.x fails to build on OS X 10.11 or earlier due to clock_gettime_nsec_np requirement
DescriptionHi, I'm the maintainer of [[https://ports.macports.org/port/php-xdebug|xdebug in MacPorts]], and [[https://trac.macports.org/ticket/63350|a user reported]] that xdebug 3.0.4 does not build on their Mac running OS X 10.11. The errors are:

src/lib/timing.c:111:9: warning: implicit declaration of function 'clock_gettime_nsec_np' is invalid in C99 [-Wimplicit-function-declaration]
        return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
               ^
src/lib/timing.c:111:31: error: use of undeclared identifier 'CLOCK_UPTIME_RAW'
        return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
                                     ^
1 warning and 1 error generated.


The problem is that functions ''clock_gettime'', ''clock_gettime_nsec_np'', and related constants were introduced in macOS 10.12.

The problem started in xdebug 3 due to [[https://github.com/xdebug/xdebug/commit/632c8a04fad70fefa5fd5e1005270f3e07c76789|this commit]] which introduced the use of ''clock_gettime'' for Linux and ''clock_gettime_nsec_np'' for macOS.

It looks like on Linux xdebug allows for the situation where the OS does not support ''clock_gettime''. Might that be extended to macOS as well?
Steps To ReproduceBuild xdebug 3 or later on OS X 10.11 or earlier.
TagsNo tags attached.
Operating SystemOS X 10.11
PHP Version8.0.0-8.0.4

Activities

ryandesign

2021-08-12 06:55

reporter   ~0005974

Sorry, my use of Mantis formatting codes did not work as I intended and I don't see a way to edit my report to correct the problem.

derick

2021-08-12 17:59

administrator   ~0005975

I don't have access to OSX 10.11 (or any OSX, beside 10.15 through Azure Pipelines), but I believe the branch issue2007-osx1011-timing on GitHub should fix the problem:
https://github.com/derickr/xdebug/tree/issue2007-osx1011-timing

Can you check that branch yourself to verify this perhaps? And also run the tests (https://github.com/xdebug/xdebug#testing)?

ryandesign

2021-08-13 11:00

reporter   ~0005976

> Can you check that branch yourself to verify this perhaps?

This does build on OS X 10.11, thanks. Configure output says:

checking for gettimeofday... yes
checking for clock_gettime... no
checking for clock_gettime_nsec_np... no

and presumably the functionality based on clock_gettime or clock_gettime_nsec_np is not included. How important is this functionality? In MacPorts we have a library of compatibility functions for older systems and we do have an implementation of clock_gettime but don't have clock_gettime_nsec_np yet. If I include that library on 10.11, then configure output says:

checking for gettimeofday... yes
checking for clock_gettime... yes
checking for clock_gettime_nsec_np... no

and the build still succeeds and presumably now uses clock_gettime. Is xdebug better when it can use clock_gettime such that it would be preferable for MacPorts to include this compatibility library?

> And also run the tests (https://github.com/xdebug/xdebug#testing)?

I have not run the tests before so I cannot be sure that I'm doing it correctly. On 10.11 with this change I get 47 test failures but on macOS 10.13 without this change (but with more PHP extensions installed) I get 90 test failures (including the same 47 that failed on 10.11) so I do not believe this change causes any new problems.

derick

2021-08-13 13:14

administrator   ~0005977

I had missed that OSX 10.11 does support clock_gettime, as although it is checked for, it is not used for OSX. It instead falls back to gettimeofday. For most purposes, this is totally usable. The ultra high precision of clock_gettime(_nsec_np) is hardly ever goign to be noticable, so I wouldn't worry about including your compatibility library.

Running just the Xdebug tests with "php run-xdebug-tests.php" (and xdebug.so enabled in your standard php.ini (php --ini) with "zend_extension=xdebug.so") should not see any test failures though. So I'm kind of interesting to see the output of that command.

ryandesign

2021-08-13 13:45

reporter   ~0005978

To clarify: macOS 10.12 introduced support for clock_gettime, clock_gettime_nsec_np, and whatever other related defines and functionality exist; OS X 10.11 and earlier do not have them.

MacPorts has a compatibility library that we can insert that provides an implementation of clock_gettime for 10.11 and older but we have not yet written a compatibility implementation of clock_gettime_nsec_np.

Unless I misunderstand, after your changes, and with the MacPorts compatibility library providing clock_gettime on 10.11, your code will follow the "Linux/Unix with clock_gettime" code path and define a xdebug_get_nanotime_rel function that uses clock_gettime. In xdebug_nanotime_init, because defined(CLOCK_MONOTONIC) (it is defined in the modified system headers provided by the MacPorts compatibility library), context.use_rel_time will be set to 1. And in xdebug_nanotime_init and xdebug_get_nanotime, again because defined(CLOCK_MONOTONIC), xdebug_get_nanotime_rel will be called. If we do not include the MacPorts compatibility library, then there will be no clock_gettime function, no CLOCK_MONOTONIC define, and a xdebug_get_nanotime_rel function will not be defined or called, and then you fall back to using xdebug_get_nanotime_abs which calls gettimeofday.

I've attached the test results from 10.11.

derick

2021-08-15 18:26

administrator   ~0005979

I have now merged the PR/branch into master. I did make a few tweaks to use more of `HAVE_CLOCK_GETTIME_*` to be more consistent, and hopefully more portable. It compiles and works on macOS 10.15 as per CI, but if you could give it one more go, that'd be appreciated.

I also had a look at your test failures, and it seems to me that the tests were *not* run against the newly built .so file, as there are test failures, and changes in output, that are present in the new code in the master branch, but not in older versions. I am going to guess you didn't run a "make install" before running the tests. That's no big deal, but it would probably explain why you have so many failures.

MergeMarc

2021-09-14 16:00

reporter   ~0006005

I had the same issue when trying to install the latest xdebug version (3.0.X) on my OS X 10.11 Mac with Homebrew.

I now tested the 3.1 beta release (3.1.0beta2).
I get a different error with the new changes:
<code>
/private/tmp/pear/temp/xdebug/src/lib/timing.c:120:6: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
            ^
/private/tmp/pear/temp/xdebug/src/lib/timing.c:120:20: error: use of undeclared identifier 'CLOCK_MONOTONIC'
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
                          ^
1 warning and 1 error generated.
</code>

Issue History

Date Modified Username Field Change
2021-08-12 06:54 ryandesign New Issue
2021-08-12 06:55 ryandesign Note Added: 0005974
2021-08-12 17:59 derick Assigned To => derick
2021-08-12 17:59 derick Status new => feedback
2021-08-12 17:59 derick Note Added: 0005975
2021-08-12 17:59 derick Description Updated
2021-08-13 11:00 ryandesign Note Added: 0005976
2021-08-13 11:00 ryandesign Status feedback => assigned
2021-08-13 13:14 derick Status assigned => feedback
2021-08-13 13:14 derick Note Added: 0005977
2021-08-13 13:45 ryandesign Note Added: 0005978
2021-08-13 13:45 ryandesign File Added: php_test_results_20210813_1039.txt.bz2
2021-08-13 13:45 ryandesign Status feedback => assigned
2021-08-15 18:26 derick Status assigned => feedback
2021-08-15 18:26 derick Note Added: 0005979
2021-09-14 16:00 MergeMarc Note Added: 0006005
2021-09-16 08:47 derick Status feedback => acknowledged
2021-09-16 08:47 derick Target Version => 3.1dev