[llvm] ef03f66 - [llvm-objcopy] Simplify --compress-debug-sections handling with AliasArgs. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 00:31:04 PDT 2022
Author: Fangrui Song
Date: 2022-07-25T00:31:00-07:00
New Revision: ef03f6623c9b19900891745c844c8754811e5f14
URL: https://github.com/llvm/llvm-project/commit/ef03f6623c9b19900891745c844c8754811e5f14
DIFF: https://github.com/llvm/llvm-project/commit/ef03f6623c9b19900891745c844c8754811e5f14.diff
LOG: [llvm-objcopy] Simplify --compress-debug-sections handling with AliasArgs. NFC
Added:
Modified:
llvm/docs/CommandGuide/llvm-objcopy.rst
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
llvm/tools/llvm-objcopy/ObjcopyOpts.td
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index 74e2b024c70d1..01bb43ecbf48b 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -296,11 +296,10 @@ them.
Add ``<incr>`` to the program's start address. Can be specified multiple
times, in which case the values will be applied cumulatively.
-.. option:: --compress-debug-sections [<style>]
+.. option:: --compress-debug-sections [<format>]
- Compress DWARF debug sections in the output, using the specified style.
- Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
- specified.
+ Compress DWARF debug sections in the output, using the specified format.
+ Supported formats are ``zlib``. Use ``zlib`` if ``<format>`` is omitted.
.. option:: --decompress-debug-sections
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 8a2b4855501bb..7db1e79f3e49a 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -719,24 +719,15 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
}
}
- if (auto Arg = InputArgs.getLastArg(OBJCOPY_compress_debug_sections,
- OBJCOPY_compress_debug_sections_eq)) {
- Config.CompressionType = DebugCompressionType::Z;
-
- if (Arg->getOption().getID() == OBJCOPY_compress_debug_sections_eq) {
- Config.CompressionType =
- StringSwitch<DebugCompressionType>(
- InputArgs.getLastArgValue(OBJCOPY_compress_debug_sections_eq))
- .Case("zlib", DebugCompressionType::Z)
- .Default(DebugCompressionType::None);
- if (Config.CompressionType == DebugCompressionType::None)
- return createStringError(
- errc::invalid_argument,
- "invalid or unsupported --compress-debug-sections format: %s",
- InputArgs.getLastArgValue(OBJCOPY_compress_debug_sections_eq)
- .str()
- .c_str());
- }
+ if (const auto *A = InputArgs.getLastArg(OBJCOPY_compress_debug_sections)) {
+ Config.CompressionType = StringSwitch<DebugCompressionType>(A->getValue())
+ .Case("zlib", DebugCompressionType::Z)
+ .Default(DebugCompressionType::None);
+ if (Config.CompressionType == DebugCompressionType::None)
+ return createStringError(
+ errc::invalid_argument,
+ "invalid or unsupported --compress-debug-sections format: %s",
+ A->getValue());
if (!compression::zlib::isAvailable())
return createStringError(
errc::invalid_argument,
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index 962028da47a04..d3713b5ec3c32 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -29,12 +29,13 @@ defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of "
" with --add-symbol unless otherwise"
" specified. The default value is 'default'.">;
-def compress_debug_sections : Flag<["--"], "compress-debug-sections">;
-def compress_debug_sections_eq
+def compress_debug_sections
: Joined<["--"], "compress-debug-sections=">,
- MetaVarName<"[ zlib ]">,
- HelpText<"Compress DWARF debug sections using specified style. Supported "
- "formats: 'zlib'">;
+ MetaVarName<"format">,
+ HelpText<"Compress DWARF debug sections using specified format. Supported "
+ "formats: zlib">;
+def : Flag<["--"], "compress-debug-sections">, Alias<compress_debug_sections>,
+ AliasArgs<["zlib"]>;
def decompress_debug_sections : Flag<["--"], "decompress-debug-sections">,
HelpText<"Decompress DWARF debug sections.">;
defm split_dwo
More information about the llvm-commits
mailing list