[clang] [clang] Implement address sanitizer on AIX (1/6) (PR #129925)

David Tenty via cfe-commits cfe-commits at lists.llvm.org
Mon May 5 20:57:17 PDT 2025


================
@@ -259,6 +260,45 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  // Add sanitizer libraries.
+  const SanitizerArgs &Sanitize = ToolChain.getSanitizerArgs(Args);
+  const char *sanitizer = nullptr;
+  bool NeedsSanitizerDeps = false;
+  // For now, only support address sanitizer.
+  if (Sanitize.needsAsanRt())
+    sanitizer = "AddressSanitizer";
+
+  if (sanitizer) {
+    if (Sanitize.needsSharedRt()) {
+      ToolChain.getDriver().Diag(diag::err_drv_unsupported_shared_sanitizer_aix)
+          << sanitizer;
+      return;
+    }
+    NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  }
+
+  // Add sanitizer runtime dependencies.
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+                   options::OPT_shared, options::OPT_r)) {
+    if (NeedsSanitizerDeps)
+      linkSanitizerRuntimeDeps(ToolChain, Args, CmdArgs);
+  }
+
+  // We won't add the static sanitizer libraries to the DSO, but we will
+  // introduce the undefined sanitizer symbols like __asan_init to the DSO. On
+  // AIX, this undefined sanitizer symbol cannot pass final link. Add the
+  // import file to make these undefined symbols be resolved at runtime.
+  if (Args.hasArg(options::OPT_shared) &&
+      ToolChain.getSanitizerArgs(Args).needsAsanRt()) {
+    CmdArgs.push_back(Args.MakeArgString(Twine("-bI:") +
+                                         ToolChain.getCompilerRTPath() +
+                                         "/asan.link_with_main_exec.txt"));
----------------
daltenty wrote:

This file isn't included in this patch, but the behaviour here seems to depend on it existing...

(Also, what's with the `.txt` file extension? Typical this would be either `.imp` or `.exp`)

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


More information about the cfe-commits mailing list