-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
M1/M2 Compatibility #56
Comments
Hi @gilaroni, I have started on M1 support, it might take a bit but it's on the roadmap, yes. |
Hello, |
Any news here, its always not possible to install valgrind .... brew install --HEAD LouisBrunner/valgrind/valgrind If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core): valgrind's formula was built from an unstable upstream --HEAD. |
any update for the M1/M2 compatibility? |
ran into the same error as @eliesaikali on my M2 Pro MacBook Pro running macOS Ventura 13.2.1 (22D68). |
+1 |
M1 Pro MacBook Pro running macOS Venture 13.3.1. Same issue as @eliesaikali and @hacknus. |
Any details about the roadmap of Valgrind runs in the M1 arch? |
any update for the M1/M2 compatibility? |
This comment was marked as spam.
This comment was marked as spam.
Still need help? |
Would really like Valgrind w/ MacOS Silicon for school purposes. We're using it at school!
|
Pleeeassseee bump this up. We're using valgrind in our cs101 class to help with memory leaks in projects related to singly linked lists and pointers. We're also going to need valgrind in our upcoming cs102 class. I don't mind using our college's ubuntu desktops with valgrind, but the labs close at 10pm, and a lot of us do our best studying after 10pm. |
Speaking from experience, a huge amount of work is needed to get things running smoothly. |
What are the alternative to valgrind on MacOS what would be usable in a continuous integration environment ? |
@MartinDelille You can use leaks if you like on MacOS |
I wasn't aware of this xcode tool! Thanks a lot! 👌 |
Yes probably, but some people want to contribute like @JoonasMykkanen, but he doesn't get any answer |
I don't have the bandwidth to contribute to this right now-- can I buy you a coffee or some takeout? You're holding all our hopes and dreams. |
FreeBSD arm64 is now working reasonably well. No signals or threads just yet. == 709 tests, 235 stderr failures, 47 stdout failures, 5 stderrB failures, 6 stdoutB failures, 0 post failures == |
This comment was marked as duplicate.
This comment was marked as duplicate.
Great news, I have managed to run a guest binary on M1 through Valgrind for the first time. But while I am very pleased, let me be absolutely clear: this is in no way stable and can at best be described as an experimental prototype. I just thought it was too much progress not to post it. If you'd like to test it for yourself, you can clone this repo and build the Summary of the roadmap ahead:
|
Thanks for all of the hard work on this @LouisBrunner, getting valgrind to work for Apple Silicon is going to be so great for anyone trying to do development in C/C++ on a Mac. As it stands I switched to Ubuntu for my tasks that require memchecks, but just know that many of us cannot wait to jump back and check out any first stable version. |
And a bit of news from upstream. This morning I pushed the code for FreeBSD arm64. Other than the occasional failure related to setting up memory for new threads (I think) it works pretty well. Might help a bit with stuff like signal resumption where Darwin and FreeBSD have very similar code. |
Not sure if helpful, but FYI I got something semiworking on a complex app with 2 patches, one that adds a (hackish) DC_ZVA instruction implementation and another that avoids crashes trying to load debug info for a lot a system libraries.
With this, memcheck seems to work perfectly for my case. --tool=massif however does not... |
There are a few bugzilla items similar to this. First we need a better implementation of the mrs instructions. Are they documented for Darwin? |
Oh, very interesting! Does your app uses threads at all? Do you interface with objc in any way?
Thanks, I will look into those. If you have any extra background on the reasoning behind those fixes, that would be very nice. Some specific questions I have:
If you get it working, feel free to post here. I am focusing mostly on memcheck as it's the default tool and there is still so much that is broken.
Couldn't find much personally. The OSS source code have a few mentions of the Apple-specific registries and that's kind of it. I don't even think you can run
Not sure what you mean by this. I added a few extra ones here, here and here. |
I've only started looking at this. My understanding is that the MSR instructions are kind of like a 'soft' version of CPUID. Unlike CPUID which returns baked-in values MRS traps to the kernel. What I don't know yet is whether it is always safe to use a dirty helper or not. It will be a problem if the kernel reports capabilities that Valgrind doesn't support. |
I don't think so, the OS parts of macOS at least seem to not bother and just assume things, like the granularity at which dc zva works As far as I can tell the libc usages don't care what the MSR contains (understandable, the loop would be far more complex and costly if it did).
No, no threads at all (by default). Just a command-line application primarily targetting Linux, so no objc either.
Sorry, I should indeed have written more: there is no issue with my binary. The problem is with in-memory system libraries where this triggered. First I tried to skip all offending binaries by name in img_from_memory (it ONLY happens with system libraries and when img_from_memory is used), but it got a bit much and went with this more general solution.
Not really, mostly guessing/trial and error. But the DCZID_EL0 register specifies the proper value, so could use that to double-check.
Yes, makes total sense. The massif issues, whatever they are, seem a bit beyond my skills. For now I'll just hope that someone else does some fixes that just happen to fix that, too! |
macOS isn't my only concern. I also want to ensure that everything works correctly on FreeBSD and Linux. |
None of my patches should change anything for FreeBSD or Linux. |
That ticket is old and lacks reproducers, but it sounds like Android might have the same issue (optimized libraries not checking if the instruction is available before using it). |
I put my patch also on that ticket, maybe there is some user feedback on it. Anyway feel free to re-use any part of my patches in any way you want. |
Hello, I've just tried building the M1 branch on my M1 Max and I got the exact same issue than rdoeffinger related to debug info.
After applying the patch and recompiling vg-in-place is now able to trace trivial applications such as ls. I have tried running a more advanced own app but it has 2 issues:
This is the output of VG when attempting to trace a custom CLI tool using a Rust dylib (everything is built with debug info including the Rust dylib):
I wonder if these errors are due to VG internal issues or if they are real and Apply really needs to fix their dyld... Are these errors expected? EDIT: I also wonder why it's calling _NSThreadPoisoned as in my test I have not used any threads. |
@Yuri6037 FYI, I edited your comment to remove the bulk of the errors (as they aren't particularly useful for this discussion and can still be accessed through the Github edit history otherwise) because your message made it difficult to scroll through this issue.
Good to know that it isn't an isolated issue. I have yet to reproduce it, I will have to look into it a bit more.
Valgrind should provide all DYLD env vars to the real dyld when running your binary. If you have a MRE, I would gladly look into that issue.
This is usually due to Valgrind not knowing about how the memory is laid out on macOS. In the past, they have been hidden through a copious amount of suppressions (a special Valgrind file). I haven't seen those specific one yet, so I don't know what's causing it but the general rule I found is: if you dig down to why an issue like
As stated in my latest update, this is currently expected. I haven't had time to investigate why that happens apart that objc is being loaded at some point. You don't have to use threads especially but if you use any macOS capability which rely on objc, you will have this crash.
I am not very knowledgeable about this so thanks for this background as it will make easier to research and fix. |
I just pushed a bunch of changes upstream for arm64 concerning several mrs and dc opcodes. That includes mrs dczd_el0 and dc zva. |
I was planning to merge the arm64 changes into Good newsValgrind is basically functional on Apple Silicon on feature/m1. This branch incorporates a lot of changes:
These changes mean that the regression tests have improved significantly, macOS 13 amd64 has a 30% reduction in failure and macOS 14 arm64 has less failures than the current So you can run Valgrind, it will probably work well and all is great. Bad newsThere is some kind of memory issue which happens when Valgrind is running (ironic, isn't it?). This is very obvious when running a GUI application or the regression tests. Your machine will slow down to a crawl and simply stopping Valgrind will not be enough to restore your system into a usable state, you will need to restart. Such freezes, where a force reset was required, happened to me a handful of time when working on Valgrind. I have been sampling my system with Due to the dramatic effect of this issue (requiring a reboot or basically crashing your computer altogether), I can't release the current state of arm64 on Going forwardI have been crunching pretty hard trying to get Valgrind ready for release and need to take break from it. I would have wanted to report the release of the first macOS arm64 version but it wasn't meant to be. However, we have never been so close to a stable release and I am confident that we are at the end of this long journey. |
Bravo! When you are ready we can work again on getting this merged upstream. |
Thank you for the amazing work. I hope you are rejuvenated by your break. I tried to run the version in the feature/m1 branch on a program of mine and got the following error. I'm on MacOS 14.7 (23H124) on an Apple M2 Max. I don't know if the following output is of interest: ` % ~/src/valgrind-macos/vg-in-place ./ref_speaker_curl_pump valgrind: the 'impossible' happened: host stacktrace: sched status: Thread 1: status = VgTs_Runnable syscall unix:197 (lwpid 259) Note: see also the FAQ in the source distribution. |
What kind of binary is ref_speaker_curl_pump? The 4k buffer on line 1164 of debuginfo.c might not be big enough. Can you try making it bigger? I need to clean up VG_(di_notify_mmap) and ML_(check_macho_and_get_rw_loads). ML_(check_macho_and_get_rw_loads) should be more like ML_(check_elf_and_get_rw_loads) taking the fd rather than relying on VG_(di_notify_mmap) to read the start of the binary into a fixed size buffer. |
Thanks for the response @paulfloyd !
The It is linked with code written in Rust and C++.
Thanks! That did change the behavior. If i increase the size to 16384 or 65536, there is an error later:
In this invocation, The C files were compiled with
The executable built with these |
Don't build your exe with sanitizers. Just -g and -fno-omit-frame-pointer are enough for Valgrind. Mixing sanitizers and Valgrind usually doesn't work. Apple has done a lot of work hardening its allocators and deallocators recently using type-aware functions. I don't know if that has spilled over into malloc_size. |
will there be a version for m1?
The text was updated successfully, but these errors were encountered: