From 9dcd232f4afabdad46e5bc2d71834765acd7738c Mon Sep 17 00:00:00 2001 From: Simi Pallipurath Date: Thu, 20 Jul 2023 10:26:45 +0100 Subject: [PATCH] [clang][driver][NFC] Call IsARMBigEndain function only for isARM and isThumb. IsARMBIgEndian function returns true only if: 1. The triples are either arm or thumb and the commandline has the option -mbig-endian 2. The triples are either armeb or thumbeb. Missing the checking of arm or thumb triples in the first case pass through the --be8 endian flag to linker For AArch64 as well which is not expected. This is the regression happened from the previous patch https://reviews.llvm.org/D154786. It is better to refactor to only call IsARMBigEndian for isARM and isthumb satisfying conditions which keeps ARM and AArch64 separate. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D155808 --- clang/lib/Driver/ToolChains/BareMetal.cpp | 5 +++-- clang/lib/Driver/ToolChains/Gnu.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 0d9a103..26a6276 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -443,12 +443,13 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-Bstatic"); - if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) { + if (Triple.isARM() || Triple.isThumb()) { bool IsBigEndian = arm::isARMBigEndian(Triple, Args); if (IsBigEndian) arm::appendBE8LinkFlag(Args, CmdArgs, Triple); - IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be; CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL"); + } else if (Triple.isAArch64()) { + CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL"); } Args.AddAllArgs(CmdArgs, diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index b58a607..b64fff8 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -424,12 +424,13 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_s)) CmdArgs.push_back("-s"); - if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) { + if (Triple.isARM() || Triple.isThumb()) { bool IsBigEndian = arm::isARMBigEndian(Triple, Args); if (IsBigEndian) arm::appendBE8LinkFlag(Args, CmdArgs, Triple); - IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be; CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL"); + } else if (Triple.isAArch64()) { + CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL"); } // Most Android ARM64 targets should enable the linker fix for erratum -- 2.7.4