[llvm] 96f3a63 - [llvm-objcopy] --dump-section: error if '=' is missing or filename is empty

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue May 4 17:31:04 PDT 2021


Author: Fangrui Song
Date: 2021-05-04T17:30:57-07:00
New Revision: 96f3a6307670bc6c79c44bf01be507dd8a1af30e

URL: https://github.com/llvm/llvm-project/commit/96f3a6307670bc6c79c44bf01be507dd8a1af30e
DIFF: https://github.com/llvm/llvm-project/commit/96f3a6307670bc6c79c44bf01be507dd8a1af30e.diff

LOG: [llvm-objcopy] --dump-section: error if '=' is missing or filename is empty

Fix PR45416: the diagnostic when '=' is missing is misleading.
`FileOutputBuffer::create` returns successfully when the filename is empty
(the temporary file is `.tmp%%%%%%%`), but `FileOutputBuffer::commit` will error when
renaming `.tmp%%%%%%%` to the empty name).

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D101697

Added: 
    

Modified: 
    llvm/test/tools/llvm-objcopy/ELF/dump-section.test
    llvm/tools/llvm-objcopy/CopyConfig.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
index daa29b3948b2a..037ec86090e55 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
@@ -59,3 +59,8 @@ ProgramHeaders:
 # RUN:   FileCheck %s --check-prefix=ERR -DFILE=%t -DSECTION=.missing
 
 # ERR: error: '[[FILE]]': section '[[SECTION]]' not found
+
+# RUN: not llvm-objcopy --dump-section .text %t /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
+# RUN: not llvm-objcopy --dump-section .text= %t /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
+
+# ERR2: error: bad format for --dump-section, expected section=file

diff  --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index 3ecf45dea1f94..5669928aac974 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -700,8 +700,14 @@ parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
           "bad format for --add-section: missing file name");
     Config.AddSection.push_back(ArgValue);
   }
-  for (auto Arg : InputArgs.filtered(OBJCOPY_dump_section))
-    Config.DumpSection.push_back(Arg->getValue());
+  for (auto *Arg : InputArgs.filtered(OBJCOPY_dump_section)) {
+    StringRef Value(Arg->getValue());
+    if (Value.split('=').second.empty())
+      return createStringError(
+          errc::invalid_argument,
+          "bad format for --dump-section, expected section=file");
+    Config.DumpSection.push_back(Value);
+  }
   Config.StripAll = InputArgs.hasArg(OBJCOPY_strip_all);
   Config.StripAllGNU = InputArgs.hasArg(OBJCOPY_strip_all_gnu);
   Config.StripDebug = InputArgs.hasArg(OBJCOPY_strip_debug);


        


More information about the llvm-commits mailing list