aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-objcopy')
-rw-r--r--llvm/tools/llvm-objcopy/ObjcopyOptions.cpp36
-rw-r--r--llvm/tools/llvm-objcopy/ObjcopyOpts.td6
2 files changed, 42 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 7269c51..70e8546 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -736,6 +736,42 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
return createStringError(errc::invalid_argument, Reason);
}
+ for (const auto *A : InputArgs.filtered(OBJCOPY_compress_sections)) {
+ SmallVector<StringRef, 0> Fields;
+ StringRef(A->getValue()).split(Fields, '=');
+ if (Fields.size() != 2 || Fields[1].empty()) {
+ return createStringError(
+ errc::invalid_argument,
+ A->getSpelling() +
+ ": parse error, not 'section-glob=[none|zlib|zstd]'");
+ }
+
+ auto Type = StringSwitch<DebugCompressionType>(Fields[1])
+ .Case("zlib", DebugCompressionType::Zlib)
+ .Case("zstd", DebugCompressionType::Zstd)
+ .Default(DebugCompressionType::None);
+ if (Type == DebugCompressionType::None && Fields[1] != "none") {
+ return createStringError(
+ errc::invalid_argument,
+ "invalid or unsupported --compress-sections format: %s",
+ A->getValue());
+ }
+
+ auto &P = Config.compressSections.emplace_back();
+ P.second = Type;
+ auto Matcher =
+ NameOrPattern::create(Fields[0], SectionMatchStyle, ErrorCallback);
+ // =none allows overriding a previous =zlib or =zstd. Reject negative
+ // patterns, which would be confusing.
+ if (Matcher && !Matcher->isPositiveMatch()) {
+ return createStringError(
+ errc::invalid_argument,
+ "--compress-sections: negative pattern is unsupported");
+ }
+ if (Error E = P.first.addMatcher(std::move(Matcher)))
+ return std::move(E);
+ }
+
Config.AddGnuDebugLink = InputArgs.getLastArgValue(OBJCOPY_add_gnu_debuglink);
// The gnu_debuglink's target is expected to not change or else its CRC would
// become invalidated and get rejected. We can avoid recalculating the
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index be02616..4bc80eb 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -35,6 +35,12 @@ 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 compress_sections
+ : Eq<"compress-sections",
+ "Compress or decompress sections using specified format. Supported "
+ "formats: zlib, zstd. Specify 'none' for decompression">,
+ MetaVarName<"<section-glob>=<format>">;
+
defm split_dwo
: Eq<"split-dwo", "Equivalent to --extract-dwo and <dwo-file> as the output file and no other options, "
"and then --strip-dwo on the input file">,