@@ -427,10 +427,10 @@ of CMake at this time. Please refer to `CMake's documentation <https://cmake.org
427
427
if you have any doubts or want more in depth information.
428
428
429
429
In order to debug remote targets running different architectures than your
430
- host, you will need to compile LLDB (or at least the server component) for the
431
- target. While the easiest solution is to just compile it locally on the target,
432
- this is often not feasible, and in these cases you will need to cross-compile
433
- LLDB on your host.
430
+ host, you will need to compile LLDB (or at least the server component
431
+ `` lldb-server ``) for the target. While the easiest solution is to compile it
432
+ locally on the target, this is often not feasible, and in these cases you will
433
+ need to cross-compile LLDB on your host.
434
434
435
435
Cross-compilation is often a daunting task and has a lot of quirks which depend
436
436
on the exact host and target architectures, so it is not possible to give a
@@ -470,9 +470,22 @@ If you find that CMake is finding a version of an optional dependency that
470
470
for whatever reason doesn't work, consider simply disabling it if you don't
471
471
know that you need it.
472
472
473
- Once all of the dependencies are in place, it's just a matter of configuring
474
- the build system with the locations and arguments of all the necessary tools.
475
- The most important cmake options here are:
473
+ Once all of the dependencies are in place, you need to configure the build
474
+ system with the locations and arguments of all the necessary tools.
475
+
476
+ There are 2 ways to do this depending on your starting point and requirements.
477
+
478
+ 1. If you are starting from scratch and only need the resulting cross compiled
479
+ binaries, you can have LLVM build the native tools for you.
480
+
481
+ 2. If you need a host build too, or already have one, you can tell CMake where
482
+ that is and it will use those native tools instead.
483
+
484
+ If you are going to run ``lldb `` and ``lldb-server `` only on the target machine,
485
+ choose option 1. If you are going to run ``lldb `` on the host machine and
486
+ connect to ``lldb-server `` on the target, choose option 2.
487
+
488
+ Either way, the most important cmake options when cross-compiling are:
476
489
477
490
* ``CMAKE_SYSTEM_NAME `` and ``CMAKE_SYSTEM_PROCESSOR ``: This tells CMake what
478
491
the build target is and from this it will infer that you are cross compiling.
@@ -482,17 +495,18 @@ The most important cmake options here are:
482
495
compilers. You may need to specify the exact target cpu and ABI besides the
483
496
include paths for the target headers.
484
497
* ``CMAKE_EXE_LINKER_FLAGS `` : The flags to be passed to the linker. Usually
485
- just a list of library search paths referencing the target libraries.
498
+ this is a list of library search paths referencing the target libraries.
486
499
* ``LLVM_HOST_TRIPLE `` : The triple of the system that lldb (or lldb-server)
487
500
will run on. Not setting this (or setting it incorrectly) can cause a lot of
488
501
issues with remote debugging as a lot of the choices lldb makes depend on the
489
502
triple reported by the remote platform.
490
- * ``LLVM_NATIVE_TOOL_DIR `` : Is a path to the llvm tools compiled for the host.
491
- Any tool that must be run on the host during a cross build will be configured
492
- from this path, so you do not need to set them all individually. If you are
493
- doing a host build just for the purpose of a cross build, you will need it
494
- to include at least ``llvm-tblgen ``, ``clang-tblgen `` and ``lldb-tblgen ``.
495
- Please be aware that that list may grow over time.
503
+ * ``LLVM_NATIVE_TOOL_DIR `` (only when using an existing host build): Is a
504
+ path to the llvm tools compiled for the host. Any tool that must be run on the
505
+ host during a cross build will be configured from this path, so you do not
506
+ need to set them all individually. If you are doing a host build only for the
507
+ purpose of a cross build, you will need it to include at least
508
+ ``llvm-tblgen ``, ``clang-tblgen `` and ``lldb-tblgen ``. Be aware that
509
+ the list may grow over time.
496
510
* ``CMAKE_LIBRARY_ARCHITECTURE `` : Affects the cmake search path when looking
497
511
for libraries. You may need to set this to your architecture triple if you do
498
512
not specify all your include and library paths explicitly.
@@ -516,8 +530,33 @@ Example 1: Cross-compiling for linux arm64 on Ubuntu host
516
530
517
531
Ubuntu already provides the packages necessary to cross-compile LLDB for arm64.
518
532
It is sufficient to install packages ``gcc-aarch64-linux-gnu ``,
519
- ``g++-aarch64-linux-gnu ``, ``binutils-aarch64-linux-gnu ``. Then it is possible
520
- to prepare the cmake build with the following parameters:
533
+ ``g++-aarch64-linux-gnu ``, ``binutils-aarch64-linux-gnu ``.
534
+
535
+ Configure as follows:
536
+
537
+ ::
538
+
539
+ cmake <path-to-monorepo>/llvm-project/llvm -G Ninja \
540
+ -DCMAKE_BUILD_TYPE=Release \
541
+ -DLLVM_ENABLE_PROJECTS="clang;lld;lldb" \
542
+ -DCMAKE_SYSTEM_NAME=Linux \
543
+ -DCMAKE_SYSTEM_PROCESSOR=AArch64 \
544
+ -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
545
+ -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
546
+ -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu \
547
+ -DLLDB_ENABLE_PYTHON=0 \
548
+ -DLLDB_ENABLE_LIBEDIT=0 \
549
+ -DLLDB_ENABLE_CURSES=0
550
+
551
+ During this build native tools will be built automatically when they are needed.
552
+ The contents of ``<build dir>/bin `` will be target binaries as you'd expect.
553
+ AArch64 binaries in this case.
554
+
555
+ Example 2: Cross-compiling for linux arm64 on Ubuntu host using an existing host build
556
+ **************************************************************************************
557
+
558
+ This build requires an existing host build that includes the required native
559
+ tools. Install the compiler as in example 1 then run CMake as follows:
521
560
522
561
::
523
562
@@ -534,6 +573,8 @@ to prepare the cmake build with the following parameters:
534
573
-DLLDB_ENABLE_LIBEDIT=0 \
535
574
-DLLDB_ENABLE_CURSES=0
536
575
576
+ The only difference from example 1 is the addition of
577
+ ``DLLVM_NATIVE_TOOL_DIR `` pointing to your existing host build.
537
578
538
579
An alternative (and recommended) way to compile LLDB is with clang.
539
580
Unfortunately, clang is not able to find all the include paths necessary for a
@@ -556,7 +597,7 @@ qemu and chroot to simulate the target environment. Then you can install the
556
597
necessary packages in this environment (python-dev, libedit-dev, etc.) and
557
598
point your compiler to use them using the correct -I and -L arguments.
558
599
559
- Example 2 : Cross-compiling for Android on Linux
600
+ Example 3 : Cross-compiling for Android on Linux
560
601
***********************************************
561
602
562
603
In the case of Android, the toolchain and all required headers and libraries
0 commit comments