devel-nytprof icon indicating copy to clipboard operation
devel-nytprof copied to clipboard

Makefile.PL uses wrong system header path when Perl has been compiled with -Dsysroot

Open vrkosk opened this issue 9 months ago • 3 comments

Makefile.PL sets include directories like so:

push @h_dirs, split /:/, $ENV{INCLUDE} if $ENV{INCLUDE};
push @h_dirs, split ' ', $Config{libsdirs};
push @h_dirs, qw(/include /usr/include /usr/local/include /usr/include/mach);

Why is it using $Config{libsdirs}? I have built a (relocatable) Perl using -Dsysroot, which means libsdirs is set to:

$ perl -MConfig -E 'say $Config{libsdirs}'
/pkgs64/centos6-sysroot/usr/lib/../lib64

When I run perl Makefile.PL, it emits a compiler warning that causes gettime to be disabled:

Looking for header files and functions...
/usr/include/time.h:37:10: fatal error: bits/types/clock_t.h: No such file or directory
   37 | #include <bits/types/clock_t.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

The reason is, $Config{libsdirs} doesn't contain any system headers from the sysroot, so it's defaulting to the host system's /usr/include. Changing Makefile.PL to $Config{incpth} fixes it. In my Perl, it's:

$ perl -MConfig -E 'say $Config{incpth}'
/pkgs64/gcc/11.3.0-c6/bin/../lib/gcc/x86_64-pc-linux-gnu/11.3.0/include /pkgs64/gcc/11.3.0-c6/bin/../lib/gcc/x86_64-pc-linux-gnu/11.3.0/include-fixed /pkgs64/centos6-sysroot/usr/local/include /pkgs64/gcc/11.3.0-c6/bin/../lib/gcc/../../include /pkgs64/centos6-sysroot/usr/include

Unfortunately, this isn't the end of the story! With the defaults, the link command is:

LD_RUN_PATH="/pkgs64/centos6-sysroot/lib/../lib64" gcc  -shared -O2 --sysroot=/pkgs64/centos6-sysroot -L/pkgs64/centos6-sysroot/usr/local/lib -fstack-protector-strong  FileHandle.o NYTProf.o  -o blib/arch/auto/Devel/NYTProf/NYTProf.so  \
   -lrt   

This looks OK, but I think the LD_RUN_PATH is wrong (and this could be an ExtUtils::MakeMaker problem), because the tests fail immediately with:

Can't load 'Devel-NYTProf-6.14/blib/arch/auto/Devel/NYTProf/NYTProf.so' for module Devel::NYTProf: /pkgs64/centos6-sysroot/lib/../lib64/librt.so.1: undefined symbol: __vdso_clock_gettime, version GLIBC_PRIVATE

I can work around it by clearing LIBS:

PERL_MM_OPT="LIBS= " perl Makefile.PL

Which results in the link command:

gcc  -shared -O2 --sysroot=/pkgs64/centos6-sysroot -L/pkgs64/centos6-sysroot/usr/local/lib -fstack-protector-strong  FileHandle.o NYTProf.o  -o blib/arch/auto/Devel/NYTProf/NYTProf.so  

And now all Devel::NYTProf tests pass. To summarise, $Config{libsdirs} definitely seems wrong, but the -lrt issue could be a fault in my sysroot or Perl compilation.

vrkosk avatar May 02 '24 09:05 vrkosk