ARM/Thumb/Data mapping symbols not being generated
| Bugzilla Link | 9582 |
| Resolution | FIXED |
| Resolved on | Apr 22, 2013 14:50 |
| Version | trunk |
| OS | Linux |
| CC | @asl |
Extended Description
ARM mapping symbols (AAELF 4.6.5) are nor being generated in ELF output, so disassemblers think that the section is code when it actually is data or vice versa. Worse than that, linker optimizations could mistakenly put code in data sections.
Example: LLVM is generating the following code:
main 0x000081f4: e92d4070 p@-. PUSH {r4-r6,lr} 0x000081f8: eb000010 .... BL _Z2g_v ; 0x8240 0x000081fc: e59f402c ,@.. LDR r4,[pc,#44] ; [0x8230] = 0xad99 0x00008200: e59f6030 0`.. LDR r6,[pc,#48] ; [0x8238] = 0xad95 0x00008204: e59f5028 (P.. LDR r5,[pc,#40] ; [0x8234] = 0xad92 (...) 0x0000822c: e12fff1e ../. BX lr 0x00008230: 0000ad99 .... MULEQ r0,r9,sp ; ? SBZ = 0xa000 0x00008234: 0000ad92 .... MULEQ r0,r2,sp ; ? SBZ = 0xa000 0x00008238: 0000ad95 .... MULEQ r0,r5,sp ; ? SBZ = 0xa000 0x0000823c: 0000ad70 p... ANDEQ r10,r0,r0,ROR sp
Everything after the BX is obviously data, so the mapping symbol $d should have been emitted after BX. The disassembler is clearly confused.
A mapping symbol $a, $t and $t has to be emitted before every ARM, Thumb and Data block, respectively. Basically, the logic is simple: emit the correct symbol whenever the next word has a different type of the previous.
See AAELF section 4.6.5 for more details at:
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044c/IHI0044C_aaelf.pdf
Fixed in r169609
Some discussions on the list worthy to mention to whomever is going to implement this feature:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-October/054278.html
Just to clarify: these symbols should not appear in a textual assembler file. They are not input (directives) to the assembler, they are added to the ELF by the assembler while it is building the code section, from the information it already has about whether ranges of bytes are ARM, Thumb or data.
No intention to fix in the short term, unassigning for someone else to grab if necessary.
Reassigning to ARM folks
Jim Grosbach:
"In particular, have a look at ARMAsmPrinter::EmitInstruction(). There's a big switch statement there for instructions that need any sorts of special handling. From the sounds of things, you'll be interested in the ARM::*_JT (jump table branch) instructions and ARM::CONSTPOOL_ENTRY.
These mapping symbols sound very similar to special-purpose assembler directives. Off the cuff, it makes sense to me to do something similar to the MCStreamer::EmitAssemblerFlag() routine."