This is an archive of the discontinued LLVM Phabricator instance.

[clang][Arm] Fix handling of -Wa,-march=
ClosedPublic

Authored by DavidSpickett on Feb 2 2021, 7:27 AM.

Details

Summary

This fixes Bugzilla #48894 for Arm, where it
was reported that -Wa,-march was not being handled
by the integrated assembler.

This was previously fixed for -Wa,-mthumb by
parsing the argument in ToolChain::ComputeLLVMTriple
instead of CollectArgsForIntegratedAssembler.
It has to be done in the former because the Triple
is read only by the time we get to the latter.

Previously only mcpu would work via -Wa but only because
"-target-cpu" is it's own option to cc1, which we were
able to modify. Target architecture is part of "-target-triple".

This change applies the same workaround to -march and cleans up
handling of -Wa,-mcpu at the same time. There were some
places where we were not using the last instance of an argument.

The existing -Wa,-mthumb code was doing this correctly,
so I've just added tests to confirm that.

Now the same rules will apply to -Wa,-march/-mcpu as would
if you just passed them to the compiler:

  • -Wa/-Xassembler options only apply to assembly files.
  • Architecture derived from mcpu beats any march options.
  • When there are multiple mcpu or multiple march, the last one wins.
  • If there is a compiler option and an assembler option of the same type, we prefer the one that fits the input type.
  • If there is an applicable mcpu option but it is overruled by an march, the cpu value is still used for the "-target-cpu" cc1 option.

Diff Detail

Event Timeline

DavidSpickett created this revision.Feb 2 2021, 7:27 AM
DavidSpickett requested review of this revision.Feb 2 2021, 7:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2021, 7:27 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
DavidSpickett added inline comments.
clang/lib/Driver/ToolChain.cpp
753

Suffix originally set here, from any compiler options.

807

Then we override that if we're using the assembler and have -Wa options.

Wow, thank you so much for the work that went into this patch! Very thorough tests. Just minor questions about yet more test cases. Patch LGTM.

clang/test/Driver/arm-target-as-march-mcpu.s
43

Below you have a comment (cortex-a32 is armv8a). That is very helpful for me. I assume cortex-a8 is armv7a?

44

I guess -check-prefix is accepted with one or two leading hyphens. Let's pick one style to use consistently in this test.

83

add a -mcpu=foo,bar test for -mcpu? (Comma separated)

95

add a comma separated test? (-march=armv8-a,armv7-a)

clang/test/Driver/arm-target-as-mthumb.s
9–17

Should we add space separated tests for these? -Wa,-mcpu=cortex-a8 -Wa,-mthumb?

nickdesaulniers added inline comments.Feb 2 2021, 3:03 PM
clang/test/Driver/arm-target-as-march-mcpu.s
43

And if so, would you mind adding a similar comment here?

  • Added split -Wa test for -mthumb
  • Use --check-prefix/--check-prefixes
  • Comment at top of march/mcpu file to explain choice of test CPUs
DavidSpickett marked 6 inline comments as done.Feb 3 2021, 2:29 AM
DavidSpickett added inline comments.
clang/test/Driver/arm-target-as-march-mcpu.s
43

Exactly, I've added a comment up top to explain the logic in one place.

83

mcpu and march don't let you use multiple values:

error: the clang compiler does not support '-march=armv8-a,armv7-a'
error: unsupported argument 'armv7-a' to option 'Wa,

(the latter it thinks that its another arg like -Wa,armv7-a)

Pretty sure that's tested elsewhere or if it isn't, this isn't the place for it at least.

nickdesaulniers accepted this revision.Feb 3 2021, 9:59 AM

Looks great. Thanks again David.

This revision is now accepted and ready to land.Feb 3 2021, 9:59 AM
This revision was landed with ongoing or failed builds.Feb 4 2021, 8:36 AM
This revision was automatically updated to reflect the committed changes.
DavidSpickett marked an inline comment as done.