Skip to contentSkip to conversation

/usr/include/perf/event.h:9:10: fatal error: linux/compiler.h: No such file or directory

DISCUSSION Vitaly Chikunov 3 participants 5 messages Oct 6, 2022

lore
Share & tools
lore
#0 lore raw

Hi,

I noticed that perf examples do not compile anymore with v6.0 (first on ALT, but on Fedora is the same). Fedora example for convenience:

  # dnf install kernel libperf-devel gcc
  # cc /usr/share/doc/libperf/examples/counting.c -lperf
  In file included from /usr/share/doc/libperf/examples/counting.c:8:
  /usr/include/perf/event.h:9:10: fatal error: linux/compiler.h: No such file or directory
      9 | #include <linux/compiler.h>
	|          ^~~~~~~~~~~~~~~~~~
  compilation terminated.

I don't see compiler.h installed anywhere by the make headers_install.

Thanks,

#1 lore raw
Quoted 10 lines · Vitaly Chikunov

I noticed that perf examples do not compile anymore with v6.0 (first on ALT, but on Fedora is the same). Fedora example for convenience:

  # dnf install kernel libperf-devel gcc
  # cc /usr/share/doc/libperf/examples/counting.c -lperf
  In file included from /usr/share/doc/libperf/examples/counting.c:8:
  /usr/include/perf/event.h:9:10: fatal error: linux/compiler.h: No such file or directory
      9 | #include <linux/compiler.h>
	|          ^~~~~~~~~~~~~~~~~~
  compilation terminated.

This is introduced in b2f10cd4e805 ("perf cpumap: Fix alignment for masks in event encoding") just (it seems) for `__packed'.
I am told that all uapi is using __attribute__ ((__packed__)) for that.

Thanks,

Quoted 5 lines

I don't see compiler.h installed anywhere by the make headers_install.

Thanks,

#2 lore raw
Quoted 13 lines · Vitaly Chikunov
Quoted 10 lines · Vitaly Chikunov

I noticed that perf examples do not compile anymore with v6.0 (first on ALT, but on Fedora is the same). Fedora example for convenience:

  # dnf install kernel libperf-devel gcc
  # cc /usr/share/doc/libperf/examples/counting.c -lperf
  In file included from /usr/share/doc/libperf/examples/counting.c:8:
  /usr/include/perf/event.h:9:10: fatal error: linux/compiler.h: No such file or directory
      9 | #include <linux/compiler.h>
      |          ^~~~~~~~~~~~~~~~~~
  compilation terminated.
Quoted 5 lines

This is introduced in b2f10cd4e805 ("perf cpumap: Fix alignment for masks in event encoding") just (it seems) for `__packed'.
I am told that all uapi is using __attribute__ ((__packed__)) for that.

Thanks,

Thanks for reporting the issue and sorry for the breakage. I'm not a dependency/packaging expert. Arnaldo, what should be the next steps here?

Thanks,
Ian

Quoted 5 lines
Quoted 5 lines

I don't see compiler.h installed anywhere by the make headers_install.

Thanks,

#3 lore raw

Em Thu, Oct 06, 2022 at 10:20:34AM -0700, Ian Rogers escreveu:

Quoted 18 lines · Vitaly Chikunov
Quoted 17 lines · Vitaly Chikunov
Quoted 10 lines

I noticed that perf examples do not compile anymore with v6.0 (first on ALT, but on Fedora is the same). Fedora example for convenience:

  # dnf install kernel libperf-devel gcc
  # cc /usr/share/doc/libperf/examples/counting.c -lperf
  In file included from /usr/share/doc/libperf/examples/counting.c:8:
  /usr/include/perf/event.h:9:10: fatal error: linux/compiler.h: No such file or directory
      9 | #include <linux/compiler.h>
      |          ^~~~~~~~~~~~~~~~~~
  compilation terminated.

This is introduced in b2f10cd4e805 ("perf cpumap: Fix alignment for masks in event encoding") just (it seems) for `__packed'.
I am told that all uapi is using __attribute__ ((__packed__)) for that.

Quoted 5 lines
Quoted 1 line

Thanks,

Thanks for reporting the issue and sorry for the breakage. I'm not a dependency/packaging expert. Arnaldo, what should be the next steps here?

I guess we should just use '__attribute__ ((__packed__))', as its what we see when grepping for attribute on /usr/include/linux/

But t his patch seems to simple remove the packed, no? I.e. is that packed really needed?

- Arnaldo

#4 lore raw
Quoted 26 lines · Arnaldo Carvalho de Melo

Em Thu, Oct 06, 2022 at 10:20:34AM -0700, Ian Rogers escreveu:

Quoted 18 lines · Vitaly Chikunov
Quoted 17 lines · Vitaly Chikunov
Quoted 10 lines

I noticed that perf examples do not compile anymore with v6.0 (first on ALT, but on Fedora is the same). Fedora example for convenience:

  # dnf install kernel libperf-devel gcc
  # cc /usr/share/doc/libperf/examples/counting.c -lperf
  In file included from /usr/share/doc/libperf/examples/counting.c:8:
  /usr/include/perf/event.h:9:10: fatal error: linux/compiler.h: No such file or directory
      9 | #include <linux/compiler.h>
      |          ^~~~~~~~~~~~~~~~~~
  compilation terminated.

This is introduced in b2f10cd4e805 ("perf cpumap: Fix alignment for masks in event encoding") just (it seems) for `__packed'.
I am told that all uapi is using __attribute__ ((__packed__)) for that.

Quoted 5 lines
Quoted 1 line

Thanks,

Thanks for reporting the issue and sorry for the breakage. I'm not a dependency/packaging expert. Arnaldo, what should be the next steps here?

Quoted 5 lines

I guess we should just use '__attribute__ ((__packed__))', as its what we see when grepping for attribute on /usr/include/linux/

But t his patch seems to simple remove the packed, no? I.e. is that packed really needed?

The packed came from undefined behavior in the disk representation of the cpu map (perf_record_cpu_map_data). Unfortunately there are unaligned __u32 and __64 values in perf_record_cpu_map_data take for example the case where bitmap entries are 32-bit (long_size == 4):

perf_record_cpu_map_data {
__u16 type

  perf_record_mask_cpu_map32 {
        __u16                    nr;
       __u16                    long_size;
       __u32                    mask[];

}
}

when mask is accessed it is necessary that the compiler know it is unaligned (2 rather than 4 byte aligned). Removing the packed would mean that the alignment on mask would change and so would the disk representation. This would break reading old perf.data files. The previous code would pass __u32 pointers to mask even though it was unaligned, triggering undefined behavior errors. The code now passes around a pointer to perf_record_cpu_map_data as the compiler knows from the packed attribute that the mask is going to be unaligned when accessed.

Thanks,
Ian

Quoted 1 line

- Arnaldo