[compiler-rt] [sanitizer_common] Add GNU/Linux main wrapper support (PR #196365)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 10:41:53 PDT 2026
================
@@ -0,0 +1,47 @@
+//===-- sanitizer_common_interceptors_main.inc -----------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Common main wrapper interceptor for tools that define MAIN_WRAPPER.
+//
+//===----------------------------------------------------------------------===//
+
+#include "interception/interception.h"
+#include "sanitizer_common.h"
+#include "sanitizer_platform.h"
+
+// __libc_start_main is a dynamic symbol in glibc.
+#if SANITIZER_LINUX && SANITIZER_GLIBC && defined(MAIN_WRAPPER)
+namespace __sanitizer {
+namespace {
+
+MainFnTy real_main;
+
+int WrappedMain(int argc, char **argv, char **envp) {
+ return MAIN_WRAPPER(real_main, argc, argv, envp);
+}
+
+} // namespace
+} // namespace __sanitizer
+
+INTERCEPTOR(int, __libc_start_main, __sanitizer::MainFnTy main, int argc,
+ char **argv, void (*init)(), void (*fini)(), void (*rtld_fini)(),
+ void *stack_end) {
+ // This provider is for dynamic glibc startup only. Other libc/startup
+ // schemes need separate platform-specific providers.
+ __interception::DoesNotSupportStaticLinking();
----------------
vitalybuka wrote:
__interception::DoesNotSupportStaticLinking(); is usually called by sanitizer init, we don't need it here
https://github.com/llvm/llvm-project/pull/196365
More information about the llvm-commits
mailing list