[clang] [compiler-rt] [XRay] Add support for instrumentation of DSOs on x86_64 (PR #90959)

Sebastian Kreutzer via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 8 05:56:36 PDT 2024


================
@@ -0,0 +1,62 @@
+//===-- xray_init.cpp -------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of XRay, a dynamic runtime instrumentation system.
+//
+// XRay initialisation logic for DSOs.
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "xray_defs.h"
+#include "xray_flags.h"
+#include "xray_interface_internal.h"
+
+using namespace __sanitizer;
+
+extern "C" {
+extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __start_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
+extern const XRayFunctionSledIndex __stop_xray_fn_idx[] __attribute__((weak))
+__attribute__((visibility("hidden")));
----------------
sebastiankreutzer wrote:

To your second point: 

With `-fxray-enable`, are you refering to the general `-fxray-instrument` flag or `-fxray-enable-shared`?

If the main executable was built entirely without `-fxray-instrument`, linking the DSO will fail, as the `__xray_register_dso` and `__xray_deregister_dso` functions could not be resolved.

Otherwise, the XRay runtime will currently always work with instrumented DSOs,  regardless of whether the executable was compiled with `-fxray-enable-shared` or not.
I don't see a reason to change this, since IMO there is no benefit (performance or otherwise) from disabling this feature statically.

I can see practical use cases where one might want to explicitly disable patching DSOs (all or a specific subset).
We could handle this by adding a runtime option, e.g. `xray_patch_dsos=true/false/list of names`.
However, this would probably be best as a separate PR. 

Let me know what you think.

https://github.com/llvm/llvm-project/pull/90959


More information about the llvm-commits mailing list