MC Assembler generates ARM NOP instructions instead of Thumb NOP instructions when aligning
| Bugzilla Link | 10632 |
| Resolution | FIXED |
| Resolved on | Oct 20, 2011 02:50 |
| Version | trunk |
| OS | All |
| CC | @efriedma-quic,@jmolloy |
Extended Description
The following assembler file gets mis-assembled:
$ cat ArmNopsInThumbCode.s .section __TEXT //,__text,regular,pure_instructions .text .code 16 f: $t: add r0, r0, #1 .align 3 add r0, r0, #2 bx lr
When using the following command line: $ build/Debug+Asserts/bin/llvm-mc -arch=thumb -mcpu=arm926ej-s ArmNopsInThumbCode.s -filetype=obj -o ArmNopsInThumbCode.o
Disassembling the generated ELF file with GNU objdump shows that ARM NOP instructions were generated instead of Thumb NOP instructions:
$ arm-none-eabi-objdump -d ArmNopsInThumbCode.o
ArmNopsInThumbCode.o: file format elf32-littlearm
Disassembly of section .text:
00000000
The decoded instruction at offsets 2-6 should be 16-bit Thumb NOP instructions. However, when looking at the encoding "0000 0e1a 0000", it seems that the ARM pseudo-NOP instruction (i.e. MOV r0,r0) was encoded.
Was fixed in r137723.
I think that the root cause of the bug originates in this area of the code:
Index: lib/MC/MCAssembler.cpp
--- lib/MC/MCAssembler.cpp (revision 136769) +++ lib/MC/MCAssembler.cpp (working copy) @@ -412,6 +412,12 @@ // bytes left to fill use the the Value and ValueSize to fill the rest. // If we are aligning with nops, ask that target to emit the right data. if (AF.hasEmitNops()) {
-
// FIXME: this assumes that the NOP data to be written is independent -
// of the instructions/fragments before or after it. -
// I believe that to write NOP data, the ASM writer should be set in -
// the correct state, e.g. for ARM compilation, in Thumb state so as -
// to produce Thumb NOP's when the NOP data is in the middle of a -
// Thumb function. if (!Asm.getBackend().WriteNopData(Count, OW)) report_fatal_error("unable to write nop sequence of " + Twine(Count) + " bytes");