Valgrind Install Fails MacOS Mojave - memory-management

I keep seeing mixed results for Valgrind's status on MacOS Mojave. Some responses say to use the head url change workaround ( & brew install --HEAD valgrind), but this did not work as I still get:
-bash: valgrind: command not found
Some say it's just not compatible at all with OS Mojave.
Valgrind is a mandatory spec for my C project. How do I go about this?

Related

Valgrind and macOS Big Sur

I'm having troubles installing Valgrind on the macOS Big Sur through the Homebrew. In the terminal I have tried
$ brew install valgrind
After Homebrew's autoupdate, I got the following message:
valgrind: Linux is required for this software.
Error: An unsatisfied requirement failed this build.
Is there a way I can install Valgrind?
Roughly your only hope is here, a work in progress.
brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind
I’d say Valgrind is a lost cause on macOS. Try looking into Address/Leak Sanitizer. Note that Apple Clang does not support leak checking, so you’ll have to grab llvm off Brew instead. If you use -fsanitize=address, you’ll also have to prepend ASAN_OPTIONS=detect_leaks=1 on macOS.
Valgrind is not supported by Big Sur, but you can try this
brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind
or a better option
in Preferences | Build, Execution, Deployment | CMake -> Cmake options
use
-DCMAKE_BUILD_TYPE=ASAN -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++
and
You can try leaks. I don't know how it compares to valgrind in terms of features, but it's enough for me rn.
leaks -atExit -- ./path/to/binary

How to install OS X 10.12 command line tools on 10.11?

I get this error when trying to brew install geckodriver
==> Installing geckodriver dependency: rust
==> Downloading https://static.rust-lang.org/dist/rustc-1.42.0-src.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/rust/1.42.0 --release-channel=stable
==> make
Last 15 lines from /Users/nilshaus/Library/Logs/Homebrew/rust/02.make:
2020-04-12 21:13:48 -0400
make
make: error: unable to find utility "make", not a developer tool or in PATH
xcodebuild: error: SDK "/Library/Developer/CommandLineTools/SDKs/MacOSX10.12.sdk" cannot be located.
clang: error: unable to find utility "clang", not a developer tool or in PATH
Do not report this issue to Homebrew/brew or Homebrew/core!
These open issues may also help:
Rust dependents that currently fail to build from source https://github.com/Homebrew/homebrew-core/issues/50815
Error: You are using macOS 10.11.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.
Obviously 10.11 is no longer supported by Homebrew. The fact that it can't find make is weird, but I'm willing to bet that the real issue is that the rust build expects the 10.12 command line tools. Is there a way for me to install them on OS X 10.11? I have Xcode 8.
I encountered this same error message when brew upgrade installed a new version of clang and tcl-tk. Found a workaround here:
Xcode was overriding the command line tools install. After moving
Xcode to the trash I found the directory of the command line tools
install:
clang --version
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/Library/Developer/CommandLineTools/usr/bin
https://github.com/pytorch/pytorch/issues/1139#issuecomment-302967251
Another possible workaround - instead of moving Xcode, choose one of the following to specify CLT version:
sudo xcode-select -s /Library/Developer/CommandLineTools
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
To display the current CLT path: xcode-select -p
https://github.com/pytorch/pytorch/issues/1139#issuecomment-303033942

How to install Valgrind on macOS Mojave(10.14) with Homebrew?

I tried to install Valgrind with brew install Valgrind and got :
valgrind: This formula either does not compile or function as expected
on macOS versions newer than Sierra due to an upstream
incompatibility.
Error: An unsatisfied requirement failed this build.
I tried brew install --HEAD Valgrind.
Instead, after successfully installing the dependencies autoconf, automake and libtool, when it tries to install valgrind, I get a configure error:
Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and
17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)
My OS is macOS Mojave(10.14), so does it mean that I can't install a functioning Valgrind with Homebrew presently?
A (rather painful) install from source workaround based on this patch, this post and this answer.
$ git clone https://github.com/Echelon9/valgrind.git
$ cd valgrind
$ git checkout feature/v3.14/macos-mojave-support-v2
$ ./autogen.sh
$ ./configure --prefix=/where/you/want/it/installed --enable-only64bit
$ make
If you get the following error: No rule to make target '/usr/include/mach/mach_vm.defs’, you will need to run xcode-select --install. You might need to install Xcode from the app store if you don't already have it. Once that's done, you will need to edit the coregrind/Makefile:
Search for:
am__append_19 = \
/usr/include/mach/mach_vm.defs \
/usr/include/mach/task.defs \
/usr/include/mach/thread_act.defs \
/usr/include/mach/vm_map.defs
After double checking the below folder exists, prefix every line with:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
End result should be:
am__append_19 = \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/mach_vm.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/task.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/thread_act.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/vm_map.defs
Now run make again and the includes should be found. But that doesn't necessarily mean it will compile. I got the following error:
vg_preloaded.c:136:19: error: expected ';' before 'const'
__private_extern__ const char *__crashreporter_info__ = "Instrumented by Valgrind " VERSION;
A fix for this is to add the following line:
#define __private_extern__ extern
to the following files:
coregrind/m_syscall.c
coregrind/m_syswrap/syswrap-darwin.c
coregrind/vg_preloaded.c
Finally, you need to cross your fingers hoping no other errors show up:
$ make
$ make install
You may use Experimental Version of Valgrind for macOS 10.14.5 Mojave at:
https://github.com/sowson/valgrind
The command to use it is:
brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
It is still experimental and needs some work but for simple projects works already... Enjoy!
addition: I found this one worked for me on my OSX 10.14
brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
A branch that is working to get OSX correct. something to tide us over until we get a real valgrind version fixed.
As others have mentioned, Louis Brunner maintains a working version at https://github.com/LouisBrunner/valgrind-macos.
brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind
This worked for me for MacOS 10.15.7 Catalina.
I am having the same issue. It seems like valgrind is not compatible with the newest macOS(10.14 Mojave). Tried installing it the High Sierra way (https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/) and got the same output you described. The only solution I can offer you right now is either working on virtual machine (https://www.virtualbox.org/) or using Docker (https://www.gungorbudak.com/blog/2018/06/13/memory-leak-testing-with-valgrind-on-macos-using-docker-containers/).
I have just found a working solution to use VALGRIND on my Mac (Mojave 10.14.6). Just run this command :
brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
(From https://github.com/LouisBrunner/valgrind-macos)
Hope it will work for you.
Not a proper solution for macOs, but for the time being, I created a docker image. After installing docker for macOS, this is how to start valgrind:
cd </path/to/source/directory/where/you/want/run/valgrind/with>
curl -O https://raw.githubusercontent.com/biocyberman/ValgrindDocker/master/startValgrind
./startValgrind # this will takes time for the first time, because it needs to fetch docker valgrind image
# you will get a root command prompt inside the docker image.
# do what ever you want
# type 'exit' to quit
As of 2019-NOV-30, it is possible to build against OS X 10.14.6 via https://github.com/sowson/valgrind and https://github.com/LouisBrunner/valgrind-macos
However, there are many test failures (see the LouisBrunner link), noise during runs, and SEGVs when running against non-trivial programs: installing is, well, installing. YMMV.
You can follow alex.m's answer to get valgrind, but if you'r using it on a int main() { return 0; } program, you'll get many weird errors, and non-existing allocs / free.
To 'hide' these annoying errors, you can follow theses steps (it's more a workaround than a real fix) (based on this wiki page and some research in Valgrind's source code):
First, create and compile a int main() { return 0; } program.
Execute the following command (to create file containing error suppression):
valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-supressions=all --log-file=$YOUR_LOG$ $YOUR_BINARY$
Using this gawk script, create the .supp valgrind file:
cat ./$YOUR_LOG$ | ./$YOUR_SCRIPT_FILE$ > minimal.supp
Copy and Past minimal.supp content at the end of $YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp file
And you are done! Weird and nonexistent errors will be ignored.
If you also want's to remove the non-existing allocs, frees etc, you can directly edit Valgrind's source code. Or just use heapusage for leak-tracking
(works on mojave 10.14.6)
brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
It seems like this specific version of OSX is problematic with valgrind, so it won't be easy as brew install the package. Fortunately the following way worked for me:
First download need MacOSX10.14 sdk, This comes with XCode but you can also download it here. The path where you unzip it will be referenced as <PATH TO OSX SDK>
Then do the following
$ git clone https://github.com/Echelon9/valgrind.git
$ cd valgrind
$ git checkout feature/v3.14/macos-mojave-support-v2
$ ./autogen.sh
$ ./configure --prefix=<installation_path> --enable-only64bit
Edit coregrind/Makefile, change this:
am__append_19 = \
/usr/include/mach/mach_vm.defs \
/usr/include/mach/task.defs \
/usr/include/mach/thread_act.defs \
/usr/include/mach/vm_map.defs
to
am__append_19 = \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/mach_vm.defs \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/task.defs \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/thread_act.defs \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/vm_map.defs
Then run
$ make
$ make install

Unable to build and install Valgrind on macOS High Sierra

I cannot install Valgrind on macOS High Sierra. It's not available through brew. I've tried with 3.10. After make install, I get this message:
configure: error: Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x and 14.x (Mac OS X 10.6/7/8/9/10)
Homebrew says:
valgrind: This formula either does not compile or function as expected on macOS
versions newer than Sierra due to an upstream incompatibility.
Error: An unsatisfied requirement failed this build.
I had the problem like this.
So, I found the solving. You should install valgrind by this code
brew install --HEAD valgrind
I have created a port of valgrind 3.13.0 to work on macOS High Sierra (10.13.x). You can get it here: https://github.com/padiakalpesh/valgrind_3.13_high_sierra
Once you have obtained the source, run the following commands from inside the source directory:
./configure
make
sudo make install
brew install Valgrind has some compatibility problem when installing on latest macOS but there is a workaround with this problem. You must be getting this error message when you try to install it using brew.
$brew install valgrind
valgrind: This formula either does not compile or function as expected on macOS
versions newer than High Sierra due to an upstream incompatibility.
Error: An unsatisfied requirement failed this build.
-------------------------------------------------------------------SOLUTION--------------------------------------------------------------
Step1: $brew edit valgrind
Step2: Find this line in the file ->(url "https://sourceware.org/git/valgrind.git")
Step3: Replace it with -> (url "git://sourceware.org/git/valgrind.git")
Step4: $brew update
Step5: $brew install --HEAD valgrind
And Done!
Let me know if it still doesn't work.
Thanks!!
I have got this working in July 2018, for reference:
https://gist.github.com/AlessandroMinali/d8316d6cc650c97027433644c2ff31ee
Edit ./configure
- 5468: applellvm-5.1|applellvm-6.*|applellvm-7.*|applellvm-8.*)
+ 5468: applellvm-5.1|applellvm-6.*|applellvm-7.*|applellvm-8.*|applellvm-9.*)
- 5879: 16.*)
+ 5879: 17.*)
Run
./autogen.sh
./configure
make
make install
Create file ~/.valgrind.supp
# false positive for any executable (it seems)
# macOS 10.12.6
# valgrind 3.13.0
{
libtrace initialization false positive
Memcheck:Param
msg->desc.port.name
fun:mach_msg_trap
fun:mach_msg
fun:task_set_special_port
fun:_os_trace_create_debug_control_port
fun:_libtrace_init
}
Create file ~/.valgrindrc
--suppressions=$HOME/.valgrind.supp
Troubleshooting
if can not read suppresion file copy and paste the contents of $HOME
if it complains about clang versions, bump the first edit up
if it complains about Darwin version, bump the second edit up
using the brew install --HEAD valgrind also worked for me, but be sure to know that it will take awhile to pull the HEAD version, and build/install.
However, no other changes were needed.
I build the git head version of Valgrind on macOS fairly regularly. If you have xcode installed then there isn't much more to it than following the instructions here.
I'll update with my build script later.
As an alternative, you might want to consider clang sanitizers. This can be enabled in xcode, or with the -fsanitize=X option (where X is address, undefined, thread, memory and a few others).
Valgrind is a rather touchy piece of software, and requires updates for each major release of macOS.
As of February 2018, there is no released version of Valgrind which supports macOS High Sierra (10.13). You will need to use a development version of Valgrind, or use alternate tools. (Apple's Instruments may have some of the functionality you are looking for.)
MacPorts version started working for me in Sep 2018!
The command, for completeness sake (completes very fast - apparently, prebuilt):
sudo port install valgrind-devel
Version:
$ valgrind --version
valgrind-3.14.0.GIT
The following worked for me using the latest Valgrind release 3.14.0 (9th October 2018) on macOS 10.13.6.
VERSION="3.14.0"
wget -O - http://www.valgrind.org/downloads/valgrind-"$VERSION".tar.bz2 | tar xjf -
cd valgrind-"$VERSION"
# use --prefix=/path/to if you want it installed somewhere in particular
./configure
make
# may need sudo
make install
# test all is working
valgrind ls -l
These instructions are taken from the README inside the Valgrind release tar ball.

Error Message "Xcode alone is not sufficient on Sierra"

I'd like to install openCV to vectorize image, but there's a series error message regarding Xcode and Ruby.
First, I use terminal to install openCV, brew install opencv.
Then, I got error message indicating that the system doesn't like my ruby version.
/usr/local/Homebrew/Library/Homebrew/brew.rb:12:in `<main>':
Homebrew must be run under Ruby 2.3! You're running 2.0.0. (RuntimeError)
So, I want to upgrade my ruby. I followed several update strategy from this post. First ruby upgrade trial: brew link --overwrite ruby & brew unlink ruby && brew link ruby and get
Error: No such keg: /usr/local/Cellar/ruby
Then second ruby upgrade trial: brew upgrade ruby and see the following error message.
Error: Xcode alone is not sufficient on Sierra.
Install the Command Line Tools:
xcode-select --install
This error message means I need to install Xcode which I already install. So, I check my Xcode status with code-select -p and get /Applications/Xcode.app/Contents/Developer which means I am fine.
I saw a comment regarding where you install python could be a big issue. Quote from the source:
If you see /usr/local/bin/python3 then you are correctly using the Homebrew version of Python. If the output is instead /usr/bin/python3 then you are incorrectly using the system version of Python.
I check which python3 and get
/Users/******/anaconda3/bin/python3
Could this be the problem? How can I change system version to local?
Let me explain this myself so people won't make the same mistakes.
When I saw the last line of the error message
Error: Xcode alone is not sufficient on Sierra.
Install the Command Line Tools:
xcode-select --install
My thought was: I already have Xcode why the system ask me to "reinstall" it. However, thanks for #SamiKuhmonen # Beartech #patrick kuang suggestion, I search a page (in Mandarin). xcode-select --install does not reinstall the whole Xcode. It means install some missing command line tools which is required by installing Ruby.
Trying to install k8s package via brew , I just got the same issue a while ago saying in the terminal :
Error: Xcode alone is not sufficient on Sierra.
Install the Command
Line Tools: xcode-select --install
You need to download *.dmg file; named Command Line Tools (macOS x.x.x) for XCode N . Search on it here : https://developer.apple.com/download/more/ . You must have developer account.
Then, congrats! 🎉
update for 2019
macOS Mojave 10.14.5
Use Xcode10.2 for macOS 10.14
I had the same issue in my Macbook Pro on Sierra. Apart from updating Xcode from the App Store, I also installed the command line utilities using the xcode-select --install command.
After the update steps, brew commands started working fine. I also updating my OS during this time.
I got the same message despite having Xcode and the command line tools already being installed a long time ago and updated numerous times.
I think it is the Apple way of telling you that Xcode command line tools need to be updated, as the App Store showed me the below:
After executing the xcode-select --install command, the update disappears from the App Store, which means they are exactly the same thing.
I had the same problem. I installed 'Command Line Tools for XCode' (choose appropriate version) from https://developer.apple.com/download/more/ and restarted my terminal. Issue resolved :)

Resources