[llvm-dev] Cross-compiling for ARM Cortex-M3 on x86

Christophe Lyon via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 12 08:42:15 PDT 2018


On 12 March 2018 at 16:35, Son Tuan VU via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Thanks for your prompt reply.
>
> I didn't build the libc at all, I downloaded a pre-built version of the
> whole toolchain from
> https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads, so I
> guess it is an official version provided by ARM and should work? This
> version targets ARM Cortex-M and Cortex-R family of processors...
>

I believe these GCC toolchains are multilib-enabled (that is, the libs are built
multiple times, with different options, including thumb/arm).

Since you already use the gcc driver to link your program,
adding -mcpu=cortex-m3 -mthumb to your link line should do the trick.

To see which multilibs are available in your GCC toolchain, use:
arm-none-eabi-gcc --print-multi-lib

HTH

Christophe


> Son Tuan Vu
>
> On Mon, Mar 12, 2018 at 4:15 PM, Tim Northover <t.p.northover at gmail.com>
> wrote:
>>
>> Hi,
>>
>> On 12 March 2018 at 15:06, Son Tuan VU via llvm-dev
>> <llvm-dev at lists.llvm.org> wrote:
>> > But libc code is in ARM mode:
>>
>> That's very bad, because Cortex-M doesn't support ARM mode. I think
>> your libc is broken.
>>
>> > As you can see, the call to srand is just a bl (Branch with Link), not a
>> > blx
>> > (Branch with Link and Exchange instruction set), so I think something is
>> > going wrong here.
>>
>> Yes, Cortex-M has no blx instruction.
>>
>> > Can anyone kindly give me some pointers on how to debug this? Or at
>> > least
>> > tell me whether this is a bug?
>>
>> You don't mention how you build libc, but that's what you need to fix.
>>
>> > I am a bit lost now, I've tried to look up
>> > for more information on this but cannot find out why Clang doesn't
>> > generate
>> > Thumb code for libc functions.
>>
>> It'll be part of your libc's build system (Makefile?). Clang should
>> simply refuse to produce ARM mode code if it knows it's targeting
>> Cortex-M, so my guess is no -mcpu option is being specified. There
>> might be subtle differences in how GCC has been compiled that means
>> your version defaults to Thumb mode anyway, but Clang doesn't.
>>
>> Cheers.
>>
>> Tim.
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>


More information about the llvm-dev mailing list