Comment 2 for bug 1782834

Revision history for this message
Thomas Thorsen (thomasthorsendk) wrote :

The ldr is not malformed. The thumb blx instruction is for indirect branches (branch to address contained in register). Everything the compiler is doing is correct based on the input you are giving it. You are effectively telling the compiler that Main is the address of a function pointer sized variable and you want it to call a function whose address is contained in that variable. It does that by first loading the address of the variable from a literal pool. Since Main is really a thumb function the value in the literal pool is an odd value. This odd value is loaded into r3. The compiler then needs to get the contents at that address (remember, you are asking the compiler to call the function which is pointed at by the variable, you are not asking it to call Main, because Main is not a function it is a variable with a pointer to a function) and does so with the ldr. This causes an unaligned access because the address being accessed is odd. This is not the compilers fault, and in fact the compiler doesn't know it will happen, because it isn't until the linker has run that the actual address of Main is resolved. Even if the processor supported unaligned accesses, it would still fail, because it would go on to load the actual bytes of code at the start of Main into r3 and then branch to it as if it represented an actual address of a function that has been put into that variable by another part of the program. In summary, the compiler is doing exactly what you are telling it to do, and there is no way it can tell that it is wrong.