summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2017-12-11 23:30:54 +0000
committerPetr Hosek <phosek@chromium.org>2017-12-11 23:30:54 +0000
commitd663de3e1828cdec1139bb3cb7a616590dbc1078 (patch)
treeba7f2c2a506f5d702bea6b3b9d7221ac845d9d94
parent0ca350a92d6b67b80bec0d979ccbd9245dcf6718 (diff)
downloadbcm5719-llvm-d663de3e1828cdec1139bb3cb7a616590dbc1078.tar.gz
bcm5719-llvm-d663de3e1828cdec1139bb3cb7a616590dbc1078.zip
[ELF] Don't set the executable bit for relocatable files
These are not executable files so they shouldn't be marked as such. Differential Revision: https://reviews.llvm.org/D41041 llvm-svn: 320438
-rw-r--r--lld/ELF/Writer.cpp6
-rw-r--r--lld/test/ELF/file-access.s16
-rw-r--r--lld/test/lit.cfg.py8
3 files changed, 28 insertions, 2 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 531071a4909..043f3239fe9 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1833,9 +1833,11 @@ template <class ELFT> void Writer<ELFT>::openFile() {
}
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 + ": " +
diff --git a/lld/test/ELF/file-access.s b/lld/test/ELF/file-access.s
new file mode 100644
index 00000000000..ed887c5a13b
--- /dev/null
+++ b/lld/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: -rwxr-xr-x
+# 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
diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py
index ae0dd187c60..f8436cab613 100644
--- a/lld/test/lit.cfg.py
+++ b/lld/test/lit.cfg.py
@@ -91,3 +91,11 @@ if tar_executable:
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()
OpenPOWER on IntegriCloud