View Issue Details

IDProjectCategoryView StatusLast Update
0002007XdebugInstallationpublic2021-10-04 09:29
Reporterryandesign Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86_64OSOS XOS Version10.11
Product Version3.0.4 
Target Version3.1devFixed in Version3.1.0 
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

Last edited: 2021-09-19 09:27

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:
/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.

derick

2021-09-19 09:26

administrator   ~0006019

@MergeMarc:
1. Did you use fresh sources? If not, please do a new GitHub checkout, and try in there
2. What is the output of "./configure" and config.log? (Please attach as file)
3. Can you also try the following patch, if 1 doesn't work.

diff --git src/lib/timing.c src/lib/timing.c
index 269072b7..3194e771 100644
--- src/lib/timing.c
+++ src/lib/timing.c
@@ -22,6 +22,12 @@
 # include <sys/time.h>
 #endif
 
+#if HAVE_CLOCK_GETTIME
+# if defined(__APPLE)
+#  include <time.h>
+# endif
+#endif
+
 #if HAVE_CLOCK_GETTIME_NSEC_NP
 # if defined(__APPLE)
 #  include <mach/mach_time.h>

derick

2021-09-22 13:25

administrator   ~0006031

FWIW, if any of you are interested in this being fixed, I do need to some assistance, for example by answering my questions. Xdebug 3.1 is going to be released next week, and it would be a shame if this issue wasn't addressed.

MergeMarc

2021-09-23 10:11

reporter   ~0006035

@derick
Sorry for the delayed response. I’m not that proficient with make yet as pecl usually does that all for me.

I cloned the repo so I could try building current master. The build failed in the same way. I attached the output of configure as well as the configure.log.

I then applied your diff and ran phpize, configure and make again. Sadly, make exited with the same error as described previously (Maybe not relevant but make also seemed to error out much faster than before applying the diff). I also attached the output of configure and configure.log of that try (see files with -withdiff suffix).

Error output with the diff applied (just the line numbers changed):
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:126:6: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
            ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:126:20: error: use of undeclared identifier 'CLOCK_MONOTONIC'
        if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
                          ^
1 warning and 1 error generated.

derick

2021-09-23 12:50

administrator   ~0006036

Your config.log includes:

configure:4607: checking for clock_gettime
configure:4607: cc -o conftest -g -O2 -I/usr/local/Cellar/php/8.0.10/include/php -I/usr/local/Cellar/php/8.0.10/include/php/main -I/usr/local/Cellar/php/8.0.10/include/php/TSRM -I/usr/local/
Undefined symbols for architecture x86_64:
  "_clock_gettime", referenced from:
      _main in conftest-79309a.o
…
configure:4607: result: no


And your configure-output file:
checking for clock_gettime... no
checking for clock_gettime_nsec_np... no


Which seems plausible. If this is not found, then HAVE_CLOCK_GETTIME should not be set. The code that you say ("I cloned the repo so I could try building current master.") doesn't compile has this in the "master" branch at the moment:

115 #elif HAVE_CLOCK_GETTIME
116 static uint64_t xdebug_get_nanotime_rel(xdebug_nanotime_context *nanotime_context)
117 {
118     struct timespec ts;
119 
120     if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
121         return (uint64_t)ts.tv_sec * NANOS_IN_SEC + (uint64_t)ts.tv_nsec;
122     }
123 
124     return 0;
125 }
126 #endif


Line 126 (where you see your error), doesn't have a clock_gettime line, and it also should never try to compile this code because HAVE_CLOCK_GETTIME is not set.

Something seems wrong on your side.

Can you show all the *exact* steps, from the beginning, with a cleanly checked out GIT repository in a new directory?

MergeMarc

2021-09-23 13:25

reporter   ~0006038

Thank you for looking into my reported details of the issue.

The error output of make I provided in my last comment was WITH the provided patch for src/lib/timing.c applied. The patch added 6 lines to the file hence the line with “clock_gettime” is offset by 6 lines (Line 126 instead of 120) when compared to master. I kept calling the patch “diff” in my previous comment, I’m sorry if that caused any confusion.

I will follow up with a step by step description of my process with a freshly cloned repo (and no patch) shortly.

MergeMarc

2021-09-23 13:52

reporter   ~0006039

Here are the step by step instructions of what I’m doing (also see the attachments for the full outputs):

$ mkdir /tmp/xdebug3
$ cd /tmp/xdebug3
$ git clone git://github.com/xdebug/xdebug.git
$ cd xdebug
$ git log -1
commit b9dbb8163c8f74a7d26e2805f900c63d638683b6 (HEAD -> master, origin/master, origin/HEAD)
Merge: 9f34d187 85192199
Author: Derick Rethans <github@derickrethans.nl>
Date:   Wed Sep 22 11:07:43 2021 +0100

    Merge branch 'xdebug_3_1'
$ phpize
$ ./configure
$ make

derick

2021-09-23 14:32

administrator   ~0006040

Ok, besides the different line numbers... this is still baffling as configure output says:

checking for clock_gettime... no
checking for clock_gettime_nsec_np... no


Which means that HAVE_CLOCK_GETTIME does not get defined, but your preprocessor still doesn't remove the bit that uses clock_gettime, which is keyed for by HAVE_CLOCK_GETTIME.

Would you mind zipping/tarring up the current state of /tmp/xdebug3, and attaching that?

MergeMarc

2021-09-23 16:54

reporter   ~0006044

I found where HAVE_CLOCK_GETTIME is defined but I cannot make much sense of it.

I managed to figure out that HAVE_CLOCK_GETTIME was, in fact, set to 1.
I used the following snipped to figure this out:
#define STRING2(x) #x
#define STRING(x) STRING2(x)
#pragma message(STRING(HAVE_CLOCK_GETTIME))


I then laced some relevant files with this snipped trying to figure out where HAVE_CLOCK_GETTIME was being set.
I ended up in php_xdebug.h. HAVE_CLOCK_GETTIME was set after these php headers(?) where included:
28: #include "php.h"


Since these don’t exist in the project I searched my php installations. I found the file that set HAVE_CLOCK_GETTIME: /usr/local/Cellar//php/8.0.10/include/php/main/php_config.h
445 /* */
446 /* #undef HAVE_CLI0EXT_H */
447
448 /* do we have clock_gettime? */
449 #define HAVE_CLOCK_GETTIME 1
450
451 /* do we have clock_get_time? */
452 /* #undef HAVE_CLOCK_GET_TIME */
453
454 /* */
455 /* #undef HAVE_CODBC */


Changing that line to the following let make compile xdebug without an issue.
449 /* #undef HAVE_CLOCK_GETTIME */


With that the problem lies somewhat out of the scope of xdebug I think. But I don’t understand why this was set in my PHP installation in the first place.
Running “pecl install xdebug-3.1.0beta2” also ran after this manual fix with no errors.

derick

2021-09-24 13:50

administrator   ~0006048

Thanks for doing that investigation. I think I might have a way to solve this without having to "hack" the PHP include files.

I've prepared the "better-clock-checks" branch, which I think should solve this problem. Could you:
1. revert the change that you've made to /usr/local/Cellar//php/8.0.10/include/php/main/php_config.h (line 449, I think)
2. check out the `better-clock-checks` branch
3. run: phpize && ./configure && make && make install
4. If that compiles, run: php -r 'xdebug_info();' | grep Clock
5. show the output of: grep -r XDEBUG_CLOCK config.h

MergeMarc

2021-09-24 16:26

reporter   ~0006049

Thank you for the update.
I removed my xdebug installation, reverted my changes in php_config.h and cloned the repo into a fresh directory and switched to branch "better-clock-checks".

Make built successfully with only one warning (see attachments for full outputs):
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:154:22: warning: implicit declaration of function 'xdebug_get_nanotime_rel' is invalid in C99
      [-Wimplicit-function-declaration]
        context.start_rel = xdebug_get_nanotime_rel(&context);
                            ^
1 warning generated.

But even doe xdebug was successfully compiled, after enabling it, php was throwing the following error whenever called:
dyld: lazy symbol binding failed: Symbol not found: _xdebug_get_nanotime_rel
  Referenced from: /usr/local/lib/php/pecl/20200930/xdebug.so
  Expected in: flat namespace

dyld: Symbol not found: _xdebug_get_nanotime_rel
  Referenced from: /usr/local/lib/php/pecl/20200930/xdebug.so
  Expected in: flat namespace

Trace/BPT trap: 5


Output of the grep command (step 5):
config.h:/* #undef HAVE_XDEBUG_CLOCK_GETTIME */
config.h:#define HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP 0

derick

2021-09-26 16:00

administrator   ~0006051

I think I have just pushed a fix for this. Could you check again with the same steps? There is an extra commit on the branch, so a "git pull" should fetch that.

derick

2021-09-28 13:55

administrator   ~0006055

It'd be great of you could have a look @MergeMarc — I'd love to have this in this week's Xdebug 3.1.0 release.

MergeMarc

2021-09-29 14:14

reporter   ~0006059

Sorry for the delayed response. I just started college and it can take me a few days sometimes to test things again.

I pulled the changes. Sadly, make now outputs a bunch of errors:
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:170:15: error: no member named 'use_rel_time' in 'struct _xdebug_nanotime_context'
        if (context->use_rel_time) {
            ~~~~~~~  ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:171:14: warning: implicit declaration of function 'xdebug_get_nanotime_rel' is invalid in C99 [-Wimplicit-function-declaration]
                nanotime = xdebug_get_nanotime_rel(context);
                           ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:173:27: error: no member named 'last_rel' in 'struct _xdebug_nanotime_context'
                if (nanotime < context->last_rel + NANOTIME_MIN_STEP) {
                               ~~~~~~~  ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:174:13: error: no member named 'last_rel' in 'struct _xdebug_nanotime_context'
                        context->last_rel += NANOTIME_MIN_STEP;
                        ~~~~~~~  ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:175:24: error: no member named 'last_rel' in 'struct _xdebug_nanotime_context'
                        nanotime = context->last_rel;
                                   ~~~~~~~  ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:177:12: error: no member named 'last_rel' in 'struct _xdebug_nanotime_context'
                context->last_rel = nanotime;
                ~~~~~~~  ^
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.c:178:56: error: no member named 'start_rel' in 'struct _xdebug_nanotime_context'; did you mean 'start_abs'?
                nanotime = context->start_abs + (nanotime - context->start_rel);
                                                                     ^~~~~~~~~
                                                                     start_abs
/Users/USERNAME/Documents/Projekte/xdebug/src/lib/timing.h:29:11: note: 'start_abs' declared here
        uint64_t start_abs;
                 ^
1 warning and 6 errors generated.
make: *** [src/lib/timing.lo] Error 1

New outputs and logs attached.
Thank you for still looking into this.

derick

2021-09-29 15:03

administrator   ~0006060

OK, that was my bad and I forgot to update a line. I suppose I couldn't have temporary access to a user account if the commit that I've just pushed didn't resolve this?

MergeMarc

2021-09-29 15:24

reporter   ~0006061

I pulled the fix. The compilation and install works fine now! I also tested line by line debugging with it and that also works without any issues.

Here are the answers to questions you asked earlier:

Output of “php -r 'xdebug_info();' | grep Clock”:
 
Clock Source => gettimeofday

Output of “grep -r XDEBUG_CLOCK config.h”:
 
config.h:/* #undef HAVE_XDEBUG_CLOCK_GETTIME */
config.h:#define HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP 0

derick

2021-09-29 16:58

administrator   ~0006062

Excellent! I'll merge and close this then.

derick

2021-09-29 17:00

administrator   ~0006063

https://github.com/xdebug/xdebug/pull/790

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
2021-09-19 09:26 derick Status acknowledged => feedback
2021-09-19 09:26 derick Note Added: 0006019
2021-09-19 09:27 derick Note Edited: 0006005
2021-09-22 13:25 derick Note Added: 0006031
2021-09-23 10:11 MergeMarc Note Added: 0006035
2021-09-23 10:11 MergeMarc File Added: config.log
2021-09-23 10:11 MergeMarc File Added: config.log-withdiff
2021-09-23 10:11 MergeMarc File Added: configure-output
2021-09-23 10:11 MergeMarc File Added: configure-output-withdiff
2021-09-23 12:50 derick Note Added: 0006036
2021-09-23 13:25 MergeMarc Note Added: 0006038
2021-09-23 13:52 MergeMarc Note Added: 0006039
2021-09-23 13:52 MergeMarc File Added: config-2.log
2021-09-23 13:52 MergeMarc File Added: output-configure
2021-09-23 13:52 MergeMarc File Added: output-make
2021-09-23 13:52 MergeMarc File Added: output-phpize
2021-09-23 14:32 derick Note Added: 0006040
2021-09-23 16:54 MergeMarc Note Added: 0006044
2021-09-24 13:50 derick Note Added: 0006048
2021-09-24 16:26 MergeMarc Note Added: 0006049
2021-09-24 16:26 MergeMarc File Added: config-3.log
2021-09-24 16:26 MergeMarc File Added: output-configure_clock-checks
2021-09-24 16:26 MergeMarc File Added: output-make_clock-checks
2021-09-24 16:26 MergeMarc File Added: output-make-install_clock-checks
2021-09-24 16:26 MergeMarc File Added: output-phpize_clock-checks
2021-09-26 16:00 derick Note Added: 0006051
2021-09-28 13:55 derick Note Added: 0006055
2021-09-29 14:14 MergeMarc Note Added: 0006059
2021-09-29 14:14 MergeMarc File Added: config-4.log
2021-09-29 14:14 MergeMarc File Added: output-configure-2
2021-09-29 14:14 MergeMarc File Added: output-make-2
2021-09-29 14:14 MergeMarc File Added: output-phpize-2
2021-09-29 15:03 derick Note Added: 0006060
2021-09-29 15:24 MergeMarc Note Added: 0006061
2021-09-29 16:58 derick Note Added: 0006062
2021-09-29 17:00 derick Status feedback => closed
2021-09-29 17:00 derick Resolution open => fixed
2021-09-29 17:00 derick Fixed in Version => 3.1dev
2021-09-29 17:00 derick Note Added: 0006063
2021-09-30 12:29 derick File Deleted: configure-output-withdiff
2021-09-30 12:29 derick File Deleted: config.log
2021-09-30 12:29 derick File Deleted: output-phpize-2
2021-09-30 12:30 derick File Deleted: output-make-2
2021-09-30 12:30 derick File Deleted: output-configure-2
2021-09-30 12:30 derick File Deleted: config-4.log
2021-09-30 12:30 derick File Deleted: output-phpize_clock-checks
2021-09-30 12:30 derick File Deleted: output-make-install_clock-checks
2021-09-30 12:30 derick File Deleted: output-make_clock-checks
2021-09-30 12:30 derick File Deleted: output-configure_clock-checks
2021-09-30 12:30 derick File Deleted: config-3.log
2021-09-30 12:31 derick File Deleted: config.log-withdiff
2021-09-30 12:31 derick File Deleted: configure-output
2021-09-30 12:31 derick File Deleted: config-2.log
2021-09-30 12:31 derick File Deleted: output-configure
2021-09-30 12:31 derick File Deleted: output-phpize
2021-09-30 12:31 derick File Deleted: output-make
2021-10-04 09:29 derick Fixed in Version 3.1dev => 3.1.0