[PATCH] D62718: [llvm-objcopy] Change output file permissions to be the same as the input file
Alex Brachet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 2 09:48:05 PDT 2019
abrachet updated this revision to Diff 202608.
abrachet added a comment.
Fixed failing test cases
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62718/new/
https://reviews.llvm.org/D62718
Files:
llvm/test/tools/llvm-objcopy/ELF/same-permissions.test
llvm/test/tools/llvm-objcopy/ELF/strip-all-and-remove.test
llvm/tools/llvm-objcopy/Buffer.cpp
llvm/tools/llvm-objcopy/llvm-objcopy.cpp
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -206,9 +206,8 @@
/// format-agnostic modifications, i.e. preserving dates.
static Error executeObjcopy(const CopyConfig &Config) {
sys::fs::file_status Stat;
- if (Config.PreserveDates)
- if (auto EC = sys::fs::status(Config.InputFilename, Stat))
- return createFileError(Config.InputFilename, EC);
+ if (auto EC = sys::fs::status(Config.InputFilename, Stat))
+ return createFileError(Config.InputFilename, EC);
if (Config.InputFormat == "binary") {
auto BufOrErr = MemoryBuffer::getFile(Config.InputFilename);
@@ -241,6 +240,10 @@
if (Error E = restoreDateOnFile(Config.SplitDWO, Stat))
return E;
}
+ if (Config.OutputFilename != "-")
+ if (std::error_code E =
+ sys::fs::setPermissions(Config.OutputFilename, Stat.permissions()))
+ return errorCodeToError(E);
return Error::success();
}
Index: llvm/tools/llvm-objcopy/Buffer.cpp
===================================================================
--- llvm/tools/llvm-objcopy/Buffer.cpp
+++ llvm/tools/llvm-objcopy/Buffer.cpp
@@ -36,7 +36,7 @@
}
Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
- FileOutputBuffer::create(getName(), Size, FileOutputBuffer::F_executable);
+ FileOutputBuffer::create(getName(), Size);
// FileOutputBuffer::create() returns an Error that is just a wrapper around
// std::error_code. Wrap it in FileError to include the actual filename.
if (!BufferOrErr)
Index: llvm/test/tools/llvm-objcopy/ELF/strip-all-and-remove.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/strip-all-and-remove.test
+++ llvm/test/tools/llvm-objcopy/ELF/strip-all-and-remove.test
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
-# RUN: cp %t %t1
+# RUN: cp -p %t %t1
# RUN: llvm-strip --remove-section=.text.bar %t
# RUN: llvm-readobj --file-headers --sections --symbols %t | FileCheck %s
Index: llvm/test/tools/llvm-objcopy/ELF/same-permissions.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/same-permissions.test
@@ -0,0 +1,6 @@
+# REQUIRES: system-linux
+# RUN: llvm-objcopy %p/Inputs/alloc-symtab.o %t
+# RUN: stat --printf=%a %p/Inputs/alloc-symtab.o > %t1
+# RUN: stat --printf=%a %t > %t2
+# RUN: diff %t1 %t2
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62718.202608.patch
Type: text/x-patch
Size: 2522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190602/8a347c99/attachment.bin>
More information about the llvm-commits
mailing list