}
}
-static DebugCompressionType getCompressDebugSections(opt::InputArgList &args) {
- StringRef s = args.getLastArgValue(OPT_compress_debug_sections, "none");
- if (s == "zlib") {
- if (!compression::zlib::isAvailable())
- error("--compress-debug-sections: zlib is not available");
- return DebugCompressionType::Zlib;
- }
- if (s == "zstd") {
- if (!compression::zstd::isAvailable())
- error("--compress-debug-sections: zstd is not available");
- return DebugCompressionType::Zstd;
+static DebugCompressionType getCompressionType(StringRef s, StringRef option) {
+ DebugCompressionType type = StringSwitch<DebugCompressionType>(s)
+ .Case("zlib", DebugCompressionType::Zlib)
+ .Case("zstd", DebugCompressionType::Zstd)
+ .Default(DebugCompressionType::None);
+ if (type == DebugCompressionType::None) {
+ if (s != "none")
+ error("unknown " + option + " value: " + s);
+ } else if (const char *reason = compression::getReasonIfUnsupported(
+ compression::formatFor(type))) {
+ error(option + ": " + reason);
}
- if (s != "none")
- error("unknown --compress-debug-sections value: " + s);
- return DebugCompressionType::None;
+ return type;
}
static StringRef getAliasSpelling(opt::Arg *arg) {
config->checkSections =
args.hasFlag(OPT_check_sections, OPT_no_check_sections, true);
config->chroot = args.getLastArgValue(OPT_chroot);
- config->compressDebugSections = getCompressDebugSections(args);
+ config->compressDebugSections = getCompressionType(
+ args.getLastArgValue(OPT_compress_debug_sections, "none"),
+ "--compress-debug-sections");
config->cref = args.hasArg(OPT_cref);
config->optimizeBBJumps =
args.hasFlag(OPT_optimize_bb_jumps, OPT_no_optimize_bb_jumps, false);
--- /dev/null
+# REQUIRES: x86
+# UNSUPPORTED: zlib
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: ld.lld %t.o --compress-debug-sections=zlib --compress-debug-sections=none -o /dev/null 2>&1 | count 0
+# RUN: not ld.lld %t.o --compress-debug-sections=zlib -o /dev/null 2>&1 | \
+# RUN: FileCheck %s --implicit-check-not=error:
+
+# CHECK: error: --compress-debug-sections: LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at build time
+
+.globl _start
+_start: