Skip to content

Commit

Permalink
[clang][driver][NFC] Call IsARMBigEndain function only for isARM and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
simpal01 committed Jul 25, 2023
1 parent 4eff7fa commit 9dcd232
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Driver/ToolChains/BareMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9dcd232

Please sign in to comment.