arsv / perl-cross

configure and cross-compile perl
Other
81 stars 29 forks source link

Time::HiRes is missing clock_gettime() #103

Closed stefanalt closed 3 years ago

stefanalt commented 3 years ago

I cross build with buildroot for an X86-linux-glibc platform. Perl 5.30.3, Perl-Cross 1.3.4, but the problem also occurs with older versions. I need clock_gettime to be able to use CLOCK_MONOTONIC. The built HiRes.so does not request clock_getttime() symbol. Hi-res time() is working properly. It looks like this:

nm perl-5.30.3/lib/auto/Time/HiRes/HiRes.so | grep clock_gettime
0000000000002909 t XS_Time__HiRes_clock_gettime

But should look like this:

nm perl-5.30.3/lib/auto/Time/HiRes/HiRes.so | grep clock_gettime
0000000000001e46 t XS_Time__HiRes_clock_gettime
                 U clock_gettime@@GLIBC_2.2.5

My investigation so far:

perl-5.30.3/dist/Time-HiRes/xdefine is missing: -DTIME_HIRES_CLOCK_GETTIME

In dist/Time-HiRes/Makefile.PL

    print "Looking for clock_gettime()... ";
    my $has_clock_gettime;
    my $has_clock_gettime_emulation;
    if (exists $Config{d_clock_gettime}) {
        $has_clock_gettime++ if $Config{d_clock_gettime}; # Unlikely...
    } elsif (has_clock_xxx('gettime')) {
        $has_clock_gettime++;
        $DEFINE .= ' -DTIME_HIRES_CLOCK_GETTIME';
    } ...

Seems the first if() is triggered by a pre-set $Config ? If I modify to if( 0 and ....), then Makefile.PL properly detects clock_gettime() and finally builds the .so file correctly.

However, for this to work TIME_HIRES_DONT_RUN_PROBES=1 must be in the ENV.

Or is there a better solution to this.

arsv commented 3 years ago

The problem there is that Makefile.PL wants to build and run tests to figure out what's supported, which is a no-go for cross builds. So instead top-level configure does a quick compile-only test for clock_gettime and sets $Config{d_clock_gettime} = 'define' to suppress testing in Time::HiRes Makefile.PL and force it to build clock_gettime support. That "unlikely" case is exactly what's supposed to happen during cross builds.

Something clearly isn't working as intended though. It's not building clock_gettime support for me either even though d_clock_gettime gets set correctly. Looking into this.

arsv commented 3 years ago

Should be fixed now.