Running GNAT On macOS Sierra
It is this time of the year again. Apple has released a new version of their operating system, now named macOS Sierra.
We started running some tests on that platform, and although we do not have full results yet, things are looking good.
The compiler and most tools work as expected.
However, Apple has once again further restricted what tools can do on the system (for sure that should result in a safer system). The major impact is on our command line debugger, gdb, since this is a tool whose whole purpose is to view and modify running processes on the system. Not something that macOS likes very much in general, although Apple's own debugger of course works flawlessly.
In previous versions of OSX, it was enough for us to codesign gdb. This no longer works, and so far there doesn't seem to be something that we can do on our side (other tools in the Apple ecosystems have similar unresolved issues).
The solutions differ on Sierra 10.12.0 and Sierra 10.12.1.
On Sierra 10.12.0
The solution will require you to slightly lower the security of your system by partially disabling SIP (System Integrity Protection). This can be done as follows:
- Reboot your system
- Keep command+R pressed until the Apple logo appears on the screen.
- Select the menu Utilities/Terminal
- Type "csrutil enable --without debug" in the terminal
- Finally, reboot your machine again
Note that disabling this will lower the security of your system, so doing the above should really be your decision.
Another impact of this change is that the DYLD_LIBRARY_PATH variable is no longer reset when spawning new processes via the shell. This variable is used by the dynamic linker to find dynamic libraries. It takes precedence over the search path coded in the executables, so is considered as unsafe by the OS. As a result, macOS by default unsets the variable so that the executable you spawn uses its own libraries. We recommend using the DYLD_FALLBACK_LIBRARY_PATH instead, which comes after the application's library search path, in case some libraries are still not found.
On Sierra 10.12.1
The solution requires a patched version of GDB, so either a recent wavefront of GNAT Pro (date >= 2016-11-08) or a fresh snapshot from FSF sources (the patch was committed today 2016-11-09).
In addition to that, you will need to add the line 'set startup-with-shell off' at the start of your GDB session, which can be done once and for all by copying it to your file .gdbinit on your $HOME. The benefit of putting it in .gdbinit is that it will work with IDEs that launch GDB for you on the program (like GPS, GNATbench or Emacs).
For reference, see Apple's forum.
We will edit this post as we discover more things about macOS Sierra
Edit: The solution for Sierra 10.12.1 still requires user action to avoiding spawning a shell from GDB. We haven't found a better solution yet, we will update the post when there is one.