I am trying to build a project with Address sanitizer in Xcode 4.6.1. I have already switched the compiler to “Apple LLVM compiler 4.2” though a setting in Xcode. My problem is that the address sanitizer page on llvm.org (http://clang.llvm.org/docs/AddressSanitizer.html) specifically says “ make sure to use clang (not ld) for the final link step”.
Based on the linker warnings I am getting, I think (but not sure) the project I am building is using ‘ld’ and not ‘clang’ for the linking step. I am unable to figure out how to instruct Xcode 4.6.1 to use clang’s linker. I couldn’t find any setting.
The project I am trying to build is dependent on hundreds of projects. These projects output static libraries (.a), dynamic libraries (.dylib) and frameworks (.framework).
I have changed all these projects
to use address sanitizer
Compilation option –fsanitize=address was added for all the projects
Linker option –fsanitize=address was added for all the projects except for static libraries
In case I am unable to use clang’s linker instead of ld through Xcode, is there any way by which I can explicitly enable asan? Perhaps by linking explicitly to libclang_rt.asan_osx_dynamic.dylib?
Is this group is not the correct place to ask such questions then could you please direct me to the correct group?
Thanks,
Amit Kumar
I investigated further and I think address sanitizer is not currently usable for even simple GUI applications on Mac.
I experimented with a very simple test cocoa application (generated entirely by Xcode). I switched back to older Xcode 4.5.2. In Xcode 4.5.2, the flag for address sanitizer is -faddress-sanitizer. If I use this flag with compiler but not linker then I get a lot of linker errors. If I supply the same flag to the linker then the errors go away. In this application, I found a lot of symbols with ‘asan’ in their names (I used nm for getting symbols). If I launch this instrumented application then I get a crash (EXEC_BAD_ACCESS). I think that the build was properly instrumented by address sanitizer because I do not get a crash if I do not use -faddress-sanitize.With Xcode 4.6.1, clang gives me an error that -faddress-sanitizer is not a valid flag. Address sanitizer page has the info that the new flag is -fsanitize=address. I think that the new flag -fsanitize=address was ignored since there wasn’t any symbol in the instrumented binary which had asan in its name.
I didn’t expect that Xcode 4.6.1 would ignore-fsanitize=address and I was incorrectly suspecting that the linker used by Xcode was still ld.
Thanks,
Amit Kumar
Um, sorry, are you trying to use the Clang version shipped with Xcode? It's not gonna work.
Instead you need to build Clang yourself. I suppose it should be possible to make Xcode use your own Clang.