On Compiling Other People’s Code and the Downside of Uppity C Compilers
I’m continuing to try to re-build LCC1802 for my fine new MacBook. Today I pushed on recompiling the excellent AS assembler that I use to translate the compiler’s output to object code.
Once I got the compiler parameters right and fixed some minor objections it built ok but blew up at run time with the unhelpful message “Abort trap: 6”. Googling around got me little but using lldb i pinned it down to the following C statement:
It looks a bit funny because the operands overlap but the intent is clearly to remove the 1st 7 characters of the string Dest. Copying Dest to Dest+7 could be bad because you could overwrite something but Dest+7 to Dest should be ok. It turns out, though, that the llvm/c runtime is CHECKING for the overlap and aborting with the “abort trap 6” message.
This is not my experience with C compilers. I can see warning at compile time but checking and aborting at run time does NOT seem useful.
I’m able to get around this by redefining strcpy as
#define strcpy(a,b) memmove(a, b, strlen(b) + 1)
Sure, because that’s a LOT safer!