From c1961eb900a8dfba97c333986b135acc01d3100e Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 24 Mar 2025 18:04:13 -0700 Subject: [PATCH] dtrace: fix on macOS (except in the package) The package needs https://github.com/NixOS/nixpkgs/pull/392918 CC: https://git.lix.systems/lix-project/lix/issues/757 Change-Id: Id040a83d845f98fa1093b782cce2a015b5c85d9f --- lix/libstore/filetransfer.cc | 8 ++++++-- lix/libstore/trace-probes.d | 8 ++++++-- lix/libutil/tracepoint.hh | 7 +++++-- meson.build | 26 ++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lix/libstore/filetransfer.cc b/lix/libstore/filetransfer.cc index cfc340874..5d7e850b4 100644 --- a/lix/libstore/filetransfer.cc +++ b/lix/libstore/filetransfer.cc @@ -9,11 +9,15 @@ #include "lix/libutil/strings.hh" #include "lix/libutil/thread-name.hh" #include "lix/libutil/tracepoint.hh" -#include +#include #include #include +#if ENABLE_DTRACE +#include "trace-probes.gen.hh" +#endif + #if ENABLE_S3 #include #endif @@ -948,7 +952,7 @@ struct curlFileTransfer : public FileTransfer size_t read(char * data, size_t len) override { - TRACE(DTRACE_PROBE2(lix_store, filetransfer__read, uri.c_str(), len)); + TRACE(LIX_STORE_FILETRANSFER_READ(uri.c_str(), len)); size_t total = 0; while (total < len && awaitData()) { diff --git a/lix/libstore/trace-probes.d b/lix/libstore/trace-probes.d index 580b00310..8ba358d53 100644 --- a/lix/libstore/trace-probes.d +++ b/lix/libstore/trace-probes.d @@ -1,9 +1,13 @@ // I don't know how the rest of these stability attrs work and tbh I don't care // either; these probes are not stable API and we don't need to be more // specific about exactly how. -#pragma D attributes Unstable/Unstable/Common provider lix_store provider provider lix_store { /** See filetransfer.cc; this is the consumption side, not the curl/production side. */ - probe filetransfer__read(string url, size_t length); + probe filetransfer__read(const char * url, size_t length); }; +#pragma D attributes Unstable/Unstable/Common provider lix_store provider +#pragma D attributes Unstable/Unstable/Common provider lix_store module +#pragma D attributes Unstable/Unstable/Common provider lix_store function +#pragma D attributes Unstable/Unstable/Common provider lix_store name +#pragma D attributes Unstable/Unstable/Common provider lix_store args diff --git a/lix/libutil/tracepoint.hh b/lix/libutil/tracepoint.hh index edbbc0c4b..14087c47c 100644 --- a/lix/libutil/tracepoint.hh +++ b/lix/libutil/tracepoint.hh @@ -15,10 +15,13 @@ #include "lix/config.h" -// NOTE: glib disables this for the clang static analyzer, idk if we need to also -#if HAVE_DTRACE +// The clang static analyzer is busted on these and throws reserved-identifier +// lints at the crimes they put in the headers. Oh well. +#if HAVE_DTRACE && !defined(__clang_analyzer__) +#define ENABLE_DTRACE 1 #define TRACE(body) body #include #else +#define ENABLE_DTRACE 0 #define TRACE(body) #endif diff --git a/meson.build b/meson.build index 8a23590e1..e84a7508b 100644 --- a/meson.build +++ b/meson.build @@ -417,11 +417,29 @@ if dtrace_feature.enabled() # NOTE: glib seems to have had to hack some stuff up that we are not hacking # up. I don't know why. # https://github.com/GNOME/glib/blob/03f7c1fbf3a3784cb4c3604f83ca3645e9225577/meson.build#L2420-L2434 - dtrace_object_gen = generator(dtrace_exe, - output : '@BASENAME@.o', - arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@']) + + # Darwin doesn't require an object generator for dtrace, but it's preferable + # to still have the build structured the same, so we generate empty object + # files with clang. + if is_darwin + dtrace_object_gen = generator(bash, + output : '@BASENAME@.o', + arguments : [ + '-c', + 'exec "$@"', + '--', + cxx.cmd_array(), + '-xc++', + '-c', '/dev/null', + '-o', '@OUTPUT@' + ]) + else + dtrace_object_gen = generator(dtrace_exe, + output : '@BASENAME@.o', + arguments : ['-G', '-s', '@INPUT@', '-o', '@OUTPUT@']) + endif dtrace_header_gen = generator(dtrace_exe, - output : '@BASENAME@.gen.h', + output : '@BASENAME@.gen.hh', arguments : ['-h', '-s', '@INPUT@', '-o', '@OUTPUT@']) endif configdata += {