Setting up a cross-compiler for cortex-m3

Hi there,

I'm trying to switch from GCC to llvm (clang++) for cross-compiling
a firmware of mine for a stm32 (ARM cortex-m3).

After looking in the documentation and a bit of googling here is what
I did (in case someone else in the future is having the same problem)

cd llvm
git clone http://llvm.org/git/llvm.git

cd llvm/tools
git clone http://llvm.org/git/clang.git

cd llvm/projects
git clone http://llvm.org/git/compiler-rt.git

cd ../llvm-build/
../llvm/configure --prefix=$(HOME)/bin/llvm
--exec-prefix=$(HOME)/bin/llvm --enable-targets=x86_64,arm,cpp
--enable-optimized

make
make install

It seems everything compiled smoothly, but I can't figure out if there
is any options that list all available targets.
The following only display my host platform as target.

clang -v
clang version 3.2 (http://llvm.org/git/clang.git
88237bf587581026dcfc8386abf055cb201aa487)
(http://llvm.org/git/llvm.git
18a1b616ea123548b61a037c4f4fea4133aac1b5)
Target: x86_64-unknown-linux-gnu
Thread model: posix

After some more bit of searching I managed to build for cortex-a with
clang -march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf
-integrated-as testReference.cpp -c

but I still haven't figure out how to build for cortex-m3

clang -march=armv7-m -mfloat-abi=soft <something missing?> testReference.cpp -c

If anyone can point me to some reading or shine some light on this
one, I'd really appreciate it.

Thanks,
Salvatore

Hi there,

I'm trying to switch from GCC to llvm (clang++) for cross-compiling
a firmware of mine for a stm32 (ARM cortex-m3).

After looking in the documentation and a bit of googling here is what
I did (in case someone else in the future is having the same problem)

cd llvm
git clone http://llvm.org/git/llvm.git

cd llvm/tools
git clone http://llvm.org/git/clang.git

cd llvm/projects
git clone http://llvm.org/git/compiler-rt.git

cd ../llvm-build/
../llvm/configure --prefix=$(HOME)/bin/llvm
--exec-prefix=$(HOME)/bin/llvm --enable-targets=x86_64,arm,cpp
--enable-optimized

make
make install

It seems everything compiled smoothly, but I can't figure out if there
is any options that list all available targets.
The following only display my host platform as target.

clang -v
clang version 3.2 (http://llvm.org/git/clang.git
88237bf587581026dcfc8386abf055cb201aa487)
(http://llvm.org/git/llvm.git
18a1b616ea123548b61a037c4f4fea4133aac1b5)
Target: x86_64-unknown-linux-gnu
Thread model: posix

After some more bit of searching I managed to build for cortex-a with
clang -march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf
-integrated-as testReference.cpp -c

but I still haven't figure out how to build for cortex-m3

clang -march=armv7-m -mfloat-abi=soft <something missing?> testReference.cpp -c

If anyone can point me to some reading or shine some light on this
one, I'd really appreciate it.

Thanks,
Salvatore

-march should have done the trick.

You can also try -mcpu=cortex-m3,

or try -ccc-host-triple armv7m-none-gnueabi (or -eabi),

and possibly -ccc-gcc-name code sourcery's gcc,

or possibly --sysroot=code sourcery/libc

but I still haven't figure out how to build for cortex-m3

clang -march=armv7-m -mfloat-abi=soft <something missing?> testReference.cpp -c

-march should have done the trick.

You can also try -mcpu=cortex-m3,

or try -ccc-host-triple armv7m-none-gnueabi (or -eabi),

I've tried with all of the following

$ clang -march=armv7-m -mfloat-abi=soft -triple thumb2-unknown-unknown
-integrated-as testReference.cpp -c
clang: warning: argument unused during compilation: '-mfloat-abi=soft'
clang: warning: argument unused during compilation: '-triple
thumb2-unknown-unknown'
error: unknown target CPU 'armv7-m'

$ clang -march=armv7-m -mfloat-abi=soft -mcpu=cortex-m3 testReference.cpp -c
clang: warning: argument unused during compilation: '-mfloat-abi=soft'
clang: warning: argument unused during compilation: '-mcpu=cortex-m3'
error: unknown target CPU 'armv7-m'

$ clang -mcpu=cortex-m3 testReference.cpp -c
clang: warning: argument unused during compilation: '-mcpu=cortex-m3'

$ clang -march=armv7-m -mfloat-abi=soft -ccc-host-triple
armv7m-none-gnueabi testReference.cpp -c
fatal error: error in backend: CPU: 'cortex-m3' does not support ARM
mode execution!

and possibly -ccc-gcc-name code sourcery's gcc,

or possibly --sysroot=code sourcery/libc

I guess those would be used for the linking part?

Anyway thanks for your rapid response.

S.

Ah, yes! Try:

$ clang -ccc-host-triple thumbv7m-none-gnueabi testReference.cpp -c

Cross compilation in Clang is very broken at the moment. There was
some effort to fix this last year, but I guess it lost momentum...

Almost there I'd say...

$ clang++ -ccc-host-triple thumbv7m-none-gnueabi testReference.cpp -c -v
clang version 3.2 (http://llvm.org/git/clang.git
88237bf587581026dcfc8386abf055cb201aa487)
(http://llvm.org/git/llvm.git
18a1b616ea123548b61a037c4f4fea4133aac1b5)
Target: thumbv7m-none--gnueabi
<------------------------------------------- Seems OK!
Thread model: posix
"/home/emitrax/bin/llvm/bin/clang" -cc1 -triple armv4t-none--gnueabi
-S -disable-free -main-file-name testReference.cpp -mrelocation-model
static -mdisable-fp-elim -fmath-errno -mconstructor-aliases
-target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft
-target-feature +soft-float-abi -target-linker-version
2.21.53.20110810 -momit-leaf-frame-pointer -v -coverage-file
/tmp/testReference-Shww7Y.s -resource-dir
/home/emitrax/bin/llvm/bin/../lib/clang/3.2 -fmodule-cache-path
/var/tmp/clang-module-cache -fdeprecated-macro
-fno-dwarf-directory-asm -fdebug-compilation-dir
/home/emitrax/programming -ferror-limit 19 -fmessage-length 106
-mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/testReference-Shww7Y.s -x c++ testReference.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target
x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/home/emitrax/bin/llvm/bin/../lib/clang/3.2/include
/usr/include
End of search list.
"/usr/bin/g++" -v -c -o testReference.o -x assembler
/tmp/testReference-Shww7Y.s
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.1-9ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'testReference.o' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
as --64 -o testReference.o /tmp/testReference-Shww7Y.s
/tmp/testReference-Shww7Y.s: Assembler messages:
/tmp/testReference-Shww7Y.s:1: Error: unknown pseudo-op: `.syntax'
/tmp/testReference-Shww7Y.s:2: Error: unknown pseudo-op: `.eabi_attribute'
... and on for a bit.

The source code of course compiles fine with g++ 4.6.1 in case you are
wondering.

I'm not sure how to interpret the above output, but I don't understand
why if say -triple armv4t-none--gnueabi .

Thanks a lot for your time.

Regards,
Salvatore

Ok, we're getting there... :wink:

I think these errors are due to Clang not finding the
libraries/includes/etc for the target you're building.

If you have CodeSourcery's GCC, use that (via --sysroot or
-ccc-gcc-name I said earlier), it's by far the easiest way.

I'm not sure compiler-rt is ready for prime time (someone else might
chip in), but that might be an alternative, though I have no idea how
to use it.

"/usr/bin/g++" -v -c -o testReference.o -x assembler
/tmp/testReference-Shww7Y.s
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.1-9ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'testReference.o' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
as --64 -o testReference.o /tmp/testReference-Shww7Y.s
/tmp/testReference-Shww7Y.s: Assembler messages:
/tmp/testReference-Shww7Y.s:1: Error: unknown pseudo-op: `.syntax'
/tmp/testReference-Shww7Y.s:2: Error: unknown pseudo-op: `.eabi_attribute'
... and on for a bit.

  Do you tell clang to use the right binutils for ARM not x86 host?

Regards,
chenwj

I'm not sure how to interpret the above output, but I don't understand
why if say -triple armv4t-none--gnueabi .

Ok, we're getting there... :wink:

Glad you are confident. :slight_smile:

I think these errors are due to Clang not finding the
libraries/includes/etc for the target you're building.

If you have CodeSourcery's GCC, use that (via --sysroot or
-ccc-gcc-name I said earlier), it's by far the easiest way.

emitrax@xartimequad:~/programming$ which arm-none-linux-gnueabi-g++
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-g++
emitrax@xartimequad:~/programming$ find
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/ -name libc
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc

$ clang++ -ccc-host-triple thumbv7m-none-gnueabi testReference.cpp -c
--sysroot=/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
-v
clang version 3.2 (http://llvm.org/git/clang.git
88237bf587581026dcfc8386abf055cb201aa487)
(http://llvm.org/git/llvm.git
18a1b616ea123548b61a037c4f4fea4133aac1b5)
Target: thumbv7m-none--gnueabi
Thread model: posix
"/home/emitrax/bin/llvm/bin/clang" -cc1 -triple armv4t-none--gnueabi
-S -disable-free -main-file-name testReference.cpp -mrelocation-model
static -mdisable-fp-elim -fmath-errno -mconstructor-aliases
-target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft
-target-feature +soft-float-abi -target-linker-version
2.21.53.20110810 -momit-leaf-frame-pointer -v -coverage-file
/tmp/testReference-IcBmdF.s -resource-dir
/home/emitrax/bin/llvm/bin/../lib/clang/3.2 -isysroot
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
-fmodule-cache-path /var/tmp/clang-module-cache -fdeprecated-macro
-fno-dwarf-directory-asm -fdebug-compilation-dir
/home/emitrax/programming -ferror-limit 19 -fmessage-length 106
-mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/testReference-IcBmdF.s -x c++ testReference.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target
x86_64-unknown-linux-gnu
ignoring nonexistent directory
"/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc//usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/home/emitrax/bin/llvm/bin/../lib/clang/3.2/include
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc//usr/include
End of search list.
"/usr/bin/g++"
--sysroot=/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
-v -c -o testReference.o -x assembler /tmp/testReference-IcBmdF.s
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.1-9ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'testReference.o' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
as --64 -o testReference.o /tmp/testReference-IcBmdF.s
/tmp/testReference-IcBmdF.s: Assembler messages:
/tmp/testReference-IcBmdF.s:1: Error: unknown pseudo-op: `.syntax'
and so on..

I'm not sure compiler-rt is ready for prime time (someone else might
chip in), but that might be an alternative, though I have no idea how
to use it.

I've also tried with a simpler source file without include statements
but I'm still getting errors.

$ clang++ -ccc-host-triple thumbv7m-none-gnueabi noInclude.cpp -c
--sysroot=/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
-v
clang version 3.2 (http://llvm.org/git/clang.git
88237bf587581026dcfc8386abf055cb201aa487)
(http://llvm.org/git/llvm.git
18a1b616ea123548b61a037c4f4fea4133aac1b5)
Target: thumbv7m-none--gnueabi
Thread model: posix
"/home/emitrax/bin/llvm/bin/clang" -cc1 -triple armv4t-none--gnueabi
-S -disable-free -main-file-name noInclude.cpp -mrelocation-model
static -mdisable-fp-elim -fmath-errno -mconstructor-aliases
-target-abi aapcs-linux -target-cpu arm7tdmi -mfloat-abi soft
-target-feature +soft-float-abi -target-linker-version
2.21.53.20110810 -momit-leaf-frame-pointer -v -coverage-file
/tmp/noInclude-YFkpA6.s -resource-dir
/home/emitrax/bin/llvm/bin/../lib/clang/3.2 -isysroot
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
-fmodule-cache-path /var/tmp/clang-module-cache -fdeprecated-macro
-fno-dwarf-directory-asm -fdebug-compilation-dir
/home/emitrax/programming -ferror-limit 19 -fmessage-length 106
-mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o
/tmp/noInclude-YFkpA6.s -x c++ noInclude.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target
x86_64-unknown-linux-gnu
ignoring nonexistent directory
"/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc//usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/home/emitrax/bin/llvm/bin/../lib/clang/3.2/include
/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc//usr/include
End of search list.
"/usr/bin/g++"
--sysroot=/home/emitrax/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
-v -c -o noInclude.o -x assembler /tmp/noInclude-YFkpA6.s
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.1-9ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin
--enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'noInclude.o' '-shared-libgcc'
'-mtune=generic' '-march=x86-64' <------------------------------ Is
this correct?
as --64 -o noInclude.o /tmp/noInclude-YFkpA6.s
/tmp/noInclude-YFkpA6.s: Assembler messages:
/tmp/noInclude-YFkpA6.s:1: Error: unknown pseudo-op: `.syntax'
/tmp/noInclude-YFkpA6.s:2: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/noInclude-YFkpA6.s:3: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/noInclude-YFkpA6.s:4: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/noInclude-YFkpA6.s:5: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/noInclude-YFkpA6.s:6: Error: unknown pseudo-op: `.eabi_attribute'
/tmp/noInclude-YFkpA6.s:13: Error: too many memory references for `sub'
/tmp/noInclude-YFkpA6.s:14: Error: expecting operand after ','; got nothing
/tmp/noInclude-YFkpA6.s:15: Error: invalid char '[' beginning operand 2 `[sp'
/tmp/noInclude-YFkpA6.s:16: Error: invalid char '[' beginning operand 2 `[sp'
/tmp/noInclude-YFkpA6.s:17: Error: invalid char '[' beginning operand 2 `[sp'
/tmp/noInclude-YFkpA6.s:18: Error: invalid char '[' beginning operand 2 `[sp'
/tmp/noInclude-YFkpA6.s:19: Error: too many memory references for `mov'
/tmp/noInclude-YFkpA6.s:20: Error: invalid char '[' beginning operand 2 `[sp]'
/tmp/noInclude-YFkpA6.s:21: Error: too many memory references for `add'
/tmp/noInclude-YFkpA6.s:22: Error: no such instruction: `bx lr'
clang: error: assembler (via gcc) command failed with exit code 1 (use
-v to see invocation)

$ cat noInclude.cpp
int main(int argc, char** argv)
{
  return 0;
}

Any idea?

Thanks,
S.

Not really. I'm not even sure how to do that.

I thought that would have done automagically by llvm.

Any readings to point me to?

S.

Not really. I'm not even sure how to do that.

I thought that would have done automagically by llvm.

Any readings to point me to?

  Yes, I think this had been discussed before,
  http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-June/050759.html

  Good Luck!

Regards,
chenwj

Try -ccc-gcc-name arm-none-linux-gnueabi-g++ -ccc-host-triple
thumbv7m-none-linux-gnueabi

Sometimes it's better than sysroot, as it finds it all by itself.

And the winner is..

clang++ -ccc-gcc-name arm-none-linux-gnueabi-g++ -ccc-host-triple
thumbv7m-none-gnueabi testReference.cpp -c

It seems like it worked.

$ arm-none-linux-gnueabi-objdump -D --section=.text testReference.o

testReference.o: file format elf32-littlearm

Disassembly of section .text:

00000000 <main>:
   0: e92d4800 push {fp, lr}
   4: e1a0b00d mov fp, sp
   8: e24dd030 sub sp, sp, #48 ; 0x30
...

I'm not 100% sure if that's the correct ISA, because I haven't run the
code, but it seems ok.

I of course own you a beer :slight_smile: Thank you very much.

Now, a grep of clang++ --ccc-gcc-name didn't give any result so I'm
still wondering what
exactly I am doing here.

Which part of gcc I'm using with that option?
Just the libc, libgcc et all?

Regards,
S.

I of course own you a beer :slight_smile: Thank you very much.

I will remind you of that, next year, on EuroLLVM 2013. :smiley:

Which part of gcc I'm using with that option?
Just the libc, libgcc et all?

AFAIK, it uses the name to find the tool chain, and guess all other
binaries from it. So it calls arm-linux-gnueabi-ld,
arm-linux-gnueabi-as etc. instead of ld, as etc., which is what you
were missing.

I of course own you a beer :slight_smile: Thank you very much.

I will remind you of that, next year, on EuroLLVM 2013. :smiley:

Any chance that'll be in Florence like the EuroPyhon? :wink:

Which part of gcc I'm using with that option?
Just the libc, libgcc et all?

AFAIK, it uses the name to find the tool chain, and guess all other
binaries from it. So it calls arm-linux-gnueabi-ld,
arm-linux-gnueabi-as etc. instead of ld, as etc., which is what you
were missing.

I thought llvm also provided its own binutils.

Anyway, thanks again. Now I've officially stepped
into the llvm world.

Regards,
Salvatore

Unfortunately, I have to resurrect this thread.

I had the time to test the code, and it is using the wrong ISA.
I can't understand why, but it uses armv5te instead of thumb2.

$ clang++ -ccc-gcc-name arm-none-linux-gnueabi-g++ -ccc-host-triple
thumbv7m-none-gnueabi testReference.cpp -c
$ arm-none-linux-gnueabi-readelf -A testReference.o
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "5TE"
  Tag_CPU_arch: v5TE
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_DIV_use: Not allowed

I realized this only when I moved to compile my firmware and
got the following

/tmp/startup-EFUAJp.s: Assembler messages:
/tmp/startup-EFUAJp.s:84: Error: width suffixes are invalid in ARM
mode -- `ldr.w sp,[r0]'

Using the -v options produce the following

gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-57)
COLLECT_GCC_OPTIONS='-ffunction-sections' '-fno-common'
'-fno-exceptions' '-fno-rtti' '-v' '-nostdlib' '-nodefaultlibs'
'-Wall' '-stdlib=libc++' '-I' '/home/emitrax/bin/llvm/lib/c++/v1'
'-std=c++11' '-I'
'/home/emitrax/programming/adok/build/include/private' '-I'
'/home/emitrax/programming/adok/include/private' '-c' '-o'
'source/porting/arch/arm/cortex-m3/stack.cpp.o' '-shared-libgcc'
'-march=armv5te' '-mtls-dialect=gnu' '-D'
'__CS_SOURCERYGXX_MAJ__=2012' '-D' '__CS_SOURCERYGXX_MIN__=3' '-D'
'__CS_SOURCERYGXX_REV__=57'

Any suggestions?

Regards,
S.

Any suggestions?

Try to specify CPU explicitly.

Already did.

clang++ -ccc-gcc-name arm-none-linux-gnueabi-g++ -ccc-host-triple
thumbv7m-none-gnueabi testReference.cpp -c -mcpu=cortex-m3
fatal error: error in backend: CPU: 'cortex-m3' does not support ARM
mode execution!

S.

clang++ -ccc-gcc-name arm-none-linux-gnueabi-g++ -ccc-host-triple
thumbv7m-none-gnueabi testReference.cpp -c -mcpu=cortex-m3
fatal error: error in backend: CPU: 'cortex-m3' does not support ARM
mode execution!

Ok, and what's about -mthumb then?

$ clang++ -ccc-gcc-name arm-none-linux-gnueabi-g++ -ccc-host-triple
thumbv7m-none-gnueabi testReference.cpp -c -mcpu=cortex-m3 -mthumb
$ arm-none-linux-gnueabi-readelf -A testReference.o
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "Cortex-M3"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Microcontroller
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_DIV_use: Not allowed

That did the trick. Although it's a lot of options.

Thanks a lot!

S.