Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created March 6, 2018 09:10
Show Gist options
  • Save kaityo256/2a3628b77f9a396e57d718691f287d01 to your computer and use it in GitHub Desktop.
Save kaityo256/2a3628b77f9a396e57d718691f287d01 to your computer and use it in GitHub Desktop.
A sample code causing SIGILL on MacOS X
int main(void) {
__asm__("movl $0, 0(%rbp,%rdx,4)");
}
@kaityo256
Copy link
Author

The above code causes SIGILL on MacOS X (High Sierra 10.13.3).

Here is a result for g++.

$ g++ --version 
g++ (Homebrew GCC 7.2.0) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ test.cpp
$ ./a.out
zsh: illegal hardware instruction  ./a.out

Clang++ has the same problem.

$ clang++ --version 
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ clang++ test.cpp
$ ./a.out
zsh: illegal hardware instruction  ./a.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment