[PATCH] D41041: [ELF] Don't set the executable bit for relocatable or shared files

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 15:16:41 PST 2017


phosek updated this revision to Diff 126458.
phosek marked an inline comment as done.

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D41041

Files:
  ELF/Writer.cpp
  test/ELF/file-access.s
  test/lit.cfg.py


Index: test/lit.cfg.py
===================================================================
--- test/lit.cfg.py
+++ test/lit.cfg.py
@@ -91,3 +91,11 @@
     if 'GNU tar' in tar_version.stdout.read().decode():
         config.available_features.add('gnutar')
     tar_version.wait()
+
+stat_executable = lit.util.which('stat', config.environment['PATH'])
+if stat_executable:
+    stat_version = subprocess.Popen(
+        [stat_executable, '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
+    if 'GNU coreutils' in stat_version.stdout.read().decode():
+        config.available_features.add('gnustat')
+    stat_version.wait()
Index: test/ELF/file-access.s
===================================================================
--- /dev/null
+++ test/ELF/file-access.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86, gnustat
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -r %t.o -o %t1.o
+# RUN: stat -c %%A %t1.o | FileCheck --check-prefix=CHECK-RELOC %s
+# CHECK-RELOC: -rw-r--r--
+# RUN: ld.lld -shared %t.o -o %t2.so
+# RUN: stat -c %%A %t2.so | FileCheck --check-prefix=CHECK-SHARED %s
+# CHECK-SHARED: -rw-r--r--
+# RUN: ld.lld %t.o -o %t3
+# RUN: stat -c %%A %t3 | FileCheck --check-prefix=CHECK-EXEC %s
+# CHECK-EXEC: -rwxr-xr-x
+
+.global _start
+_start:
+  nop
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1833,9 +1833,11 @@
   }
 
   unlinkAsync(Config->OutputFile);
+  unsigned Flags = 0;
+  if (!Config->Relocatable)
+    Flags = FileOutputBuffer::F_executable;
   Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
-      FileOutputBuffer::create(Config->OutputFile, FileSize,
-                               FileOutputBuffer::F_executable);
+      FileOutputBuffer::create(Config->OutputFile, FileSize, Flags);
 
   if (!BufferOrErr)
     error("failed to open " + Config->OutputFile + ": " +


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41041.126458.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171211/c9134b4e/attachment.bin>


More information about the llvm-commits mailing list