Address Sanitizier crashes with puts function in Xcode14

The same thing happens with builds for iOS.

A clang issue rather than an Xcode issue?

Minimum sample source

// main1.c

#include <stdio.h>

int main(int argc, char *argv[]) {
  return 0;
}

int puts( const char *buffer ) {
  return 0;
}

Build

clang -fsanitize=address -o main1 main1.c

Execution result

% ./main1 
==17795==ERROR: Interceptors are not working. This may be because AddressSanitizer is loaded too late (e.g. via dlopen). Please launch the executable with:
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
"interceptors not installed" && 0
zsh: abort   ./main1

What do you want to happen here? You have a function with the same name as a libc function to which address sanitiser intercepts calls. Do you want address sanitiser to intercept calls to your puts(), or not?

The code shown here is the minimum that can reproduce the problem. The original system is much larger.

I'm in trouble because I updated from Xcode13 to Xcode14 and it behaved differently than before.

Sure. But what do you want to happen? Why are you defining your own puts()?

The purpose is to temporarily replace the part that is output to the standard output with another logic.

In actual processing, printf, fprintf, etc. are also replaced in addition to the puts function. But this error does not occur even if there are printf, fprintf, fputs, but if there is a puts function, this error will occur.

Your problem is here:

https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp#L991

Turns out that the sanitizers use puts to figure out if they have installed themselves early enough in the launch process.

I was running into a similar issue except I was trying to override __sanitizer_report_error_summary which according to the headers I should be able to override.

https://reviews.llvm.org/D144830

Address Sanitizier crashes with puts function in Xcode14
 
 
Q