[cfe-users] PIC in ARM assembly

Jeff Schenck Jeff.Schenck at dts.com
Mon Feb 24 12:10:34 PST 2014


Hello,

I'm trying to create position-independent ARM assembly code.  For armcc I do the following:

        IMPORT  foo

L_PIC   ldr     r0, L_FOO
        add     r0, pc, r0
...
L_FOO   DCD     foo - (L_PIC + 8)

which for gcc looks similar:

        .extern foo
L_PIC:  ldr     r0, L_FOO
        add     r0, pc, r0
...
L_FOO:  .word   foo - (L_PIC + 8)

This works fine when using the GNU assembler.  But when using Clang I get the following weird error: "symbol '_foo' can not be undefined in a subtraction expression".  Looking at assembly code produced from C by the Clang compiler, it does things differently, using the directive ".indirect_symbol", which gcc and armcc don't support:

        movw    r0, :lower16:(L_FOO-(L_PIC+8))
        movt    r0, :upper16:(L_FOO-(L_PIC+8))
L_PIC:  ldr     r0, [pc, r0]
...
L_FOO:  .indirect_symbol    _foo

This would be fine except that I want to have one code base that can be built on multiple architectures with different tools.  In the short term, I'm looking for an approach that will work with both gcc and Clang.  In the longer term, it would be nice if this could be "fixed" in Clang.  (I put "fixed" in quotes since I don't know if Clang has compatibility with armcc/gcc as a goal.)  Thanks in advance for any suggestions.

Thanks,
Jeff Schenck


________________________________

Notice:
This message and any included attachments are intended only for the use of the addressee, and may contain information that is privileged or confidential. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please destroy the original message and any copies or printouts hereof.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20140224/43e9c5f0/attachment.html>


More information about the cfe-users mailing list