libbpf: Add support to GCC in CORE macro definitions
authorCupertino Miranda <cupertino.miranda@oracle.com>
Tue, 13 Feb 2024 17:35:43 +0000 (17:35 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 13 Feb 2024 19:28:12 +0000 (11:28 -0800)
commit12bbcf8e840f40b82b02981e96e0a5fbb0703ea9
tree9238bb36e780acb761de92836f81c420f941aeb8
parent52dbd67dff5d050e99301100e2cac578eef9b2e9
libbpf: Add support to GCC in CORE macro definitions

Due to internal differences between LLVM and GCC the current
implementation for the CO-RE macros does not fit GCC parser, as it will
optimize those expressions even before those would be accessible by the
BPF backend.

As examples, the following would be optimized out with the original
definitions:
  - As enums are converted to their integer representation during
  parsing, the IR would not know how to distinguish an integer
  constant from an actual enum value.
  - Types need to be kept as temporary variables, as the existing type
  casts of the 0 address (as expanded for LLVM), are optimized away by
  the GCC C parser, never really reaching GCCs IR.

Although, the macros appear to add extra complexity, the expanded code
is removed from the compilation flow very early in the compilation
process, not really affecting the quality of the generated assembly.

Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240213173543.1397708-1-cupertino.miranda@oracle.com
tools/lib/bpf/bpf_core_read.h