-
Notifications
You must be signed in to change notification settings - Fork 339
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
Throwing exceptions in methods declared __attribute__((pure)) leads to abort on (at least) FreeBSD #41
Comments
Wow, this is interesting! You mean like setting |
Seems indeed to work! |
Yes, that's exactly what I did. I didn't bother with a patch since it was such a simple change and I figured someone who knew the code might want to do it properly and keep the optimisation where exceptions weren't used or make it based on compiler. I'd be happy to have a go at a better fix if that would be helpful. |
Huh, interesting find. The GCC documentation of |
The "pure" and "const" attributes are not so well-defined, and a recent clang version implements an optimization which pushes the definition's boundary beyond what I believed it was. clang now assumes that functions declared "pure" cannot throw exceptions, even if they lack the "noexcept" specification. When compiled with this new clang version, MPD will crash randomly if an exception happens to get thrown by such as "pure" function (#41). This commit removes all such misplaced "pure" and "const" attributes, closing #41.
I quickly wrote a clang plugin which shows me code locations that need to be fixed: https://gist.github.com/MaxKellermann/758ed94d66cc744fe163bee0f854352d |
Nice way to find them. I've applied the commit and can confirm it fixes the issue I was seeing. |
Fixes a database update issue reported by ajacoutot@, fix found via FreeBSD by Andre Smagin (cf MusicPlayerDaemon/MPD#41) ok dcoppa@ (maintainer) ajacoutot@
MPD was recently changed to use C++ exceptions and I see aborts on FreeBSD. The simplest way to reproduce is to point at a music library directory with a single directory "foo" under which there's a single file "foo.mp3". Once MPD is running, move "foo" to "bar" and trigger an update. It will crash with an abort.
I tracked this down to the combination of
__attribute__((pure))
and the clang compiler which FreeBSD uses. I guess it's optimising away the exception handling. gcc seems to not make the same optimisation.There may be other cases. I've just worked around by redefining
gcc_pure
(which MPD defines to apply the attribute) to no-op.The text was updated successfully, but these errors were encountered: