Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -1293,11 +1293,20 @@ // Append the module inline asm string. if (!IsPerformingImport && !SrcM->getModuleInlineAsm().empty()) { + std::string SrcModuleInlineAsm = SrcM->getModuleInlineAsm(); + // Add directives to support mixing module-level inline assembly from ARM + // and Thumb modules. + if (SrcTriple.getArch() == Triple::thumb || + SrcTriple.getArch() == Triple::thumbeb) + SrcModuleInlineAsm = ".text\n.balign 2\n.thumb\n" + SrcModuleInlineAsm; + else if (SrcTriple.getArch() == Triple::arm || + SrcTriple.getArch() == Triple::armeb) + SrcModuleInlineAsm = ".text\n.balign 4\n.arm\n" + SrcModuleInlineAsm; 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. Index: test/Linker/Inputs/thumb-module-inline-asm.ll =================================================================== --- /dev/null +++ test/Linker/Inputs/thumb-module-inline-asm.ll @@ -0,0 +1,3 @@ +target triple = "thumbv7-linux-gnueabihf" + +module asm "orn r1, r2, r2" Index: test/Linker/link-arm-and-thumb-module-inline-asm.ll =================================================================== --- /dev/null +++ test/Linker/link-arm-and-thumb-module-inline-asm.ll @@ -0,0 +1,17 @@ +; RUN: llvm-as %s -o %t1.bc +; RUN: llvm-as %p/Inputs/thumb-module-inline-asm.ll -o %t2.bc +; RUN: llvm-link %t1.bc %t2.bc -S 2> %t3.out | FileCheck %s + +target triple = "armv7-linux-gnueabihf" + +module asm "add r1, r2, r2" + +; CHECK: .text +; CHECK-NEXT: .balign 4 +; CHECK-NEXT: .arm +; CHECK-NEXT: add r1, r2, r2 +; CHECK-NEXT: module asm +; CHECK-NEXT: .text +; CHECK-NEXT: .balign 2 +; CHECK-NEXT: .thumb +; CHECK-NEXT: orn r1, r2, r2 Index: test/MC/ARM/inline-asm-switch-mode.ll =================================================================== --- /dev/null +++ test/MC/ARM/inline-asm-switch-mode.ll @@ -0,0 +1,14 @@ +; RUN: llc -mtriple=armv7-linux -filetype=asm < %s | FileCheck %s + +module asm ".thumb" +module asm ".align 1" + +define i32 @inc1() { + ret i32 10 +} + +; CHECK: .code 16 +; CHECK-next: .p2align 1 +; CHECK: .code 32 +; CHECK: .p2align 2 +; CHECK-LABEL: @inc1