llvm-6502/lib/MC
David Peixotto 1edc33b924 ARM integrated assembler generates incorrect nop opcode
This patch fixes a bug in the assembler that was causing bad code to
be emitted.  When switching modes in an assembly file (e.g. arm to
thumb mode) we would always emit the opcode from the original mode.

Consider this small example:

$ cat align.s
.code 16
foo:
  add r0, r0
.align 3
  add r0, r0

$ llvm-mc -triple armv7-none-linux align.s -filetype=obj -o t.o
$ llvm-objdump -triple thumbv7 -d t.o
Disassembly of section .text:
foo:
       0:       00 44         add     r0, r0
       2:       00 f0 20 e3   blx #4195904
       6:       00 00         movs    r0, r0
       8:       00 44         add     r0, r0

This shows that we have actually emitted an arm nop (e320f000)
instead of a thumb nop. Unfortunately, this encodes to a thumb
branch which causes bad things to happen when compiling assembly
code with align directives.

The fix is to notify the ARMAsmBackend when we switch mode. The
MCMachOStreamer was already doing this correctly. This patch makes
the same change for the MCElfStreamer.

There is still a bug in the way nops are emitted for alignment
because the MCAlignment fragment does not store the correct mode.
The ARMAsmBackend will emit nops for the last mode it knew about. In
the example above, we still generate an arm nop if we add a `.code
32` to the end of the file.

PR18019


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195677 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-25 19:11:13 +00:00
..
MCDisassembler
MCParser Support multiple COFF sections with the same name but different COMDAT. 2013-11-19 19:52:52 +00:00
CMakeLists.txt
ELFObjectWriter.cpp Move the STT_FILE symbols out of the normal symbol table processing for 2013-10-29 01:06:17 +00:00
LLVMBuild.txt
MachObjectWriter.cpp
Makefile
MCAsmBackend.cpp
MCAsmInfo.cpp Remove AllowQuotesInName and friends from MCAsmInfo. 2013-11-13 14:01:59 +00:00
MCAsmInfoCOFF.cpp Remove AllowQuotesInName and friends from MCAsmInfo. 2013-11-13 14:01:59 +00:00
MCAsmInfoDarwin.cpp Remove AllowQuotesInName and friends from MCAsmInfo. 2013-11-13 14:01:59 +00:00
MCAsmInfoELF.cpp
MCAsmStreamer.cpp MCStreamer: Reimplement the virtual EmitRawText as a protected member, EmitRawTextImpl, to avoid string literal ambiguities 2013-10-24 22:43:10 +00:00
MCAssembler.cpp
MCAtom.cpp [weak vtables] Remove a bunch of weak vtables 2013-11-19 00:57:56 +00:00
MCCodeEmitter.cpp
MCCodeGenInfo.cpp
MCContext.cpp Support multiple COFF sections with the same name but different COMDAT. 2013-11-19 19:52:52 +00:00
MCDisassembler.cpp
MCDwarf.cpp
MCELF.cpp Move the STT_FILE symbols out of the normal symbol table processing for 2013-10-29 01:06:17 +00:00
MCELFObjectTargetWriter.cpp
MCELFStreamer.cpp ARM integrated assembler generates incorrect nop opcode 2013-11-25 19:11:13 +00:00
MCExpr.cpp
MCExternalSymbolizer.cpp Add to the disassembler C API output reference types for 2013-11-01 00:00:07 +00:00
MCFunction.cpp
MCInst.cpp
MCInstPrinter.cpp
MCInstrAnalysis.cpp
MCLabel.cpp
MCMachObjectTargetWriter.cpp
MCMachOStreamer.cpp
MCModule.cpp
MCModuleYAML.cpp
MCNullStreamer.cpp
MCObjectDisassembler.cpp
MCObjectFileInfo.cpp Add a method to get the object-file appropriate stack map section. 2013-11-08 22:14:49 +00:00
MCObjectStreamer.cpp Emit DWARF line entries for all data in the instruction stream. 2013-10-20 02:16:18 +00:00
MCObjectSymbolizer.cpp
MCObjectWriter.cpp
MCPureStreamer.cpp
MCRegisterInfo.cpp
MCRelocationInfo.cpp
MCSection.cpp
MCSectionCOFF.cpp
MCSectionELF.cpp Remove AllowQuotesInName and friends from MCAsmInfo. 2013-11-13 14:01:59 +00:00
MCSectionMachO.cpp
MCStreamer.cpp [weak vtables] Remove a bunch of weak vtables 2013-11-19 00:57:56 +00:00
MCSubtargetInfo.cpp
MCSymbol.cpp Don't mangle \n and " 2013-11-14 06:05:49 +00:00
MCSymbolizer.cpp
MCValue.cpp
MCWin64EH.cpp
SubtargetFeature.cpp
WinCOFFObjectWriter.cpp [weak vtables] Remove a bunch of weak vtables 2013-11-19 00:57:56 +00:00
WinCOFFStreamer.cpp Fix .comm and .lcomm on COFF. 2013-11-25 16:06:04 +00:00