This is an archive of the discontinued LLVM Phabricator instance.

[ARM] reject -mtp=cp15 if target subarch does not support it
ClosedPublic

Authored by ardb on Nov 2 2021, 9:26 AM.

Details

Summary

Currently, we permit -mtp=cp15 even for targets that don't implement the TLS register. When building for ARMv6 or earlier, this means we emit instructions that will UNDEF at runtime. For Thumb1, passing -mtp=cp15 will trigger an assert in the backend.

So let's add some diagnostics to ensure that -mtp=cp15 is only accepted for ARMv6T2 or newer.

Diff Detail

Event Timeline

ardb created this revision.Nov 2 2021, 9:26 AM
ardb requested review of this revision.Nov 2 2021, 9:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2021, 9:26 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thanks for the patch! Don't forget to run git-clang-format HEAD~.

clang/lib/Driver/ToolChains/Arch/ARM.cpp
160–161

The last two checks seems redundant (getARMSubArchVersionNumber(Triple) < 7 && llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2). If the ArchKind was ARMV6T2 then getARMSubArchVersionNumber should return 6.

Or do we want to support ARMv6T2, in which case the patch description should be edited:

ensure that -mtp=cp15 is rejected for ARMv6T2 or earlier.

s/ARMv6T2 or earlier/ARMv6 (except ARMv6T2) or earlier/

clang/test/Driver/clang-translation.c
118–119

The -check-prefix should probably s/ARMv7/ARMv5T/.

It might be interesting to additionally test armv6 vs armv6t, depending on the answer to my question above.

ardb updated this revision to Diff 384175.Nov 2 2021, 11:31 AM
ardb edited the summary of this revision. (Show Details)

Fix test issue and add more test cases

ardb marked 2 inline comments as done.Nov 2 2021, 11:32 AM
ardb added inline comments.
clang/lib/Driver/ToolChains/Arch/ARM.cpp
160–161

The last two checks seems redundant (getARMSubArchVersionNumber(Triple) < 7 && llvm::ARM::parseArch(Triple.getArchName()) != llvm::ARM::ArchKind::ARMV6T2). If the ArchKind was ARMV6T2 then getARMSubArchVersionNumber should return 6.

Or do we want to support ARMv6T2, in which case the patch description should be edited:

ensure that -mtp=cp15 is rejected for ARMv6T2 or earlier.

s/ARMv6T2 or earlier/ARMv6 (except ARMv6T2) or earlier/

Yeah, the latter. ARMv6T2 is the first core that implements Thumb2,

nickdesaulniers accepted this revision.Nov 2 2021, 11:36 AM
This revision is now accepted and ready to land.Nov 2 2021, 11:36 AM
This revision was automatically updated to reflect the committed changes.
ardb marked an inline comment as done.