How to catch data-alignment faults on x86 (aka SIGBUS on Sparc)

前端 未结 6 1002
耶瑟儿~
耶瑟儿~ 2020-12-25 15:30

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 r

6条回答
  •  感动是毒
    2020-12-25 15:57

    Many years later: if your gcc/clang is new enough (GCC 4.9, clang 3.3?) you may be able to build your code with the undefined behaviour sanitizer (-fsanitize=undefined) to get warnings about misaligned accesses on a given platform (but bear in mind different platforms have different alignment requirements, different compilers will choose different layouts etc). See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html and https://developers.redhat.com/blog/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan/ for details.

提交回复
热议问题