On Fri, Aug 04, 2017 at 04:03:35PM -0600, Jonathan Roelofs wrote:> > > 1) Pick a directory as your sysroot > > ~/arm-sysroot > > > > > 2) Install the libc headers there (without having built it) > > What I did was mv musl-*/include ~/arm-sysroot/usr/include. > > I think you need to copy them, not move them.On a new directories and fresh untar of musl, I don't think there's a difference> > > 3) Build clang w/ baremetal cache, pointing it at the partially built > > > sysroot. > > cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C ../../code/clang/cmake/caches/BaremetalARM.cmake ../../code/clang > > Sorry, I wasn't explicit enough. You need to define all of the variables > that the cache is looking for. > > > loading initial cache file ../../code/clang/cmake/caches/BaremetalARM.cmake > > -- Found LLVM_CONFIG as /usr/local/bin/llvm-config > > -- Building with -fPIC > > -- Could NOT find Z3 (missing: Z3_LIBRARIES Z3_INCLUDE_DIR) (Required is at least version "4.5") > > -- Clang version: 4.0.1 > > CMake Error at /usr/local/llvm40/lib/cmake/llvm/LLVM-Config.cmake:203 (message): > > Library `BinaryFormat' not found in list of llvm libraries. > > Call Stack (most recent call first): > > /usr/local/llvm40/lib/cmake/llvm/AddLLVM.cmake:508 (llvm_map_components_to_libnames) > > cmake/modules/AddClang.cmake:86 (llvm_add_library) > > lib/AST/CMakeLists.txt:6 (add_clang_library) > > > > -- Configuring incomplete, errors occurred! > > See also "/usr/home/meka/repos/clang/build/clang/CMakeFiles/CMakeOutput.log". > > I think it found an installed llvm, and is trying to use that to build clang > against. First, the clang and llvm's versions have to match. Second, when I > mentioned building clang, I really meant building llvm+clang... sorry. > > $ cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C > path/to/copy/of/edited/BaremetalARM.cmake path/to/llvm > > Where your path/to/llvm has the symlinks: > > * path/to/llvm/tools/clang -> path/to/clangln -s `which clang40` path/to/llvm/tools/clang> * path/to/llvm/runtimes/compiler_rt path/to/compiler_rtln -s path/to/llvm/projects/compiler-rt path/to/llvm/runtimes/compiler_rt Is that right?> > And by "edited BaremetalARM.cmake" I mean you can strip out the other > targets in there that you don't need.So I have copied BaremetalARM.cmake into llvm/cmake/caches/BaremetalARM.cmake to be able to alter it, I've put all other repos in llvm/projects and the command is: # cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -DBAREMETAL_ARMV6M_SYSROOT=~/arm-sysroot -DBAREMETAL_ARMV7M_SYSROOT=~/arm-sysroot -C ../../code/llvm/cmake/caches/BaremetalARM.cmake ../../code/llvm Before adding all repos into llvm/projects, it complained about 'Specified distribution component 'clang' doesn't have a target' (just an example). Now I have 'Specified distribution component 'builtins-armv6m-none-eabi' doesn't have a target' as error. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170805/52db4043/attachment.sig>
Jonathan Roelofs via llvm-dev
2017-Aug-04 22:40 UTC
[llvm-dev] Cross compiling C++ program
On 8/4/17 4:29 PM, Goran Mekić wrote:> On Fri, Aug 04, 2017 at 04:03:35PM -0600, Jonathan Roelofs wrote: >>>> 1) Pick a directory as your sysroot >>> ~/arm-sysroot >>> >>>> 2) Install the libc headers there (without having built it) >>> What I did was mv musl-*/include ~/arm-sysroot/usr/include. >> I think you need to copy them, not move them. > On a new directories and fresh untar of musl, I don't think there's a differenceI was assuming you'd want to build it from the same sources later...> > >>>> 3) Build clang w/ baremetal cache, pointing it at the partially built >>>> sysroot. >>> cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C ../../code/clang/cmake/caches/BaremetalARM.cmake ../../code/clang >> Sorry, I wasn't explicit enough. You need to define all of the variables >> that the cache is looking for. >> >>> loading initial cache file ../../code/clang/cmake/caches/BaremetalARM.cmake >>> -- Found LLVM_CONFIG as /usr/local/bin/llvm-config >>> -- Building with -fPIC >>> -- Could NOT find Z3 (missing: Z3_LIBRARIES Z3_INCLUDE_DIR) (Required is at least version "4.5") >>> -- Clang version: 4.0.1 >>> CMake Error at /usr/local/llvm40/lib/cmake/llvm/LLVM-Config.cmake:203 (message): >>> Library `BinaryFormat' not found in list of llvm libraries. >>> Call Stack (most recent call first): >>> /usr/local/llvm40/lib/cmake/llvm/AddLLVM.cmake:508 (llvm_map_components_to_libnames) >>> cmake/modules/AddClang.cmake:86 (llvm_add_library) >>> lib/AST/CMakeLists.txt:6 (add_clang_library) >>> >>> -- Configuring incomplete, errors occurred! >>> See also "/usr/home/meka/repos/clang/build/clang/CMakeFiles/CMakeOutput.log". >> I think it found an installed llvm, and is trying to use that to build clang >> against. First, the clang and llvm's versions have to match. Second, when I >> mentioned building clang, I really meant building llvm+clang... sorry. >> >> $ cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C >> path/to/copy/of/edited/BaremetalARM.cmake path/to/llvm >> >> Where your path/to/llvm has the symlinks: >> >> * path/to/llvm/tools/clang -> path/to/clang > ln -s `which clang40` path/to/llvm/tools/clangNo, not the binary, the source. The closer to top of trunk you pull the source, the easier it'll be to get it working. A lot of the upstreaming of baremetal support has been *very* recent.... "bleeding edge" recent.>> * path/to/llvm/runtimes/compiler_rt path/to/compiler_rt > ln -s path/to/llvm/projects/compiler-rt path/to/llvm/runtimes/compiler_rt > > Is that right?Sorry, it should be spelled `compiler-rt`, not `compiler_rt`.>> And by "edited BaremetalARM.cmake" I mean you can strip out the other >> targets in there that you don't need. > So I have copied BaremetalARM.cmake into llvm/cmake/caches/BaremetalARM.cmake to be able to alter it, I've put all other repos in llvm/projects and the command is:Leave all the others out for now. An in-tree build of them is just going to give you host binaries, which isn't helpful in your case. You'll have to build them "out of tree". Might be a helpful exercise for you to try building vanilla clang with runtimes for the host, before worrying about how to build everything for your baremetal case: http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary> > # cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -DBAREMETAL_ARMV6M_SYSROOT=~/arm-sysroot -DBAREMETAL_ARMV7M_SYSROOT=~/arm-sysroot -C ../../code/llvm/cmake/caches/BaremetalARM.cmake ../../code/llvm > > Before adding all repos into llvm/projects, it complained about 'Specified distribution component 'clang' doesn't have a target' (just an example). Now I have 'Specified distribution component 'builtins-armv6m-none-eabi' doesn't have a target' as error.I think that error happened because you symlinked the clang binary in, not the source. Jon -- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded / Siemens
On Fri, Aug 04, 2017 at 04:40:44PM -0600, Jonathan Roelofs wrote:> Might be a helpful exercise for you to try building vanilla clang with > runtimes for the host, before worrying about how to build everything for > your baremetal case: > http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summaryI think I'll start with that, first :o) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170805/b611a681/attachment.sig>
On Fri, Aug 04, 2017 at 04:40:44PM -0600, Jonathan Roelofs wrote:> Might be a helpful exercise for you to try building vanilla clang with > runtimes for the host, before worrying about how to build everything for > your baremetal case: > http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summarySo I did. :o) It was fun realizing how much Release type reduces LD memory usage :o) Anyway, just to be clear what "I did" means: - llvm sources from trunk and projects/tools repos checkout under llvm - clang-6.0 compiles "Hello World" - make check-all fails (not sure I'm not causing it) - make install creates everything under PREFIX # cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX=/tmp/x86-sysroot ../../source/llvm # make -j4 # make install It was fun learning how to manualy compile compiler for the first time. Now how to cross compile for bare? Given that I have musl-1.1.16 directory and that I'm preseeding sysroot with: # rm -rf /tmp/barearm-sysroot # mkdir -p /tmp/barearm-sysroot # cp -r musl-1.1.16/include /tmp/barearm-sysroot/ # Thanx for the tip! So I tried to use it, and clang/llvm build, but compiler-rt fails: # cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DBAREMETAL_ARMV7EM_SYSROOT=/tmp/barearm-sysroot -DCMAKE_INSTALL_PREFIX=/tmp/barearm-sysroot -C ../../source/llvm/cmake/caches/BaremetalARM.cmake ../../source/llvm # make -j4 https://gist.github.com/anonymous/85cd5081a6d46a63731d970ee95b20b4 This is the BaremetalARM.cmake: https://gist.github.com/anonymous/ff3248f08ddc99361dcc009e9f4c1020 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170805/d256baa8/attachment.sig>