[php-src] PR #11858: Fix DTrace build with SystemTap and GCC defaults
| From: | f4z4on | Date: | Wed, 02 Aug 2023 15:26:55 +0000 |
| Subject: | [php-src] PR #11858: Fix DTrace build with SystemTap and GCC defaults | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-23244@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/11858
Author: f4z4on
We are experiencing an issue when building PHP with DTrace enabled with SystemTap (see #11847).
SystemTap, unlike Oracle DTrace, Open DTrace or their forks, relies on C compiler and preprocessor.
We have recently aligned both of these with compiler and preprocessor we use to build regular C
source code (see #11643). We set
CPP environment variable to the value of our
CPP macro which defaults to C preprocessor detected by configure script.
Similarly, we set CC environment variable to the value of our CC macro
which defaults to C compiler detected by configure script. C compiler flags have
already been in place since versions 5.4.20 and 5.5.4 from 2013-09-18.
We had modified all dtrace invocation in the same way to make it look consistent.
However, SystemTap dtrace needs C preprocessor only when it generates header files
(-h option) with preprocessing (-C option). Similarly, it needs C compiler
only when it generates object files with probe definitions (-G option). Therefore, we
have recently stopped setting all these environment variables when invoking dtrace. We
set only what is necessary for particular action. We hope this makes this fix simpler and clearer
without introducing additional complexity to our build system.
The cause of our issue is the fact that GCC preprocessor, when invoked via gcc binary,
detects the language for preprocessing from source file extensions. Because DTrace probes and
providers for statically-defined tracing are in files with .d extension, GCC detection
fails because it probably thinks it is processing proper D programing language source code (somewhat
different from what DTrace uses) which has no C-style preprocessing. People have noticed, because
configure script on systems with GCC sets CPP make macro to gcc
-E. Therefore practically everyone, who does not override C preprocessor, who is building PHP
with DTrace enabled on Linux with SystemTap, experiences this issue.
We fix this by forcing C language when passing C preprocessor as set by the user or detected by the
configure script. SystemTap dtrace expects C language preprocessor because
pragmas in D programming language used by DTrace are the same #pragma directives known
from C and similar languages.
We use -x option from GCC to force C. Other compilers suites and their preprocessors
(most notably Clang) recognize this option too. Many probably do not. However, this issue is
specific to SystemTap, which is itself specific to Linux and has to be build using the same compiler
as Linux kernel, which only supports building using GCC-compatible compilers. We can definitely
imagine someone building PHP with DTrace enabled using SystemTap and wanting to use compiler suite
or preprocessor which is different from what they used to build SystemTap itself or their Linux
kernel and which does not recognize -x option. However, we do not think it is
reasonable to accommodate for such use case. Properly solving this would require implementing
non-trivial m4 macros, which is probably not warranted given this affects 2 lines of make
commands…
This has no effect on Oracle DTrace, Open DTrace or any of their forks because they do not allow
customization of preprocessor nor compiler. They simply ignore CPP, CC,
and CFLAGS environment variables, so it does not matter what values we set there.