at first excuse me for not providing any code, but it's hard to just C+P an excerpt, since the errors are caused somehow randomly.
I am encountering a very strange error when compiling my C source with GCC. I am developing a linked-in driver for Erlang, and I do not understand what is causing the error. The error goes like this:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffffb012aae8
[Switching to process 7316 thread 0x1503]
ktqk_exec (query=0x13e0af00, table=0x13e00ea0) at ktqk.c:215
215 clock_t start = clock();
I am running the Erlang virtual machine wrapped with GDB, so I can access the memory sections. To me, the high address 0xffffffffb012aae8
looks very suspicious. However, with Clang everything works as expected, no errors, no segfaults. I tried to investigate:
(gdb) p clock
$1 = {<text variable, no debug info>} 0x7fff85c29fd0 <clock>
(gdb) p start
$2 = 2954013712
So the value was obviously not initialized, it crashed before. When I set breakpoints in the same file, they are simply skipped. Why does everything work with Clang, but not with GCC?
Since Clang uses C99 and GCC C89 by default, I had to included the -std=c99
flag for compilation on GCC. May this be a potential source? However, when I comment out the code above, it fails at the next function call. So it seems somehow related to function calls. Nevertheless, all function calls before this line are fine.
A very strange error. Does anybody have any ideas? Sorry for this rather fuzzy explanation, I am simply not understanding the error.
All the best, Martin