diff options
author | Florian Hahn <florian.hahn@arm.com> | 2017-07-12 11:52:28 +0000 |
---|---|---|
committer | Florian Hahn <florian.hahn@arm.com> | 2017-07-12 11:52:28 +0000 |
commit | dba40dd7a1193dee3f1e615e602914dd073073de (patch) | |
tree | 4db42de9fa4e10eec726400090abbfa9e737def5 /lib/Linker/IRMover.cpp | |
parent | a3db45981cb7219619802cbfd263f9518f4d5b69 (diff) |
[Linker] Add directives to support mixing ARM/Thumb module-level inline asm.
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.
Reviewers: olista01, tejohnson, echristo, t.p.northover, rafael
Reviewed By: echristo
Subscribers: aemerson, javed.absar, eraman, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D34622
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307772 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker/IRMover.cpp')
-rw-r--r-- | lib/Linker/IRMover.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index defad190498..f486e525b5e 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -1256,6 +1256,18 @@ Error IRLinker::linkModuleFlagsMetadata() { return Error::success(); } +/// Return InlineAsm adjusted with target-specific directives if required. +/// For ARM and Thumb, we have to add directives to select the appropriate ISA +/// to support mixing module-level inline assembly from ARM and Thumb modules. +static std::string adjustInlineAsm(const std::string &InlineAsm, + const Triple &Triple) { + if (Triple.getArch() == Triple::thumb || Triple.getArch() == Triple::thumbeb) + return ".text\n.balign 2\n.thumb\n" + InlineAsm; + if (Triple.getArch() == Triple::arm || Triple.getArch() == Triple::armeb) + return ".text\n.balign 4\n.arm\n" + InlineAsm; + return InlineAsm; +} + Error IRLinker::run() { // Ensure metadata materialized before value mapping. if (SrcM->getMaterializer()) @@ -1293,11 +1305,13 @@ Error IRLinker::run() { // Append the module inline asm string. if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) { + std::string SrcModuleInlineAsm = adjustInlineAsm(SrcM->getModuleInlineAsm(), + SrcTriple); if (DstM.getModuleInlineAsm().empty()) - DstM.setModuleInlineAsm(SrcM->getModuleInlineAsm()); + DstM.setModuleInlineAsm(SrcModuleInlineAsm); else DstM.setModuleInlineAsm(DstM.getModuleInlineAsm() + "\n" + - SrcM->getModuleInlineAsm()); + SrcModuleInlineAsm); } // Loop over all of the linked values to compute type mappings. |