[compiler-rt] [sanitizer_common] Add GNU/Linux main wrapper support (PR #196365)

Kunqiu Chen via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 10:48:03 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);
----------------
Camsyn wrote:


```
int MAIN_WRAPPER(main, argc, argv, envp) {
   // main is the real function `main`, argc/argv/envp are real arguments of main.
   // Do something here
}
```

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


More information about the llvm-commits mailing list