[PATCH] D159407: [BOLT] Incorporate umask into the output file permission

Jiapeng Zhou via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 02:31:49 PDT 2023


Kepontry updated this revision to Diff 556539.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159407/new/

https://reviews.llvm.org/D159407

Files:
  bolt/lib/Rewrite/MachORewriteInstance.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/permission.test


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
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>(sys::fs::perms::all_all &
+                                  ~sys::fs::getUmask()));
   check_error(EC, "cannot set permissions of output file");
 }
 
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>(sys::fs::perms::all_all &
+                                  ~sys::fs::getUmask()));
   check_error(EC, "cannot set permissions of output file");
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159407.556539.patch
Type: text/x-patch
Size: 1877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230912/215e00b5/attachment.bin>


More information about the llvm-commits mailing list