Is it somehow possible to catch data-alignment faults even on i386? Maybe by setting a i386 specific machine register or something like that.
On Solaris-Sparc I am receiving a SIGBUS in this case, but on i386 everything is fine.
Environment:
- 32-bit application
- Ubuntu Karmic
- gcc/g++ v4.4.1
EDIT:
Here is why I am asking this:
- our application crashes on Sol-Sparc with SIGBUS. For the purpose of debugging I would try to get a similar behavior on our i386 platform.
- our Sol-sparc machine is very slow, so compiling and debugging takes a lot of time there. And our i386 machine is unbelievable fast (8 cores, 32G memory).
- Even on i386 platforms there is a cost of performance on data-alignment faults. And therefore I would like to fix data-alignment faults wherever possible.
To expand on Vokuhila-Oliba’s answer looking at the “SOF Mis-aligned pointers on x86.” thread it seems that gcc can generate code with mis-aligned memory access. AFAIK you don’t have any control over this.
Enabling alignment checks on gcc compiled code would be a bad idea. You risk getting SIGBUS errors for good C code.
ReEdited: Sorry about that