This is an archive of the discontinued LLVM Phabricator instance.

[clang][driver][NFC] Call IsARMBigEndain function only for isARM and isThumb.
ClosedPublic

Authored by simpal01 on Jul 20 2023, 3:03 AM.

Details

Summary

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.

Diff Detail

Event Timeline

simpal01 created this revision.Jul 20 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 3:03 AM
simpal01 requested review of this revision.Jul 20 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 3:03 AM
simpal01 retitled this revision from [clang][driver] Missing the condition in ISARMBigEndain function. to [clang][driver] Missing the condition in IsARMBigEndain function..
simpal01 edited the summary of this revision. (Show Details)Jul 20 2023, 3:23 AM
simpal01 edited the summary of this revision. (Show Details)
peter.smith added inline comments.Jul 20 2023, 3:37 AM
clang/lib/Driver/ToolChains/Arch/ARM.cpp
39 ↗(On Diff #542403)

Is this the right place to fix?

I would expect it to be a precondition that the Triple was Arm or Thumb before calling isARMBigEndian?

For example

if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
    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");
  }

Shouldn't this be refactored to only call isARMBigEndian for isARM and isThumb? Something like:

if ((Triple.isARM() || Triple.isThumb()) {
  bool BigEndian = arm::isARMBigEndian(Triple, Args);
  if (BigEndian)
    arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
  CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
} else if (Triple.isAArch64)) {
  CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
}

This is a bit longer but it is easier to read and keeps ARM and AArch64 separate.

simpal01 updated this revision to Diff 543484.Jul 24 2023, 5:26 AM

Addressing review comments.

simpal01 retitled this revision from [clang][driver] Missing the condition in IsARMBigEndain function. to [clang][driver] Call IsARMBigEndain function only for isARM and isThumb..Jul 24 2023, 5:31 AM
simpal01 edited the summary of this revision. (Show Details)
MaskRay accepted this revision.Jul 24 2023, 8:52 AM

Sounds good to make arm::isARMBigEndian focus on AArch32 :)

This revision is now accepted and ready to land.Jul 24 2023, 8:52 AM

Add NFC if this is NFC?

simpal01 retitled this revision from [clang][driver] Call IsARMBigEndain function only for isARM and isThumb. to [clang][driver][NFC] Call IsARMBigEndain function only for isARM and isThumb..Jul 24 2023, 9:23 AM

Add NFC if this is NFC?

Done

This revision was landed with ongoing or failed builds.Jul 25 2023, 1:21 AM
This revision was automatically updated to reflect the committed changes.