Update libffi to 3.1

Update libffi to 3.1 to add support for new architectures.
libffi: restore some small patches

Also, revert file-permission changes.