oracle / dtrace-utils

DTrace-utils contains the DTrace port to Linux
Other
118 stars 17 forks source link

2.0.0-1.1: build fails with `__KERNEL__` redefined #71

Open kloczek opened 3 months ago

kloczek commented 3 months ago
[tkloczko@pers-jacek dtrace-utils-2.0.0-1.14]$ make
M4: libdtrace/procfs.d.in
Macro "TASK_RUNNING" has no definition on this system.
libdtrace/procfs.m4:14:9: warning: "__KERNEL__" redefined
   14 | #define __KERNEL__
      |         ^~~~~~~~~~
<command-line>: note: this is the location of the previous definition
Error: Not all tokens in libdtrace/procfs.d.in defined in headers.
kvanhees commented 3 months ago

This typically means that you do not have the kernel development headers package installed for the kernel you are compiling DTrace against. A kernel -devel or -dev package is needed because it is used to generate the translator files.

Future releases will contain pre-generated translator files, which will make this a non-issue.

kloczek commented 3 months ago

After add to build env kernel-devel package still I see the same error. I'm using fedora rawhide kernel.

In this case additionally I don't see anything which could make something if kernel-devel header are installed do something, and otherwise do something else. In this case error does not show that some headers are missing but that existing define is redefined.

BTW would you potentially accept PR with build framework based on for example meson? 🤔 For example with current make files I cannot enable use compiler passed in $CC, or use exacct build flags passed in $CFLAGS or enable verbose output which should shows all compiler params. Also detection of libelf, libpcap, bison, flex and probably few other looks like is missing. Implementing all that things im plan make files is real nightmare.

Just in case .. I'm not ready yet do prepare such meson support now because I'm still not able to build dtrace and clearly see what needs to be done to build it, however it would be good to know is it any will to potentially accept such PR.

kvanhees commented 3 months ago

From what you describe, I'd guess that the install of the kernel headers package does not match the running kernel and/or that no /lib/modules/ directory with build and source links to the actual headers was installed.

If you install the kernel devel package for the running kernel, it should work because then /lib/modules//build and source will be links to the correct locations.

If you install a kernel devel package that is different, you can still compile DTrace and get translator files generated by adding the following to the make command:

KERNELMODDIR=/usr/src/kernels KERNELSRCNAME= KERNELBLDNAME= KERNELS=

BUT in that case the version of the headers should be EARLIER than the running kernel, because the runtime logic picks up translator files that are as close to the running kernel version but not newer (because newer often means that they do not match anymore).

I hope to have a patch in the devel tree in a few days to introduce pre-generated translator files, to avoid this type of problems.

kloczek commented 3 months ago

If you install a kernel devel package that is different, you can still compile DTrace and get translator files generated by adding the following to the make command:

KERNELMODDIR=/usr/src/kernels KERNELSRCNAME= KERNELBLDNAME= KERNELS=

BUT in that case the version of the headers should be EARLIER than the running kernel, because the runtime logic picks up translator files that are as close to the running kernel version but not newer (because newer often means that they do not match anymore).

I hope to have a patch in the devel tree in a few days to introduce pre-generated translator files, to avoid this type of problems.

Indeed all that is true. System is running on 6.8.4 and kernel headers are from 6.9.0 rc3

With above made small progress ..

+ cd dtrace-utils-2.0.0-1.14
+ ASMFLAGS='-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -grecord-gcc-switches -pipe -mtls-dialect=gnu2 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdata-sections -ffunction-sections -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -flto=auto -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security'
+ CFLAGS='-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -grecord-gcc-switches -pipe -mtls-dialect=gnu2 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdata-sections -ffunction-sections -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -flto=auto -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security'
+ CXXFLAGS='-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -grecord-gcc-switches -pipe -mtls-dialect=gnu2 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdata-sections -ffunction-sections -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -flto=auto -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security'
+ FFLAGS='-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -grecord-gcc-switches -pipe -mtls-dialect=gnu2 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdata-sections -ffunction-sections -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -flto=auto -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security -I/usr/lib64/gfortran/modules'
+ FCFLAGS='-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g -grecord-gcc-switches -pipe -mtls-dialect=gnu2 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fdata-sections -ffunction-sections -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -flto=auto -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -Wall -Werror=format-security -I/usr/lib64/gfortran/modules'
+ LDFLAGS='-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--gc-sections -Wl,--as-needed -Wl,--build-id=sha1 -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-z,pack-relative-relocs -flto=auto -fuse-linker-plugin'
+ RUSTFLAGS='-C codegen-units=1 -C debuginfo=2 -C opt-level=2 -C link-arg=-Wl,--as-needed -C link-arg=-Wl,--build-id=sha1 -C link-arg=-Wl,-z,now -C link-arg=-specs=/usr/lib/rpm/redhat/redhat-hardened-ld -C link-arg=-Wl,-z,pack-relative-relocs -C link-arg=-Wl,-z,relro -C link-arg=-flto=auto --cap-lints=warn'
+ VALAFLAGS=-g
+ CC=/usr/bin/gcc
+ CXX=/usr/bin/g++
+ FC=/usr/bin/gfortran
+ AR=/usr/bin/gcc-ar
+ NM=/usr/bin/gcc-nm
+ RANLIB=/usr/bin/gcc-ranlib
+ export ASMFLAGS CFLAGS CXXFLAGS FFLAGS FCFLAGS LDFLAGS VALAFLAGS CC CXX FC AR NM RANLIB RUSTFLAGS VALAFLAGS
+ ./configure --bindir=/usr/bin --build=x86_64-redhat-linux --datadir=/usr/share --disable-dependency-tracking --exec-prefix=/usr --host=x86_64-redhat-linux --includedir=/usr/include --infodir=/usr/share/info --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --mandir=/usr/share/man --prefix=/usr --program-prefix= --runstatedir=/run --sbindir=/usr/sbin --sharedstatedir=/var/lib --sysconfdir=/etc --with-libsystemd=yes --with-libfuse3=yes
Writing build/config-vars.mk
Writing build/config.{h,mk}
+ /usr/bin/make -O -j48 V=1 VERBOSE=1 -j1 KERNELMODDIR=/usr/src/kernels KERNELSRCNAME= KERNELBLDNAME= KERNELS=
CC: libdtrace/drti.c
libdtrace/drti.c:73:1: warning: constructor priorities from 0 to 100 are reserved for the implementation [-Wprio-ctor-dtor]
   73 | {
      | ^
libdtrace/drti.c: In function ‘dtrace_dof_register’:
libdtrace/drti.c:230:25: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  230 |                         write(2, errmsg_open, strlen(errmsg_open));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libdtrace/drti.c:236:25: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  236 |                         write(2, errmsg_ioctl_failed,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237 |                               strlen(errmsg_ioctl_failed));
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libdtrace/drti.c:240:25: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  240 |                         write(2, ioctl_failed, strlen(ioctl_failed));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libdtrace/drti.c:243:17: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  243 |                 write(2, errmsg_ioctl_ok, strlen(errmsg_ioctl_ok));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: libcommon/dof_parser.c
CC: libcommon/dof_parser_host.c
CC: libcommon/dt_list.c
BUILD-AR: libcommon.a
YACC: libdtrace/dt_grammar.c
VERSION: .git-version
CC: libdtrace/dt_aggregate.c
CC: libdtrace/dt_as.c
CC: libdtrace/dt_bpf.c
CC: libdtrace/dt_buf.c
CC: libdtrace/dt_cc.c
CC: libdtrace/dt_cg.c
CC: libdtrace/dt_conf.c
libdtrace/dt_conf.c: In function ‘dt_conf_init’:
libdtrace/dt_conf.c:118:25: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  118 |                         fscanf(fp, "%u", &ci->cpu_chip);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: libdtrace/dt_consume.c
libdtrace/dt_consume.c:3070:1: warning: conflicting types for ‘dtrace_consume’ due to enum/integer mismatch; have ‘dtrace_workstatus_t(dtrace_hdl_t *, FILE *, int (*)(const dtrace_probedata_t *, void *), int (*)(const dtrace_probedata_t *, const dtrace_recdesc_t *, void *), void *)’ {aka ‘dtrace_workstatus_t(struct dtrace_hdl *, FILE *, int (*)(const struct dtrace_probedata *, void *), int (*)(const struct dtrace_probedata *, const struct dtrace_recdesc *, void *), void *)’} [-Wenum-int-mismatch]
 3070 | dtrace_consume(dtrace_hdl_t *dtp, FILE *fp, dtrace_consume_probe_f *pf,
      | ^~~~~~~~~~~~~~
In file included from libdtrace/dt_impl.h:14,
                 from libdtrace/dt_consume.c:16:
libdtrace/dtrace.h:209:12: note: previous declaration of ‘dtrace_consume’ with type ‘int(dtrace_hdl_t *, FILE *, int (*)(const dtrace_probedata_t *, void *), int (*)(const dtrace_probedata_t *, const dtrace_recdesc_t *, void *), void *)’ {aka ‘int(struct dtrace_hdl *, FILE *, int (*)(const struct dtrace_probedata *, void *), int (*)(const struct dtrace_probedata *, const struct dtrace_recdesc *, void *), void *)’}
  209 | extern int dtrace_consume(dtrace_hdl_t *dtp, FILE *fp,
      |            ^~~~~~~~~~~~~~
libdtrace/dt_consume.c: In function ‘dt_consume_one_probe’:
libdtrace/dt_consume.c:2405:33: warning: ignoring return value of ‘ftruncate’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 2405 |                                 ftruncate(fileno(fp), 0);
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~
CC: libdtrace/dt_debug.c
CC: libdtrace/dt_decl.c
CC: libdtrace/dt_dis.c
CC: libdtrace/dt_dlibs.c
CC: libdtrace/dt_dof.c
CC: libdtrace/dt_error.c
CC: libdtrace/dt_errtags.c
CC: libdtrace/dt_grammar.c
CC: libdtrace/dt_handle.c
CC: libdtrace/dt_htab.c
CC: libdtrace/dt_ident.c
LEX: libdtrace/dt_lex.c
CC: libdtrace/dt_lex.c
CC: libdtrace/dt_link.c
CC: libdtrace/dt_kernel_module.c
CC: libdtrace/dt_map.c
CC: libdtrace/dt_module.c
CC: libdtrace/dt_open.c
CC: libdtrace/dt_options.c
libdtrace/dt_options.c: In function ‘dt_coredump’:
libdtrace/dt_options.c:71:9: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   71 |         write(STDERR_FILENO, msg, sizeof(msg) - 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: libdtrace/dt_parser.c
CC: libdtrace/dt_pcap.c
libdtrace/dt_pcap.c: In function ‘dt_pcap_filename’:
libdtrace/dt_pcap.c:345:25: warning: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  345 |                         read(pipe_err[0], err, 1023);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: libdtrace/dt_pcb.c
CC: libdtrace/dt_peb.c
CC: libdtrace/dt_pid.c
CC: libdtrace/dt_pragma.c
CC: libdtrace/dt_printf.c
libdtrace/dt_printf.c: In function ‘dtrace_freopen’:
libdtrace/dt_printf.c:1627:17: warning: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 1627 |                 asprintf(&faultstr, "couldn't freopen() \"%s\": %s",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1628 |                                 dtp->dt_freopen_filename, strerror(errno));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CC: libdtrace/dt_probe.c
CC: libdtrace/dt_proc.c
CC: libdtrace/dt_program.c
CC: libdtrace/dt_prov_cpc.c
libdtrace/dt_prov_cpc.c:16:10: fatal error: perfmon/pfmlib_perf_event.h: No such file or directory
   16 | #include <perfmon/pfmlib_perf_event.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Looks like it is:

After add libpfm-devel:

CC: libdtrace/dt_work.c
libdtrace/dt_work.c:22:10: fatal error: valgrind/valgrind.h: No such file or directory
   22 | #include <valgrind/valgrind.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

So it is second not checked build dependency. After add valgrind-devel build fails on:

SHLINK: libproc-lookup-victim-lib.so
/bin/bash: line 1: bpf-unknown-none-gcc: command not found
make: *** No rule to make target '/usr/include/bpf/bpf_helper_defs.h', needed by '/home/tkloczko/rpmbuild/BUILD/dtrace-utils-2.0.0-1.14/build/include/bpf_asm_helpers.h'.  Stop.

on first look it looks like some bpftools or libbpt dependency but none of that packages provides that. So I need another hint .. 😋

Additionally I made as well test with running make -k to generate all compiler warning stats:

[tkloczko@pers-jacek todo-2]$ rpmbuild -ba dtrace.spec --quiet 2>&1 | grep -- \\[-W | sed 's/.*\[//; s/\]//' | sort | uniq -c | sort -nr
     29 -Wunused-result
      8 -Wcpp
      1 -Wprio-ctor-dtor
      1 -Wenum-int-mismatch

Do you want me to open new ticket with those stats and extracted all compiler warnings from stderr? 🤔

ezannoni commented 3 months ago

Hi Tomasz, so one big thing that you need for dtrace is the toolchain for BPF. Cross-gcc and cross-binutils. You can look at the RPMs for OL or also they are in debian already. bpf-unknown-none is the target for binutils and gcc. https://tracker.debian.org/pkg/gcc-bpf https://tracker.debian.org/pkg/binutils-bpf Does fedora have these? Specifically these are just another target in the cross-binutils and cross-gcc RPMs. No need for new src RPMs, it is just that new binaries will be created as target for the crosses. I see the rpms are here: https://packages.fedoraproject.org/pkgs/cross-gcc/ and https://src.fedoraproject.org/rpms/cross-binutils (you can look at the OL sources to see what we added (ignore the patches because those versions of binutils and gcc are much older, probably using current upstream is enough)

ezannoni commented 3 months ago

One more thing, you can find us on libera irc in the linux-dtrace channel

kloczek commented 3 months ago

Does fedora have these?

I'm working on m own distro so looks like I'll need to package that 😋

kloczek commented 3 months ago

Just checked m spec file and as same as in case of Fedora I'm building my binutils with TARGS="--enable-targets=x86_64-pep,bpf-unknown-none" so theoretically OOTB it should be possible to use those binaries to compile bpf code and gcc should be be to recognise that arch. Q: how to do do that/what neds to be passed to gcc params? 🤔

ezannoni commented 3 months ago

hmm, i don't know the details, you can download the srpms from yum.oracle.com/repo/OracleLinux/OL9/developer.

Or ( may be better) you can ask on #gccbpf in oftc irc server

kloczek commented 3 months ago

hmm, i don't know the details, you can download the srpms from yum.oracle.com/repo/OracleLinux/OL9/developer.

That link shows me Not a file message.

ezannoni commented 3 months ago

oh yes, sorry I copied but truncated badly: https://yum.oracle.com/oracle-linux-9.html and https://yum.oracle.com/repo/OracleLinux/OL9/developer/x86_64/index_src.html

dafaust commented 3 months ago

Q: how to do do that/what neds to be passed to gcc params? 🤔

If you're asking about building the toolchain, generally the bpf cross does not require any special flags. It is just like building the cross-toolchain for other targets. A simple configure --target=bpf-unknown-none in both binutils and gcc should be enough.

To build gcc you'll need to have the bpf binutils already installed or to use a --prefix where they can be found. For gcc it also makes sense to --enable-languages=c to avoid building the other language front-ends. Also gcov cannot be built for bpf, but it should be disabled by default for the target (if not, as in older gcc versions, add --disable-gcov to gcc configure).

For a distro you likely want to set --bindir=, --libdir=, --infodir=, etc. appropriately.

The debian binutils-bpf and gcc-bpf packages have quite nice simple build rules without noise for building other targets.

ezannoni commented 1 month ago

BTW, I filed fedora bugzillas, feel free to add your need for the crosses there:

https://bugzilla.redhat.com/show_bug.cgi?id=2281043 https://bugzilla.redhat.com/show_bug.cgi?id=2281056

kloczek commented 1 month ago

Thank you. I was to busy to do the same 😋 I have similar issues with other packages like cpu-x and few other which needs to generate similar code so this will allow fix me few other issues 😄