This is an archive of the discontinued LLVM Phabricator instance.

[Thumb1] Do not allow Armv6-m XO and PI code
ClosedPublic

Authored by keith.walker.arm on Aug 10 2023, 7:22 AM.

Details

Summary

When generating armv6-m (Thumb1) Position Independent (PI) code
there are currently some code sequences that are not compatible
with eXecute-Only (XO) code.

For example, this simple code sequence when compiler for XO & PI:

extern int x;
int fn() { return x; }

is a problem as the address of x is currently loaded by:

  ldr r0, .L0
:
:
.L0:
  .long   x

which is not XO compiant as this involves reading the value at
.L0 which is in the code section. Generating correct code is
currently hindered by lack of suitable relocations.

Disallow the generation of armv6-m PI code together with XO code
until they can be made to work together.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2023, 7:22 AM
keith.walker.arm requested review of this revision.Aug 10 2023, 7:22 AM
john.brawn added inline comments.Aug 14 2023, 7:53 AM
clang/lib/Driver/ToolChains/Arch/ARM.cpp
853

We probably don't need to use a new diagnostic here, as -mexecute-only is already specific to the arm target and we already use err_opt_not_valid_with_opt for clashes between two target-specific options (like we do with -mno-movt just below).

clang/lib/Driver/ToolChains/Arch/ARM.cpp
853

I disagree.

In the -mno-movt case, the problem is due to that option being incompatible with the selected target, so the err_opt_not_valid_with_opt is sufficient to know that this option is clashing with the selected target.

In the XO & PI case, that clash is not with the selected target, but rather with another option on the command line when used with the selected target. You really need to know what is the other option that is causing the clash.

john.brawn added inline comments.Aug 17 2023, 5:57 AM
clang/lib/Driver/ToolChains/Arch/ARM.cpp
853

Ah, I think you're taking 'target' to mean 'the specific target' i.e. armv6-m, whereas I'm taking it to mean the arm target as a whole.

In that case I think it would be better to mention the specific target in the error message, e.g. like in err_target_unsupported_execute_only (and other err_target_unsupported errors).

olista01 added inline comments.Aug 17 2023, 7:17 AM
clang/lib/Driver/ToolChains/Arch/ARM.cpp
852

If we are rejecting -fpic and -fpie, should we also check for -fPIC and -fPIE?

Added checks for -FPIE and -f PIC command line options.

Improved error message with additiona of sub-architecture details.

keith.walker.arm marked 2 inline comments as done.Aug 18 2023, 1:34 AM
This revision is now accepted and ready to land.Aug 22 2023, 1:42 AM
This revision was landed with ongoing or failed builds.Aug 22 2023, 3:09 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2023, 3:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript