[llvm-branch-commits] [llvm] [llvm-profgen] Add ITM data trace support (PR #230310)
Kunal Pathak via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 4 12:01:37 PST 2026
================
@@ -24,8 +24,8 @@ with `-b`.
:::
:::{option} --etm=<string>
-Path of the ETM trace file created by ARM CoreSight trace tools.
-Requires the OpenCSD library version 1.5.4 or higher to be enabled during the build.
+Path of the ETMv4/ITM trace file created by ARM CoreSight trace tools.
+Requires the OpenCSD library version 1.7.1 or higher to be enabled during the build.
----------------
kunalspathak wrote:
I tried this with OpenCSD 1.8.3 (latest release, so it passes the new 1.7.1 minimum) and it doesn't build:
```
ETMTraceDecoder.cpp:68:3: error: 'ocsd_itm_cfg' does not name a type; did you mean 'ocsd_stm_cfg'?
ETMTraceDecoder.cpp:74:5: error: 'Cfg' was not declared in this scope
ETMTraceDecoder.cpp:233:51: error: 'class llvm::{anonymous}::ITMTraceConfig' has no member named 'Cfg'
```
As far as I can tell it's two things on the OpenCSD side:
- `opencsd/c_api/ocsd_c_api_types.h` pulls in the etmv3/etmv4/ptm/stm/ete packet types but not `itm/trc_pkt_types_itm.h`, so `ocsd_itm_cfg` isn't visible through `opencsd_c_api.h`.
- `make install` (the `install_inc` rule in `decoder/build/unix_common/rctdl_c_api_lib/makefile`) doesn't install `opencsd/itm/` at all, and neither do the install lists in the new experimental CMake build. So adding the include here only helps if you point at the source tree.
Repro without LLVM:
```
git clone https://github.com/Linaro/OpenCSD && cd OpenCSD && git checkout v1.8.3
cd decoder/build/linux && make -j && make install PREFIX=/tmp/ocsd \
INSTALL_LIB_DIR=/tmp/ocsd/lib INSTALL_INCLUDE_DIR=/tmp/ocsd/include \
INSTALL_BIN_DIR=/tmp/ocsd/bin INSTALL_MAN_DIR=/tmp/ocsd/man
ls /tmp/ocsd/include/opencsd # no itm/
cat > t.cpp <<'X'
#include "opencsd/c_api/opencsd_c_api.h"
ocsd_itm_cfg Cfg{};
int main() { return Cfg.reg_tcr != 0; }
X
c++ -fsyntax-only -I /tmp/ocsd/include t.cpp # error
c++ -fsyntax-only -I <OpenCSD>/decoder/include t.cpp # same error, source tree
c++ -fsyntax-only -I <OpenCSD>/decoder/include \
-include opencsd/itm/trc_pkt_types_itm.h t.cpp # ok
```
And in LLVM: `-DLLVM_ENABLE_OPENCSD=ON -DOPENCSD_ROOT=/tmp/ocsd` prints "OpenCSD support enabled (found 1.8.3)" and then `ninja lib/ProfileData/CMakeFiles/LLVMProfileData.dir/ETMTraceDecoder.cpp.o` fails as above. Same file on main compiles fine against the same install, so it's the ITM bits.
Which OpenCSD are you building against -- master? If so, the version gate is accepting every released version (1.7.1 through 1.8.3) even though none of them can compile this, and since plain `ON` enables it, someone with a distro/release OpenCSD gets a hard build error rather than falling back to "OpenCSD not enabled". Nothing in CI builds with OpenCSD, so the ARM tests just show UNSUPPORTED and this wouldn't get caught.
Could the CMake check test for what's actually used instead of a version number? Something like:
```cmake
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${OPENCSD_INCLUDE})
check_cxx_source_compiles("
#include \"opencsd/c_api/opencsd_c_api.h\"
int main() { ocsd_itm_cfg C{}; (void)C; (void)OCSD_BUILTIN_DCD_ITM; return 0; }"
OPENCSD_HAS_ITM_C_API)
unset(CMAKE_REQUIRED_INCLUDES)
```
and only enable `HAVE_OPENCSD` when that passes (or keep the ETM-only path working when ITM isn't available). If it really needs unreleased OpenCSD, it'd be good to say so in the docs/CMake message too.
(Some help from AI GPT-6 Astra in coming up with repro)
https://github.com/llvm/llvm-project/pull/230310
More information about the llvm-branch-commits
mailing list