-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Segmentation fault with clang + optimizations (-O2) #18
Comments
This is unfortunate. I've heard other reports of a broken build with Clang 3.6 too, and I remember having build problems with earlier versions of Clang (3.2, I believe). It's been fine with 3.3, 3.4, and 3.5, though, so I assume it has to be a recently-resurfaced (or a new) problem in Clang. |
Hmm, that's interesting. We are using clang by default on FreeBSD to build thousands of packages and this kind of problem is uncommon. BTW, it really works with clang 3.4! =/ You can update your list, it fails with clang 3.8 as well. |
Is there any more information you can provide about what the problem might be? OpenAL Soft uses quite a few C99 features, and even some C11 features when available (threading stuff and atomics mostly), along with some GNU extensions to pick up some slack, so it's possible it's hitting some obscure bugs caused by certain (combinations of) features. Or perhaps OpenAL Soft is using some feature or function incorrectly that just happens to work on GCC and pre-3.6 Clang. Unfortunately, Debian doesn't have 3.6 in the stable or unstable repos, so it's not that easy for me to test myself. |
The clang's AddressSanitizer caught a buffer overflow in openal. I've copied it here -> http://pastebin.com/kndRZnj2 |
Are you able to test using the latest Git version, just to ensure it's still present? The log doesn't make much sense. It says there's a 1-byte allocation, but it's using 16-bit samples, so the allocation must be at least a multiple of 2. I can only guess that's because it allocated a 0-byte buffer (from 0 length input) but the system gave it a minimum of 1 byte. In that case, the sample length would be 0, so it shouldn't try loading from the buffer. Are you able to get any more information, such as the offending ALbuffer's member values? |
There is a realloc call in LoadData() function receiving the second parameter as zero. The specification of realloc says that if the size is zero and the pointer is not null it'll be freed. The PoC patch avoids the crash, but no sound though. --- OpenAL32/alBuffer.c.orig 2015-09-20 19:31:23 UTC
I'll try the latest code from git. |
With the latest version it works. |
Yeah, realloc is kinda funny. It also says that if the pointer is null, it'll act like Good to hear it works in the latest git, though I can't help but feel the issue is being masked. I don't remember fixing anything in this regard. Does the sound work too, or is it silent like with 1.16 and your patch? If ithe sound works, that's particularly curious since the |
Yes, the sound just works.
|
This patch fixes the problem -> http://pastebin.com/YYzwdd9m |
For some reason clang is breaking the code when openal-soft is built with optimizations. If the file alBuffer.c is built with -O1 the problem don't happens. See kcat/openal-soft#18 The problem seems to happen just on CURRENT due the clang version. PR: 199488, 203818 Tested by: ohartman@zedat.fu-berlin.de Approved by: mva MFH: 2015Q4 git-svn-id: svn+ssh://svn.freebsd.org/ports/head@399540 35697150-7ecd-e111-bb59-0022644237b5
For some reason clang is breaking the code when openal-soft is built with optimizations. If the file alBuffer.c is built with -O1 the problem don't happens. See kcat/openal-soft#18 The problem seems to happen just on CURRENT due the clang version. PR: 199488, 203818 Tested by: ohartman@zedat.fu-berlin.de Approved by: mva MFH: 2015Q4
- Add a workaround for a problem caused by clang For some reason clang is breaking the code when openal-soft is built with optimizations. If the file alBuffer.c is built with -O1 the problem don't happens. See kcat/openal-soft#18 The problem seems to happen just on CURRENT due the clang version. PR: 199488, 203818 Tested by: ohartman@zedat.fu-berlin.de Approved by: mva Approved by: ports-secteam (feld)
Is it cased by loop vectorization? |
I think I may have "fixed" the problem, assuming it's the same thing that was affecting OSX/XCode (which uses Clang too). Can you check to see if it's working properly now? If it is fixed, it seems to have been an issue with certain functions being marked as |
I think you should try with: http://clang.llvm.org/docs/AddressSanitizer.html And: http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html Clang devs say if you run with these and fix all issues and optimization breaks the code, then raise a compiler bug. But likely there is memory/ub error some where and these sanitizers will find them at runtime. |
Seems it was because I marked a function as
The GCC docs say that const functions must not read global memory (do function-local static const variables count as global memory in this context?) and have no effects except for their return values (the return statement, and the two output parameters). It also says that such functions mustn't read from any pointer parameters (it doesn't, it only writes to them). I can only guess I had a more loose definition of "return value" -- results given back by the function, rather than strictly what the call's expression is evaluated as. The Undefined Behavior Sanitizer didn't report any problems, and there was no warning by the compiler that I was doing something bad in a const function (using |
Hmm hard for me to say if this a bug in the tooling or not, I guess it can't tell if you are passing in pointers to "global" memory or not. |
- Add a workaround for a problem caused by clang For some reason clang is breaking the code when openal-soft is built with optimizations. If the file alBuffer.c is built with -O1 the problem don't happens. See kcat/openal-soft#18 The problem seems to happen just on CURRENT due the clang version. PR: 199488, 203818 Tested by: ohartman@zedat.fu-berlin.de Approved by: mva Approved by: ports-secteam (feld)
- Add a workaround for a problem caused by clang For some reason clang is breaking the code when openal-soft is built with optimizations. If the file alBuffer.c is built with -O1 the problem don't happens. See kcat/openal-soft#18 The problem seems to happen just on CURRENT due the clang version. PR: 199488, 203818 Tested by: ohartman@zedat.fu-berlin.de Approved by: mva Approved by: ports-secteam (feld)
Hello,
I'm building solarus (https://github.com/christopho/solarus/) with openal-soft and I'm getting a segfault when I build it with clang. Actually, the program crashes when I build openal-soft with optimizations enabled. If I build openal with -O0 it works fine. With GCC it just works. I'm using openal-soft 1.16.0 and clang 3.6.1.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 808416400 (LWP 100215)]
Load_ALshort (srcstep=, samples=, dst=, src=) at /usr/ports/audio/openal-soft/work/openal-soft-1.16.0/Alc/mixer.c:119
119 DECL_TEMPLATE(ALshort)
The backtrace:
The text was updated successfully, but these errors were encountered: