capitan
capitan

Reputation: 11

Does AddressSanitizer use a different standard library? (C programming)

Do you guys know why the AddressSanitizer would be taking a whole different set of libraries.

For instance, I was trying to recreate strcmp, when I was comparing my output with the standard strcmp from string.h but what I realized is that compiling it normally with gcc it outputs the difference, but with the -fsanitize=address flag added it gives me 1, 0, -1 outputs.

both gcc and clang behave the same way

I am on a OSX 10.11.6, btw. Is this behavior unique to MACOS or other systems have similar effects?

Btw, from what I was reading, the strcmp of the GNU C library outputs the difference and the Apple version only has outputs of 1, -1 and 0. So this is even more puzzling to me, because the gcc/clang in MACOS seems to be using the gnu libc by default, and somehow shifting to the apple's version of libc when using the -fsanitize=address flag.

If anyone can explain this to me I would very grateful. btw, just in case, this is my configuration of gcc:

➜ gcc --version
Configured with:
--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
    Apple LLVM version 8.0.0 (clang-800.0.38)
    Target: x86_64-apple-darwin15.6.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Upvotes: 1

Views: 660

Answers (1)

yugr
yugr

Reputation: 21955

-fsanitize=address forces your binary to link against Asan runtime which overloads a lot of standard functions (including strcmp). Overloading is done to check input arguments to these functions. Asan implementations are generally standard-compliant but don't follow all the nits for a particular platform so this may be the reason for differences that you see.

Upvotes: 1

Related Questions