[llvm-dev] ARM baremetal linking (original) (raw)

Peter Smith via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 8 02:23:07 PDT 2018


On Fri, 5 Oct 2018 at 19:52, Goran Mekić via llvm-dev <llvm-dev at lists.llvm.org> wrote:

On Thu, Oct 04, 2018 at 10:25:41AM +0200, Goran Mekić via llvm-dev wrote: _> arm-none-eabi-ld --entry=start -T/usr/home/meka/repos/nuttx/nuttx/configs/nucleo-f4x1re/scripts/f401re.ld -L"/usr/home/meka/repos/nuttx/nuttx/staging" -L"/usr/home/meka/repos/nuttx/nuttx/arch/arm/src/board" -o "/usr/home/meka/repos/nuttx/nuttx/nuttx" --start-group -lsched -ldrivers -lconfigs -lc -lmm -larch -lxx -lapps -lfs -lbinfmt -lxx -lboard "/usr/lib/libgcc.a" --end-group I lost few days staring at the debugger only to realize that "/usr/lib/libgcc.a" is my system lib. If I'm right, it comes from compiler-rt, and what I would need is compiler-rt for baremetal ARM. If I'm right, as CFLAGS for crosscompile are -target arm-none-eabi -march=armv7-m -mcpu=cortex-m4 that's the exact chip I would need to build compiler-rt for. How could this be done? Also, if anyone is working on compiling for armv7-m without using GNU tools, I'm more than interested in joining forces (hopefully someone has success). The reason I think this is true are these commands: clang -print-libgcc-file-name # using the system lib /usr/lib/libgcc.a clang -target arm-none-eabi -print-libgcc-file-name # using the baremetal lib /usr/lib/clang/6.0.1/lib/libclangrt.builtins-arm.a As that's where "/usr/lib/libgcc.a" in original command comes from, I really hope I figured this right, but do correct me if I'm wrong. Regards, meka PS. I tried to do the same last year, but I felt I need to learn a lot before dealing with LLVM-only baremetal development, and I did. If you feel I need some more info/literature, please do point it out, I'm more than willing to learn.

Hello again,

I've written

It is possible to build compiler-rt for v6-m and v7-m although it can be a bit of a struggle to set up. There are a couple of ways that I know of. The first is to use the BaremetalARM.cmake cache file in tools/clang/ and the second is to do a standalone build of compiler-rt.

There isn't a lot of documentation about using the BaremetalARM.cmake cache file. The best that I know of is the commit message that I've quoted below: Don't defer to the GCC driver for linking arm-baremetal

Also comes with a cmake cache for building the runtime bits:

$ cmake
-DBAREMETAL_ARMV6M_SYSROOT=/path/to/sysroot
-DBAREMETAL_ARMV7M_SYSROOT=/path/to/sysroot
-DBAREMETAL_ARMV7EM_SYSROOT=/path/to/sysroot
-C /path/to/clang/cmake/caches/BaremetalARM.cmake
/path/to/llvm

https://reviews.llvm.org/D33259

I got this to work a year or so ago. The main missing bit of information was that this required compiler-rt to be in the runtimes directory and not in the projects directory as suggested by https://llvm.org/docs/GettingStarted.html it also uses hardware floating point and the hard-floating point float-abi for v7m which may not be what you want depending on whether your cortex-m4 has floating point support.

For building compiler-rt standalone for Arm there is the docs page https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html . That will be a good place to start. The hardest part is usually fighting your way past the CMAKE try compile step. I strongly recommend using a version of cmake >= 3.6 so that you can use the -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY .

Hope that this gets you a little bit further.

Peter


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