From 10ed0e406589604bf8ea5edd571a6f72dd8a6721 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 8 Feb 2025 16:36:46 -0800 Subject: [PATCH] [ELF] Reorder target-specific error messaes --- lld/ELF/Driver.cpp | 75 +++++++++++++------------- lld/test/ELF/target-specific-options.s | 2 +- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 2835b86d05e9..3d6e022a89e5 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -371,6 +371,9 @@ static void checkOptions(Ctx &ctx) { if (!ctx.arg.cmseOutputLib.empty()) ErrAlways(ctx) << "--out-implib may not be used without --cmse-implib"; } + if (ctx.arg.fixCortexA8 && !ctx.arg.isLE) + ErrAlways(ctx) + << "--fix-cortex-a8 is not supported on big endian targets"; } else { if (ctx.arg.cmseImplib) ErrAlways(ctx) << "--cmse-implib is only supported on ARM targets"; @@ -378,30 +381,46 @@ static void checkOptions(Ctx &ctx) { ErrAlways(ctx) << "--in-implib is only supported on ARM targets"; if (!ctx.arg.cmseOutputLib.empty()) ErrAlways(ctx) << "--out-implib is only supported on ARM targets"; + if (ctx.arg.fixCortexA8) + ErrAlways(ctx) << "--fix-cortex-a8 is only supported on ARM targets"; + if (ctx.arg.armBe8) + ErrAlways(ctx) << "--be8 is only supported on ARM targets"; } - if (ctx.arg.fixCortexA53Errata843419 && ctx.arg.emachine != EM_AARCH64) - ErrAlways(ctx) - << "--fix-cortex-a53-843419 is only supported on AArch64 targets"; + if (ctx.arg.emachine != EM_AARCH64) { + if (ctx.arg.executeOnly) + ErrAlways(ctx) << "--execute-only is only supported on AArch64 targets"; + if (ctx.arg.fixCortexA53Errata843419) + ErrAlways(ctx) << "--fix-cortex-a53-843419 is only supported on AArch64"; + if (ctx.arg.zPacPlt) + ErrAlways(ctx) << "-z pac-plt only supported on AArch64"; + if (ctx.arg.zForceBti) + ErrAlways(ctx) << "-z force-bti only supported on AArch64"; + if (ctx.arg.zBtiReport != "none") + ErrAlways(ctx) << "-z bti-report only supported on AArch64"; + if (ctx.arg.zPauthReport != "none") + ErrAlways(ctx) << "-z pauth-report only supported on AArch64"; + if (ctx.arg.zGcsReport != "none") + ErrAlways(ctx) << "-z gcs-report only supported on AArch64"; + if (ctx.arg.zGcs != GcsPolicy::Implicit) + ErrAlways(ctx) << "-z gcs only supported on AArch64"; + } - if (ctx.arg.fixCortexA8 && ctx.arg.emachine != EM_ARM) - ErrAlways(ctx) << "--fix-cortex-a8 is only supported on ARM targets"; - - if (ctx.arg.armBe8 && ctx.arg.emachine != EM_ARM) - ErrAlways(ctx) << "--be8 is only supported on ARM targets"; - - if (ctx.arg.fixCortexA8 && !ctx.arg.isLE) - ErrAlways(ctx) << "--fix-cortex-a8 is not supported on big endian targets"; - - if (ctx.arg.tocOptimize && ctx.arg.emachine != EM_PPC64) - ErrAlways(ctx) << "--toc-optimize is only supported on PowerPC64 targets"; - - if (ctx.arg.pcRelOptimize && ctx.arg.emachine != EM_PPC64) - ErrAlways(ctx) << "--pcrel-optimize is only supported on PowerPC64 targets"; + if (ctx.arg.emachine != EM_PPC64) { + if (ctx.arg.tocOptimize) + ErrAlways(ctx) << "--toc-optimize is only supported on PowerPC64 targets"; + if (ctx.arg.pcRelOptimize) + ErrAlways(ctx) + << "--pcrel-optimize is only supported on PowerPC64 targets"; + } if (ctx.arg.relaxGP && ctx.arg.emachine != EM_RISCV) ErrAlways(ctx) << "--relax-gp is only supported on RISC-V targets"; + if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 && + ctx.arg.zCetReport != "none") + ErrAlways(ctx) << "-z cet-report only supported on X86 and X86_64"; + if (ctx.arg.pie && ctx.arg.shared) ErrAlways(ctx) << "-shared and -pie may not be used together"; @@ -435,9 +454,6 @@ static void checkOptions(Ctx &ctx) { } if (ctx.arg.executeOnly) { - if (ctx.arg.emachine != EM_AARCH64) - ErrAlways(ctx) << "--execute-only is only supported on AArch64 targets"; - if (ctx.arg.singleRoRx && !ctx.script->hasSectionsCommand) ErrAlways(ctx) << "--execute-only and --no-rosegment cannot be used together"; @@ -445,25 +461,6 @@ static void checkOptions(Ctx &ctx) { if (ctx.arg.zRetpolineplt && ctx.arg.zForceIbt) ErrAlways(ctx) << "-z force-ibt may not be used with -z retpolineplt"; - - if (ctx.arg.emachine != EM_AARCH64) { - if (ctx.arg.zPacPlt) - ErrAlways(ctx) << "-z pac-plt only supported on AArch64"; - if (ctx.arg.zForceBti) - ErrAlways(ctx) << "-z force-bti only supported on AArch64"; - if (ctx.arg.zBtiReport != "none") - ErrAlways(ctx) << "-z bti-report only supported on AArch64"; - if (ctx.arg.zPauthReport != "none") - ErrAlways(ctx) << "-z pauth-report only supported on AArch64"; - if (ctx.arg.zGcsReport != "none") - ErrAlways(ctx) << "-z gcs-report only supported on AArch64"; - if (ctx.arg.zGcs != GcsPolicy::Implicit) - ErrAlways(ctx) << "-z gcs only supported on AArch64"; - } - - if (ctx.arg.emachine != EM_386 && ctx.arg.emachine != EM_X86_64 && - ctx.arg.zCetReport != "none") - ErrAlways(ctx) << "-z cet-report only supported on X86 and X86_64"; } static const char *getReproduceOption(opt::InputArgList &args) { diff --git a/lld/test/ELF/target-specific-options.s b/lld/test/ELF/target-specific-options.s index 94dccd9e4a0c..0f126f0186f8 100644 --- a/lld/test/ELF/target-specific-options.s +++ b/lld/test/ELF/target-specific-options.s @@ -2,7 +2,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t # RUN: not ld.lld %t --fix-cortex-a53-843419 -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-843419 -# ERR-843419: error: --fix-cortex-a53-843419 is only supported on AArch64 targets +# ERR-843419: error: --fix-cortex-a53-843419 is only supported on AArch64 # RUN: not ld.lld %t --be8 -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-BE8 # ERR-BE8: error: --be8 is only supported on ARM targets