copied from https://chromium.googlesource.com/external/naclports.git