Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac OS X Sierra: detect_leaks is not supported on this platform #1026

Open
ZedZipDev opened this issue Nov 24, 2018 · 11 comments
Open

Mac OS X Sierra: detect_leaks is not supported on this platform #1026

ZedZipDev opened this issue Nov 24, 2018 · 11 comments

Comments

@ZedZipDev
Copy link

I have Mac OS X Sierra 10.13
and do as described here:
https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer

$ cat memory-leak.c
#include <stdlib.h>
void *p;
int main() {
p = malloc(7);
p = 0; // The memory is leaked here.
return 0;
}
% clang -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
==23646==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x4af01b in __interceptor_malloc /projects/compiler-rt/lib/asan/asan_malloc_linux.cc:52:3
#1 0x4da26a in main memory-leak.c:4:7
#2 0x7f076fd9cec4 in __libc_start_main libc-start.c:287
SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

But receive the message:

admins-Mac:test2 admin$ clang -fsanitize=address -g mleak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out
==556==AddressSanitizer: detect_leaks is not supported on this platform.
Abort trap: 6
admins-Mac:test2 admin$ 

What I do incorrent?

@kcc
Copy link
Contributor

kcc commented Nov 26, 2018

@kubamracek

@kubamracek
Copy link

If you're using Apple Clang (the one that comes with Xcode) then this is expected. LSan isn't mature enough on macOS and is unsupported.

You can build Clang from open-source to experiment with LSan on macOS.

@tevariou
Copy link

Any update on that ? It doesn't seem to work on Catalina neither after building clang with brew.

@fatfatson
Copy link

it still doesn't work at 2020..

@morrisonlevi
Copy link

Apple clang version 12.0 (which comes on Catalina) doesn't support detect_leaks either.

Anyone know if Big Sur supports it?

@nickwilliams-zaxiom
Copy link

I'm also getting this error (on 10.15.7 Catalina with Apple clang version 12.0.0 (clang-1200.0.32.21)), and I'm confused by this bug report for a couple reasons:

This documentation says you can use detect_leaks=1 to enable leak detection on macOS: https://clang.llvm.org/docs/AddressSanitizer.html

The leak detection is turned on by default on Linux, and can be enabled using ASAN_OPTIONS=detect_leaks=1 on macOS; however, it is not yet supported on other platforms.

Is this documentation wrong?

Also, I was using detect_leaks=1 successfully on this same machine and compiler version two months ago, and suddenly it's not working. 🤔

Can anyone clear up exactly what the status is and what's necessary to make it work?

And, related, should I / can I use both -fsanitize=address -fsanitize=leak, or do I have to pick one or the other?

@bwesen
Copy link

bwesen commented May 28, 2021

Ran into this here now (2021), I'm following the instructions that say it works on Mac OSX..

If it simply is the case that the Apple-provided clang really does not support this, I think it should be updated in

https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer

otherwise people will continue to read "it works on Mac OSX". Building your own compiler toolchain (if that is a requirement) is not one of the most common things you do and might be good to state that it's not supported on the typical mac osx developer setup otherwise.

@alexyalunin
Copy link

alexyalunin commented Oct 20, 2021

If you use clion try this

In Preferences | Build, Execution, Deployment | CMake -> Cmake options use

-DCMAKE_BUILD_TYPE=ASAN -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++
and
2021-10-20 18 43 59

@sc1f
Copy link

sc1f commented Nov 1, 2021

Running Big Sur 11.5.2 (20G95) and Apple clang version 13.0.0 (clang-1300.0.29.3) for x86_64-apple-darwin20.6.0, detect_leaks=1 still breaks with "detect_leaks is not supported on this platform".

Instruments, which is installed with XCode, can be launched separately against your running process in order to check for allocations and leaks. I am not sure how accurate it is since I can't run detect_leaks but it might be handy in a pinch.

To launch Instruments, right click on XCode and select "show package contents", then navigate to /Applications inside the XCode folder and click on "Instruments".

@MustCodeAl
Copy link

MustCodeAl commented Dec 19, 2021

If you use clion try this

In Preferences | Build, Execution, Deployment | CMake -> Cmake options use

-DCMAKE_BUILD_TYPE=ASAN -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ and 2021-10-20 18 43 59

Your solution WORKED!! THANK YOU! I'm on an M1 Macbook Pro on Big Sur 11.6 using Clion 2021.3 . I installed LLVM from Homebrew and used my llvm Homebrew path instead of the MacOS one.
brew install llvm@13

I Also had to make sure I had the ++ at the end to use the C++ compiler instead of the C compiler

my path was "/opt/homebrew/Cellar/llvm/13.0.0_2/bin/clang++"
f652cc01b171e3b5e0c8df432548eb67

then i had to add set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g") to my cmakefile and reload it.
Here is Jetbrains official guide Clion IDE
c3f962e8945c5c790264763bd499032b

Hopefully this helps anyone who was just as confuse as I was lol.

@ramosian-glider
Copy link
Member

@kubamracek do you know the status of LSan on OSX?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests