This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Avoid switching ARM/Thumb mode on .arch/.cpu directive
ClosedPublic

Authored by olista01 on Apr 11 2016, 4:26 AM.

Details

Summary

When we see a .arch or .cpu directive, we should try to avoid switching
ARM/Thumb mode if possible.

If we do have to switch modes, we also need to emit the correct mapping
symbol for the new ISA. We did not do this previously, so could emit
ARM code with Thumb mapping symbols (or vice-versa).

The GAS behaviour is to always stay in the same mode, and to emit an
error on any instructions seen when the current mode is not available on
the current target. We can't represent that situation easily (we assume
that Thumb mode is available if ModeThumb is set), so we differ from the
GAS behaviour when switching to a target that can't support the old
mode. I've added a warning for when this implicit mode-switch occurs.

Diff Detail

Repository
rL LLVM

Event Timeline

olista01 updated this revision to Diff 53217.Apr 11 2016, 4:26 AM
olista01 retitled this revision from to [ARM] Avoid switching ARM/Thumb mode on .arch/.cpu directive.
olista01 updated this object.
olista01 added reviewers: rengolin, t.p.northover.
olista01 set the repository for this revision to rL LLVM.
olista01 added a subscriber: llvm-commits.
rengolin accepted this revision.Apr 11 2016, 5:37 AM
rengolin edited edge metadata.

Hum, this is an interesting one, and is probably only relevant for v6M and v7M.

I don't like deviating from what GNU tools do, but in this case, I don't see an easy solution.

The problem in doing this is that Clang users will have trouble using GAS, since they won't need the .code 16 for Clang, but will for GAS. The fix is easy, though, just add another .code 16 and job's done, so I agree this is not a big deal.

GCC already adds .code directives on inline assembly, and that has caused us some grief, but again, nothing serious, just a bit ugly.

Since this is no-man's land, and the change is mostly harmless, I'm ok with it (with the two extra tests).

LGTM. Thanks!

test/MC/ARM/directive-arch-mode-switch.s
25 ↗(On Diff #53217)

Add two .cpu tests, for coverage. Ex. v7 -> M0 -> A9

This revision is now accepted and ready to land.Apr 11 2016, 5:37 AM
This revision was automatically updated to reflect the committed changes.