This is an archive of the discontinued LLVM Phabricator instance.

[Linker] Add directives to support mixing ARM/Thumb module-level inline asm.
ClosedPublic

Authored by fhahn on Jun 26 2017, 7:45 AM.

Details

Summary

By prepending .text .thumb .balign 2 to the module-level inline
assembly from a Thumb module, the assembler will generate the assembly
from that module as Thumb, even if the destination module uses an ARM
triple. Similar directives are used for module-level inline assembly in
ARM modules.

The alignment and instruction set are reset based on the target triple
before emitting the first function label.

Diff Detail

Event Timeline

fhahn created this revision.Jun 26 2017, 7:45 AM
tejohnson edited edge metadata.Jun 28 2017, 9:00 AM

Can you add comments to the top of your tests as to what is being tested?

lib/Linker/IRMover.cpp
1309

Suggest outlining this handling in a helper function that takes the original module inline asm string and passes back a new one.

1311

Should this first check if the dest module is of the other arch before emitting these?

I guess by always emitting then you don't have to worry about needing to switch the arch again back to the dest arch. I.e. in the case where the dest module is arm, a source module with thumb inline assembly linked in, followed by another source module with arm inline assembly being linked in (I assume this needs to get ".thumb" for source module 1 and then ".arm" for source module 2). Is that why it is being unconditionally emitted?

test/MC/ARM/inline-asm-switch-mode.ll
10 ↗(On Diff #103950)

Confused as to what is being tested here since no llvm-link invocation.

fhahn updated this revision to Diff 104442.Jun 28 2017, 9:39 AM
fhahn marked 2 inline comments as done.

Outlined code to add directives, removed MC test case

lib/Linker/IRMover.cpp
1311

Exactly. Also I think there are cases where we have to emit .arm even though we merge an ARM module into an ARM module. For example: We merge module M1 - Thumb and module M2 - ARM into an ARM module.

We have to emit .arm for the inline assembly of M2 (even thought the dest module is also ARM), because M1 set .thumb.

test/MC/ARM/inline-asm-switch-mode.ll
10 ↗(On Diff #103950)

Ah sorry about that. This test ensures that the mode is reset properly before the first function. I'll remove it from this patch and commit is separately.

echristo edited edge metadata.Jun 28 2017, 9:40 AM

Can you give me an example here of what you're trying to accomplish? I'm not sure I understand.

fhahn added a comment.Jun 28 2017, 9:45 AM

@echristo when linking ARM and Thumb modules, their module-level inline assembly can contain instructions only available in Thumb or ARM, e.g. ORN in test/Linker/Inputs/thumb-module-inline-asm.ll is only available in Thumb. Without adding .arm/.thumb when joining the inline assembly, assembling destination module will fail, if an ARM triple is used.

This looks ok to me now, but please wait for echristo to see if he has more concerns or a different suggestion for handling this situation.

lib/Linker/IRMover.cpp
1311

Ok, that's what I thought - that was the scenario I was trying to describe.

fhahn added a comment.Jul 5 2017, 8:14 AM

@echristo Did the case I described make sense?

echristo accepted this revision.Jul 12 2017, 3:39 AM

Not a huge fan, but also don't have any better ideas for now.

All of the work you've been doing seems like it should have a release note - including breaking out this sort of code transformation.

Thanks!

-eric

This revision is now accepted and ready to land.Jul 12 2017, 3:39 AM
fhahn added a comment.Jul 12 2017, 3:46 AM

Thanks. There are people currently testing mixed ARM/Thumb LTO on real-world projects and I assume there will be a few more bugs that need addressing. I think it would be worth waiting a little bit with adding the release note until they had some more time for testing.

Cheers!

Thanks. There are people currently testing mixed ARM/Thumb LTO on real-world projects and I assume there will be a few more bugs that need addressing. I think it would be worth waiting a little bit with adding the release note until they had some more time for testing.

Cheers!

Sure, as long as something gets written :)

-eric

fhahn closed this revision.Jul 12 2017, 4:52 AM