Index: bolt/lib/Rewrite/MachORewriteInstance.cpp =================================================================== --- bolt/lib/Rewrite/MachORewriteInstance.cpp +++ bolt/lib/Rewrite/MachORewriteInstance.cpp @@ -564,8 +564,10 @@ writeInstrumentationSection("I__literal16", OS); Out->keep(); - EC = sys::fs::setPermissions(opts::OutputFilename, - sys::fs::perms::all_all); + EC = sys::fs::setPermissions( + opts::OutputFilename, + static_cast(sys::fs::perms::all_all & + ~sys::fs::getUmask())); check_error(EC, "cannot set permissions of output file"); } Index: bolt/lib/Rewrite/RewriteInstance.cpp =================================================================== --- bolt/lib/Rewrite/RewriteInstance.cpp +++ bolt/lib/Rewrite/RewriteInstance.cpp @@ -5359,7 +5359,10 @@ } Out->keep(); - EC = sys::fs::setPermissions(opts::OutputFilename, sys::fs::perms::all_all); + EC = sys::fs::setPermissions( + opts::OutputFilename, + static_cast(sys::fs::perms::all_all & + ~sys::fs::getUmask())); check_error(EC, "cannot set permissions of output file"); } Index: bolt/test/permission.test =================================================================== --- /dev/null +++ bolt/test/permission.test @@ -0,0 +1,13 @@ +# Ensure that the permissions of the optimized binary file comply with the +# system's umask. + +# This test performs a logical AND operation on the results of the `stat -c %a +# %t.bolt` and `umask` commands (both results are displayed in octal), and +# checks whether the result is equal to 0. +REQUIRES: system-linux + +RUN: %clang %cflags %p/Inputs/hello.c -o %t -Wl,-q +RUN: llvm-bolt %t -o %t.bolt +RUN: echo $(( 8#$(stat -c %a %t.bolt) & 8#$(umask) )) | FileCheck %s + +CHECK: 0