All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler
@ 2019-09-06  9:09 Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 01/11] package/clang: help host-clang to find our external toolchain Romain Naour
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Last year Valentin Korenblit added during his internship at Smile,
llvm/clang packages to provide llvm/clang libraries for the target.
See the article from Valentin on Linuxembedded blog [1].

But Clang could not be used as a cross-compiler by Buildroot since
it was necessary to build the Linux kernel with GCC [2].

Recently, I've tried to build an aarch64 Linux kernel (5.2.7) with
Clang and it worked under Qemu [3]. I also tested for x86_64 but we need
the upcomming llvm/clang version 9 to build the kernel [4].
This new version add the support of "asm-goto" which was the last
missing part to be able to build the Linux kernel on x86_64 [5].
But for theses tests, only the kernel was built with Clang.

While testing the x86_64 kernel and it's rootfs built with Clang under Qemu,
I had a runtime issue during the userspace boot process (Busybox's init).
While searching about the issue, I discover the lowRISC blog from Lu??s Marques
about the same issue and tested the patch he contributed to the Busybox project
(Thanks!).

So, this series is about to complete the integration of Clang as cross-compiler
by using a toolchain-wrapper and fixing some build system infrastructure
(cmake, meson) to use Clang instead of GCC.

Add this new experimental option into "Advanced" menu since we are expecting
some build and runtime issues for number of packages (bootloaders, kernel).

For now, Clang cross-compiler can only be use as internal toolchain,
so it is build from the source which take a long time...

[1] http://www.linuxembedded.fr/2018/07/llvmclang-integration-into-buildroot
[2] https://www.elinux.org/Buildroot:DeveloperDaysFOSDEM2018#LLVM.2FClang
[3] http://www.linuxembedded.fr/2019/08/my-first-linux-kernel-built-with-clang-compiler
[4] https://www.phoronix.com/scan.php?page=news_item&px=LLVM-9.0-RC3-Released
[5] https://www.phoronix.com/scan.php?page=news_item&px=LLVM-Asm-Goto-Merged
[6] https://www.lowrisc.org/blog/2019/07/large-scale-risc-v-llvm-testing-with-buildroot

Best regards,
Romain

Romain Naour (11):
  package/clang: help host-clang to find our external toolchain
  package/llvm: add the version major variable
  package/clang: add the version major variable
  package/clang: install a toolchain-wrapper for the host clang
    cross-compiler
  linux: override CC for the case CC is not GCC
  package/meson: use TARGET_{CC,CXX} instead of TARGET_CROSS
  package/busybox: fix applets runtime issue when building with clang
    cross-compiler
  package/clang: add a host entry for clang
  core: allow to use Clang as cross-compiler
  toolchain: add a warning when Clang is used as cross-compiler
  linux: don't set -Wno-attribute-alias flag when Clang is used as
    cross-compiler

 Config.in                                     |  20 ++
 linux/linux.mk                                |   4 +-
 package/Config.in.host                        |   1 +
 package/Makefile.in                           |  13 +-
 ...use-BB_GLOBAL_CONST-where-applicable.patch | 173 ++++++++++++++++++
 ...hains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch |  76 ++++++++
 package/clang/Config.in.host                  |  19 ++
 package/clang/clang.mk                        |  49 ++++-
 package/llvm/llvm.mk                          |   3 +-
 package/meson/cross-compilation.conf.in       |   4 +-
 package/meson/meson.mk                        |   3 +-
 package/pkg-meson.mk                          |   3 +-
 toolchain/Config.in                           |   6 +
 .../toolchain-buildroot.mk                    |   7 +
 .../toolchain-external/toolchain-external.mk  |   7 +
 15 files changed, 378 insertions(+), 10 deletions(-)
 create mode 100644 package/busybox/0003-use-BB_GLOBAL_CONST-where-applicable.patch
 create mode 100644 package/clang/0001-lib-Driver-ToolChains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch
 create mode 100644 package/clang/Config.in.host

-- 
2.21.0

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 01/11] package/clang: help host-clang to find our external toolchain
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 02/11] package/llvm: add the version major variable Romain Naour
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

To build libfuzzer package Matthew Weber noticed that (host) clang
doesn't run on the host without "-B $(HOST_DIR)/opt/ext-toolchain"
option. This option add a new search path for binaries and object
files used implicitly.

Without -B clang fail to link due to missing crtbeging.o file and libgcc:
output/host/bin/aarch64-linux-gnu-ld: cannot find crtbegin.o: No such file or directory
output/host/bin/aarch64-linux-gnu-ld: cannot find -lgcc

Indeed, clang search path doesn't include the dafault cross-gcc's search paths:

$ output/host/bin/clang -print-search-dirs
programs: = output/host/bin:output/host/bin:/..//bin
libraries: = output/host/lib/clang/8.0.0:
             output/host/bin/../lib64:
             /lib/../lib64:
             /usr/lib/../lib64:
             output/host/bin/../lib:
             /lib:/usr/lib

Here is the same command for cross-gcc:

$ output/host/bin/aarch64-linux-gnu-gcc -print-search-dirs
install: output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/
programs: = output/host/opt/ext-toolchain/bin/../libexec/gcc/aarch64-linux-gnu/8.3.0/:
            output/host/opt/ext-toolchain/bin/../libexec/gcc/:
            output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/../../../../aarch64-linux-gnu/bin/aarch64-linux-gnu/8.3.0/:
            output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/../../../../aarch64-linux-gnu/bin/
libraries: = output/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/:
             output/host/opt/ext-toolchain/bin/../lib/gcc/:
             output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/../../../../aarch64-linux-gnu/lib/aarch64-linux-gnu/8.3.0/:
             output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/../../../../aarch64-linux-gnu/lib/../lib64/:
             output/host/aarch64-buildroot-linux-gnu/sysroot/lib/aarch64-linux-gnu/8.3.0/:
             output/host/aarch64-buildroot-linux-gnu/sysroot/lib/../lib64/:
             output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/aarch64-linux-gnu/8.3.0/:
             output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/:
             output/host/opt/ext-toolchain/bin/../lib/gcc/aarch64-linux-gnu/8.3.0/../../../../aarch64-linux-gnu/lib/:
             output/host/aarch64-buildroot-linux-gnu/sysroot/lib/:
             output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/

We can see that gcc default search path contains
"output/host/opt/ext-toolchain" directory where the external toolchain
has been extracted.

Since we want to use clang without additional option like -B,
patch clang in order to use GCC_INSTALL_PREFIX instead of
using automatic detection (which doesn't work for Buildroot).

We eventually want to relocate the Buildroot SDK containing the clang
cross-compiler, so we provide a relative path to GCC_INSTALL_PREFIX
in order to avoid to hardcode the path to the GCC toolchain.

Also the path between clang and the GCC external toolchain is not always
the same, we have the following case:

* Toolchain to be downloaded and installed
  The toolchain is extracted into $(HOST_DIR)/opt/ext-toolchain, so the
  path is "../opt/ext-toolchain".

* Pre-installed toolchain
  The toolchain is localed somewhere in the host filesystem and
  defined by the user using BR2_TOOLCHAIN_EXTERNAL_PATH.

So, set GCC_INSTALL_PREFIX using realpath:

-DGCC_INSTALL_PREFIX:PATH=`realpath --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`

When we use a Buildroot's internal toolchain, clang will find theses
crt*.o files and libgcc.

http://lists.busybox.net/pipermail/buildroot/2019-August/256204.html

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matthew Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
v2: don't hack the external toolchain infra.
    patch clang and provide GCC_INSTALL_PREFIX
---
 ...hains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch | 76 +++++++++++++++++++
 package/clang/clang.mk                        |  7 ++
 2 files changed, 83 insertions(+)
 create mode 100644 package/clang/0001-lib-Driver-ToolChains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch

diff --git a/package/clang/0001-lib-Driver-ToolChains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch b/package/clang/0001-lib-Driver-ToolChains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch
new file mode 100644
index 0000000000..63ddbaf35f
--- /dev/null
+++ b/package/clang/0001-lib-Driver-ToolChains-Gnu-Use-GCC_INSTALL_PREFIX-in-.patch
@@ -0,0 +1,76 @@
+From fe21cede3939a435d62efbd5799547fab6af1b0a Mon Sep 17 00:00:00 2001
+From: Romain Naour <romain.naour@smile.fr>
+Date: Mon, 5 Aug 2019 16:06:48 +0200
+Subject: [PATCH] lib/Driver/ToolChains/Gnu: Use GCC_INSTALL_PREFIX in the set
+ of prefixes for searching the gcc toolchain
+
+By default, the Gnu Toolchains driver is looking at the parent
+directory while looking for the gcc toolchain when clang is installed
+at "D.InstalledDir"
+
+But this doesn't work with Buildroot since the external
+toolchain is installed in host/opt/ext-toolchain and the sysroot is
+moved to host/<arch>-buildroot-linux-gnu/sysroot/ directory.
+
+We tried by setting GCC_INSTALL_PREFIX in clang.mk for host-clang
+but it doesn't work since we already provide a sysroot [1].
+
+Help the Gnu Toolchains driver by using GCC_INSTALL_PREFIX path.
+
+Since we want to be able to relocate the clang toolchain,
+allow to use a relative path with GCC_INSTALL_PREFIX.
+
+Buildroot will provide such relative path by using:
+HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`
+
+Doing so allow to use clang without providing additional search
+paths with -B option on the clang's command line.
+
+[1] https://reviews.llvm.org/D49244
+[2] http://lists.busybox.net/pipermail/buildroot/2019-August/256204.html
+
+Signed-off-by: Romain Naour <romain.naour@smile.fr>
+---
+This issue needs to be reported and discussed with upstream.
+---
+ lib/Driver/ToolChains/Gnu.cpp | 17 +++++++++++++++++
+ 1 file changed, 17 insertions(+)
+
+diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
+index 2ad45097dc..90d6b5b748 100644
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -1725,6 +1725,8 @@ void Generic_GCC::GCCInstallationDetector::init(
+ 
+     Prefixes.push_back(GCCToolchainDir);
+   } else {
++    StringRef GccIinstallPrefix = GCC_INSTALL_PREFIX;
++
+     // If we have a SysRoot, try that first.
+     if (!D.SysRoot.empty()) {
+       Prefixes.push_back(D.SysRoot);
+@@ -1734,6 +1736,21 @@ void Generic_GCC::GCCInstallationDetector::init(
+     // Then look for gcc installed alongside clang.
+     Prefixes.push_back(D.InstalledDir + "/..");
+ 
++    // Use GCC_INSTALL_PREFIX if provided by the buildsystem.
++    if (!GccIinstallPrefix.empty())
++    {
++        if (llvm::sys::path::is_relative(GccIinstallPrefix))
++        {
++            // Use a relative path to gcc from clang install path.
++            Prefixes.push_back(D.InstalledDir + "/" + GccIinstallPrefix.str());
++        }
++        else
++        {
++            // Hardcode the absolute path provided by GCC_INSTALL_PREFIX.
++            Prefixes.push_back(GCC_INSTALL_PREFIX);
++        }
++    }
++
+     // Next, look for prefix(es) that correspond to distribution-supplied gcc
+     // installations.
+     if (D.SysRoot.empty()) {
+-- 
+2.20.1
+
diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index 3796ca8605..ed6f9bf90e 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -102,5 +102,12 @@ CLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON
 HOST_CLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all
 CLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all
 
+# Help host-clang to find our external toolchain, use a relative path from the clang
+# installation directory to the external toolchain installation directory in order to
+# not hardcode the toolchain absolute path.
+ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
+HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`
+endif
+
 $(eval $(cmake-package))
 $(eval $(host-cmake-package))
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 02/11] package/llvm: add the version major variable
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 01/11] package/clang: help host-clang to find our external toolchain Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 03/11] package/clang: " Romain Naour
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 package/llvm/llvm.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
index f14b537d94..e885c63f98 100644
--- a/package/llvm/llvm.mk
+++ b/package/llvm/llvm.mk
@@ -5,7 +5,8 @@
 ################################################################################
 
 # LLVM and Clang should be version bumped together
-LLVM_VERSION = 8.0.1
+LLVM_VERSION_MAJOR = 8
+LLVM_VERSION = $(LLVM_VERSION_MAJOR).0.1
 LLVM_SITE = https://github.com/llvm/llvm-project/releases/download/llvmorg-$(LLVM_VERSION)
 LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
 LLVM_LICENSE = NCSA
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 03/11] package/clang: add the version major variable
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 01/11] package/clang: help host-clang to find our external toolchain Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 02/11] package/llvm: add the version major variable Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 04/11] package/clang: install a toolchain-wrapper for the host clang cross-compiler Romain Naour
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

CLANG_VERSION_MAJOR will be used in a followup patch
to install the toolchain-wrapper for clang cross-compiler
and it's symlinks.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 package/clang/clang.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index ed6f9bf90e..857ec148ac 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -5,7 +5,8 @@
 ################################################################################
 
 # LLVM and Clang should be version bumped together
-CLANG_VERSION = 8.0.1
+CLANG_VERSION_MAJOR = 8
+CLANG_VERSION = $(CLANG_VERSION_MAJOR).0.1
 CLANG_SITE = https://github.com/llvm/llvm-project/releases/download/llvmorg-$(CLANG_VERSION)
 CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
 CLANG_LICENSE = NCSA
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 04/11] package/clang: install a toolchain-wrapper for the host clang cross-compiler
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (2 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 03/11] package/clang: " Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 05/11] linux: override CC for the case CC is not GCC Romain Naour
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

In order to use clang as a host cross-compiler for Buildroot, we need
to provide at least the path to the sysroot (using --sysroot) and
some other compiler flags.

Hoppefully, we can reuse the toolchain wrapper for gcc since
clang support most of the gcc flags used in the Buildroot's toolchain
wrapper.

Only the flag -mfused-madd (deprecated since gcc 4.6) for mips is
not supported by clang. Since Clang require gcc >= 5.x this flag
can never be used.

Since host-clang is always build by Buildroot as an internal toolchain,
we have to use a second toolchain-wrapper called toolchain-wrapper-clang
when an external toolchain is used.
Inded, the two wrapper use a different path BR_CROSS_PATH_SUFFIX in this
case.

After building the clang toolchain wrapper, create the symlinks needed
to force package infrastructure to use clang througt the wrapper.

Initially clang install the clang-8 binary and create all other symlinks:

 # clang -> clang-8
 # clang++ -> clang
 # clang-8
 # clang-cl -> clang
 # clang-cpp -> clang

Use a post install hook to rename the clang-8 binary to clang-8.br_real
and recreate all symlinks:

 # clang -> toolchain-wrapper-clang
 # clang++ -> toolchain-wrapper-clang
 # clang-8 -> toolchain-wrapper-clang
 # clang-8.br_real
 # clang++.br_real -> clang-8.br_real
 # clang.br_real -> clang-8.br_real
 # clang-cl -> toolchain-wrapper-clang
 # clang-cl.br_real -> clang-8.br_real
 # clang-cpp -> toolchain-wrapper-clang
 # clang-cpp.br_real -> clang-8.br_real

Use the previously introduced CLANG_VERSION_MAJOR variable to create
theses symlinks.

Set BR_CROSS_PATH_SUFFIX to ".br_real" as for the Buildroot's internal
GCC toolchain backend to find the "real" clang binary installed in
$(HOST_DIR)/bin.

Borrow TOOLCHAIN_WRAPPER_BUILD and TOOLCHAIN_WRAPPER_INSTALL to
build and install the specific clang toolchain wrapper.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 package/clang/clang.mk | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index 857ec148ac..148df8e611 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -110,5 +110,39 @@ ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
 HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`
 endif
 
+define HOST_CLANG_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
+	$(Q)cd $(HOST_DIR)/bin; \
+	for i in clang clang-$(CLANG_VERSION_MAJOR) clang++ clang-cl clang-cpp; do \
+		case "$$i" in \
+		*clang-$(CLANG_VERSION_MAJOR)) \
+			rm -f $$i.br_real; \
+			mv $$i $$i.br_real; \
+			ln -sf toolchain-wrapper-clang $$i; \
+			;; \
+		*) \
+			ln -snf toolchain-wrapper-clang $$i; \
+			ln -snf clang-$(CLANG_VERSION_MAJOR).br_real $$i.br_real; \
+			;; \
+		esac; \
+	done
+endef
+
+define HOST_CLANG_TOOLCHAIN_WRAPPER_BUILD
+	$(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
+		-s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
+		toolchain/toolchain-wrapper.c \
+		-o $(@D)/toolchain-wrapper-clang
+endef
+
+define HOST_CLANG_TOOLCHAIN_WRAPPER_INSTALL
+	$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper-clang \
+		$(HOST_DIR)/bin/toolchain-wrapper-clang
+endef
+
+HOST_CLANG_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
+HOST_CLANG_POST_BUILD_HOOKS += HOST_CLANG_TOOLCHAIN_WRAPPER_BUILD
+HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_TOOLCHAIN_WRAPPER_INSTALL
+HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
+
 $(eval $(cmake-package))
 $(eval $(host-cmake-package))
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 05/11] linux: override CC for the case CC is not GCC
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (3 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 04/11] package/clang: install a toolchain-wrapper for the host clang cross-compiler Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 06/11] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS Romain Naour
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Until now we provided only CROSS_COMPILE to the kernel
buildsystem to use our GCC cross-compiler. Internally,
the buildsystem defined CC=$(CROSS_COMPILE)gcc.

Since Clang can now be used as cross-compiler, Buildroot
may define in the future TARGET_CC to use clang instead
of GCC.

In order to build the kernel with the selected compiler,
make sure to define CC=$(TARGET_CC) in LINUX_MAKE_FLAGS.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 linux/linux.mk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux/linux.mk b/linux/linux.mk
index 29d2f0ee69..d381c96d85 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -128,6 +128,7 @@ LINUX_MAKE_FLAGS = \
 	ARCH=$(KERNEL_ARCH) \
 	INSTALL_MOD_PATH=$(TARGET_DIR) \
 	CROSS_COMPILE="$(TARGET_CROSS)" \
+	CC="$(TARGET_CC)" \
 	DEPMOD=$(HOST_DIR)/sbin/depmod
 
 ifeq ($(BR2_REPRODUCIBLE),y)
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 06/11] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (4 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 05/11] linux: override CC for the case CC is not GCC Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06 15:58   ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler Romain Naour
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Using TARGET_CROSS expect using GCC compiler, instead use
TARGET_CC and TARGET_CXX for the case where Clang is
used as cross-compiler.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 package/meson/cross-compilation.conf.in | 4 ++--
 package/meson/meson.mk                  | 3 ++-
 package/pkg-meson.mk                    | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/package/meson/cross-compilation.conf.in b/package/meson/cross-compilation.conf.in
index fc8e27f7eb..86347e9e4e 100644
--- a/package/meson/cross-compilation.conf.in
+++ b/package/meson/cross-compilation.conf.in
@@ -4,8 +4,8 @@
 # - Buildroot's 'target' is Meson's 'host'
 
 [binaries]
-c = '@TARGET_CROSS at gcc'
-cpp = '@TARGET_CROSS at g++'
+c = '@TARGET_CC@'
+cpp = '@TARGET_CXX@'
 ar = '@TARGET_CROSS at ar'
 strip = '@TARGET_CROSS at strip'
 pkgconfig = '@HOST_DIR@/usr/bin/pkg-config'
diff --git a/package/meson/meson.mk b/package/meson/meson.mk
index 3267581fc6..1f836ef070 100644
--- a/package/meson/meson.mk
+++ b/package/meson/meson.mk
@@ -54,7 +54,8 @@ HOST_MESON_SED_CXXFLAGS = $(if $(strip $(TARGET_CXXFLAGS)),`printf '"%s"$(comma)
 # own flags if they need to.
 define HOST_MESON_INSTALL_CROSS_CONF
 	mkdir -p $(HOST_DIR)/etc/meson
-	sed -e "s%@TARGET_CROSS@%$(TARGET_CROSS)%g" \
+	sed -e "s%@TARGET_CC@%$(TARGET_CC)%g" \
+	    -e "s%@TARGET_CXX@%$(TARGET_CXX)%g" \
 	    -e "s%@TARGET_ARCH@%$(HOST_MESON_TARGET_CPU_FAMILY)%g" \
 	    -e "s%@TARGET_CPU@%$(HOST_MESON_TARGET_CPU)%g" \
 	    -e "s%@TARGET_ENDIAN@%$(HOST_MESON_TARGET_ENDIAN)%g" \
diff --git a/package/pkg-meson.mk b/package/pkg-meson.mk
index 0b811d1cc0..9821636c28 100644
--- a/package/pkg-meson.mk
+++ b/package/pkg-meson.mk
@@ -71,7 +71,8 @@ $(2)_MESON_SED_CXXFLAGS = $$(if $$(strip $$($(2)_CXXFLAGS)),`printf '"%s"$$(comm
 define $(2)_CONFIGURE_CMDS
 	rm -rf $$($$(PKG)_SRCDIR)/build
 	mkdir -p $$($$(PKG)_SRCDIR)/build
-	sed -e "s%@TARGET_CROSS@%$$(TARGET_CROSS)%g" \
+	sed -e "s%@TARGET_CC@%$(TARGET_CC)%g" \
+	    -e "s%@TARGET_CXX@%$(TARGET_CXX)%g" \
 	    -e "s%@TARGET_ARCH@%$$(HOST_MESON_TARGET_CPU_FAMILY)%g" \
 	    -e "s%@TARGET_CPU@%$$(GCC_TARGET_CPU)%g" \
 	    -e "s%@TARGET_ENDIAN@%$$(call LOWERCASE,$$(BR2_ENDIAN))%g" \
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (5 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 06/11] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-07  3:11   ` Matthew Weber
  2019-09-06  9:09 ` [Buildroot] [PATCH 08/11] package/clang: add a host entry for clang Romain Naour
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Apply a patch contributed by Luis Marques on the Busybox mailing list [1]
fixing a runtime issue (segfault) when busybox is compiled by Clang.

The patch disable the compiler optimizations for Clang/LLVM only.

Without this patch, busybox segfault with several applets
(login on aarch64 using Clang 8.0.1, init on x86_64 using Clang 9.0.0rc3)

[1] http://lists.busybox.net/pipermail/busybox/2019-June/087337.html

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Luis Marques <luismarques@lowrisc.org>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
Note:
 The Luis Marques's SoB line in the Busybox patch is missing.
 The patch is still under review to avoid disabling optimizations.
---
 ...use-BB_GLOBAL_CONST-where-applicable.patch | 173 ++++++++++++++++++
 1 file changed, 173 insertions(+)
 create mode 100644 package/busybox/0003-use-BB_GLOBAL_CONST-where-applicable.patch

diff --git a/package/busybox/0003-use-BB_GLOBAL_CONST-where-applicable.patch b/package/busybox/0003-use-BB_GLOBAL_CONST-where-applicable.patch
new file mode 100644
index 0000000000..738a15b0de
--- /dev/null
+++ b/package/busybox/0003-use-BB_GLOBAL_CONST-where-applicable.patch
@@ -0,0 +1,173 @@
+From 6f53fa8303edff685aee3cc16a6c8967fae869db Mon Sep 17 00:00:00 2001
+From: Luis Marques <luismarques@lowrisc.org>
+Date: Wed, 4 Sep 2019 17:48:39 +0200
+Subject: [PATCH] use BB_GLOBAL_CONST where applicable
+
+Signed-off-by: Romain Naour <romain.naour@smile.fr>
+---
+ coreutils/test.c          |  3 +--
+ coreutils/test_ptr_hack.c |  2 +-
+ include/libbb.h           | 27 +++++++++++++++++++++++++--
+ libbb/lineedit.c          |  3 +--
+ libbb/lineedit_ptr_hack.c |  2 +-
+ libbb/ptr_to_globals.c    |  2 +-
+ shell/ash.c               | 13 -------------
+ shell/ash_ptr_hack.c      |  6 +++---
+ 8 files changed, 33 insertions(+), 25 deletions(-)
+
+diff --git a/coreutils/test.c b/coreutils/test.c
+index 8d7dac025..e1d440106 100644
+--- a/coreutils/test.c
++++ b/coreutils/test.c
+@@ -400,8 +400,7 @@ struct test_statics {
+ 	jmp_buf leaving;
+ };
+ 
+-/* See test_ptr_hack.c */
+-extern struct test_statics *const test_ptr_to_statics;
++extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
+ 
+ #define S (*test_ptr_to_statics)
+ #define args            (S.args         )
+diff --git a/coreutils/test_ptr_hack.c b/coreutils/test_ptr_hack.c
+index 5ba9dcc68..6759b2144 100644
+--- a/coreutils/test_ptr_hack.c
++++ b/coreutils/test_ptr_hack.c
+@@ -18,6 +18,6 @@ struct test_statics *test_ptr_to_statics;
+ /* gcc -combine will see through and complain */
+ /* Using alternative method which is more likely to break
+  * on weird architectures, compilers, linkers and so on */
+-struct test_statics *const test_ptr_to_statics __attribute__ ((section (".data")));
++struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics __attribute__ ((section (".data")));
+ 
+ #endif
+diff --git a/include/libbb.h b/include/libbb.h
+index 021100db1..2523fd89c 100644
+--- a/include/libbb.h
++++ b/include/libbb.h
+@@ -338,10 +338,33 @@ struct BUG_off_t_size_is_misdetected {
+ #endif
+ #endif
+ 
++/* We use a trick to have more optimized code (fewer pointer reloads). E.g.:
++ *  ash.c:   extern struct globals *const ash_ptr_to_globals;
++ *  ash_ptr_hack.c: struct globals *ash_ptr_to_globals;
++ * This way, compiler in ash.c knows the pointer cannot change.
++ *
++ * However, this relies on C undefined behavior, so we whitelist compilers
++ * where we know this isn't problematic, by using the the BB_GLOBAL_CONST
++ * preprocessor definition.
++ * If you are sure this trick also works with your toolchain you can add
++ * "-DBB_GLOBAL_CONST='const'" to CONFIG_EXTRA_CFLAGS or add your compiler to
++ * the whitelist below.
++ */
++
++#ifndef BB_GLOBAL_CONST
++# if defined(__clang__)
++#  define BB_GLOBAL_CONST
++# elif defined(__GNUC__)
++#  define BB_GLOBAL_CONST const
++# else
++#  define BB_GLOBAL_CONST
++# endif
++#endif
++
+ #if defined(__GLIBC__)
+ /* glibc uses __errno_location() to get a ptr to errno */
+ /* We can just memorize it once - no multithreading in busybox :) */
+-extern int *const bb_errno;
++extern int *BB_GLOBAL_CONST bb_errno;
+ #undef errno
+ #define errno (*bb_errno)
+ #endif
+@@ -2109,7 +2132,7 @@ struct globals;
+ /* '*const' ptr makes gcc optimize code much better.
+  * Magic prevents ptr_to_globals from going into rodata.
+  * If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */
+-extern struct globals *const ptr_to_globals;
++extern struct globals *BB_GLOBAL_CONST ptr_to_globals;
+ /* At least gcc 3.4.6 on mipsel system needs optimization barrier */
+ #define barrier() __asm__ __volatile__("":::"memory")
+ #define SET_PTR_TO_GLOBALS(x) do { \
+diff --git a/libbb/lineedit.c b/libbb/lineedit.c
+index fbabc6c12..b9e9719c5 100644
+--- a/libbb/lineedit.c
++++ b/libbb/lineedit.c
+@@ -180,8 +180,7 @@ struct lineedit_statics {
+ #endif
+ };
+ 
+-/* See lineedit_ptr_hack.c */
+-extern struct lineedit_statics *const lineedit_ptr_to_statics;
++extern struct lineedit_statics *BB_GLOBAL_CONST lineedit_ptr_to_statics;
+ 
+ #define S (*lineedit_ptr_to_statics)
+ #define state            (S.state           )
+diff --git a/libbb/lineedit_ptr_hack.c b/libbb/lineedit_ptr_hack.c
+index dc45855d5..ac33bd409 100644
+--- a/libbb/lineedit_ptr_hack.c
++++ b/libbb/lineedit_ptr_hack.c
+@@ -18,6 +18,6 @@ struct lineedit_statics *lineedit_ptr_to_statics;
+ /* gcc -combine will see through and complain */
+ /* Using alternative method which is more likely to break
+  * on weird architectures, compilers, linkers and so on */
+-struct lineedit_statics *const lineedit_ptr_to_statics __attribute__ ((section (".data")));
++struct lineedit_statics *BB_GLOBAL_CONST lineedit_ptr_to_statics __attribute__ ((section (".data")));
+ 
+ #endif
+diff --git a/libbb/ptr_to_globals.c b/libbb/ptr_to_globals.c
+index 8ba9cd154..26d7b2042 100644
+--- a/libbb/ptr_to_globals.c
++++ b/libbb/ptr_to_globals.c
+@@ -25,7 +25,7 @@ int *bb_errno;
+ /* gcc -combine will see through and complain */
+ /* Using alternative method which is more likely to break
+  * on weird architectures, compilers, linkers and so on */
+-struct globals *const ptr_to_globals __attribute__ ((section (".data")));
++struct globals *BB_GLOBAL_CONST ptr_to_globals __attribute__ ((section (".data")));
+ 
+ #ifdef __GLIBC__
+ int *const bb_errno __attribute__ ((section (".data")));
+diff --git a/shell/ash.c b/shell/ash.c
+index e3bbac9a0..3141f3812 100644
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -288,19 +288,6 @@ typedef long arith_t;
+ # error "Do not even bother, ash will not run on NOMMU machine"
+ #endif
+ 
+-/* We use a trick to have more optimized code (fewer pointer reloads):
+- *  ash.c:   extern struct globals *const ash_ptr_to_globals;
+- *  ash_ptr_hack.c: struct globals *ash_ptr_to_globals;
+- * This way, compiler in ash.c knows the pointer can not change.
+- *
+- * However, this may break on weird arches or toolchains. In this case,
+- * set "-DBB_GLOBAL_CONST=''" in CONFIG_EXTRA_CFLAGS to disable
+- * this optimization.
+- */
+-#ifndef BB_GLOBAL_CONST
+-# define BB_GLOBAL_CONST const
+-#endif
+-
+ 
+ /* ============ Hash table sizes. Configurable. */
+ 
+diff --git a/shell/ash_ptr_hack.c b/shell/ash_ptr_hack.c
+index f69840825..af16cca27 100644
+--- a/shell/ash_ptr_hack.c
++++ b/shell/ash_ptr_hack.c
+@@ -22,8 +22,8 @@ struct globals_var      *ash_ptr_to_globals_var;
+ /* gcc -combine will see through and complain */
+ /* Using alternative method which is more likely to break
+  * on weird architectures, compilers, linkers and so on */
+-struct globals_misc     *const ash_ptr_to_globals_misc __attribute__ ((section (".data")));
+-struct globals_memstack *const ash_ptr_to_globals_memstack __attribute__ ((section (".data")));
+-struct globals_var      *const ash_ptr_to_globals_var __attribute__ ((section (".data")));
++struct globals_misc     *BB_GLOBAL_CONST ash_ptr_to_globals_misc __attribute__ ((section (".data")));
++struct globals_memstack *BB_GLOBAL_CONST ash_ptr_to_globals_memstack __attribute__ ((section (".data")));
++struct globals_var      *BB_GLOBAL_CONST ash_ptr_to_globals_var __attribute__ ((section (".data")));
+ 
+ #endif
+-- 
+2.21.0
+
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 08/11] package/clang: add a host entry for clang
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (6 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 09/11] core: allow to use Clang as cross-compiler Romain Naour
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

In order to allow Buildroot's user to select clang
as cross-compiler we need first an option to select
host-clang package in menuconfig.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 package/Config.in.host       |  1 +
 package/clang/Config.in.host | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 package/clang/Config.in.host

diff --git a/package/Config.in.host b/package/Config.in.host
index 93822304e9..182e175a78 100644
--- a/package/Config.in.host
+++ b/package/Config.in.host
@@ -7,6 +7,7 @@ menu "Host utilities"
 	source "package/cbootimage/Config.in.host"
 	source "package/checkpolicy/Config.in.host"
 	source "package/checksec/Config.in.host"
+	source "package/clang/Config.in.host"
 	source "package/cmake/Config.in.host"
 	source "package/cramfs/Config.in.host"
 	source "package/cryptsetup/Config.in.host"
diff --git a/package/clang/Config.in.host b/package/clang/Config.in.host
new file mode 100644
index 0000000000..ca5d7ba678
--- /dev/null
+++ b/package/clang/Config.in.host
@@ -0,0 +1,19 @@
+config BR2_PACKAGE_HOST_CLANG
+	bool "clang cross-compiler"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on BR2_HOST_GCC_AT_LEAST_4_8
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on !BR2_TOOLCHAIN_HAS_GCC_BUG_64735 # std::shared_future
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_USE_WCHAR # std::wstring
+	help
+	  Clang is a C/C++, Objective C/C++ and OpenCL C front-end
+	  for the LLVM compiler.
+
+	  This option install the clang cross-compiler and it's
+	  libraires. It doesn't mean that's used by Buildroot
+	  infra to build packages.
+
+	  http://clang.llvm.org
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 09/11] core: allow to use Clang as cross-compiler
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (7 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 08/11] package/clang: add a host entry for clang Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 10/11] toolchain: add a warning when Clang is used " Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 11/11] linux: don't set -Wno-attribute-alias flag " Romain Naour
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Add this new experimental option into "Advanced" menu since
we are expecting some build and runtime issues for number of
packages (bootloaders, kernel).

Add host-clang as dependency in toolchain-buildroot and
toolchain-external virtual in order to be sure that the
clang cross-compiler is built before generating
Buildroot.cmake file from an TOOLCHAIN_CMAKE_INSTALL_FILES
hook (defined in cmake package).

For toolchain-external package, we can latter remove the
host-clang dependency if we can import Clang with the
prebuilt external toolchain.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 Config.in                                     | 20 +++++++++++++++++++
 package/Makefile.in                           | 13 +++++++++---
 package/clang/clang.mk                        |  5 +++++
 .../toolchain-buildroot.mk                    |  7 +++++++
 .../toolchain-external/toolchain-external.mk  |  7 +++++++
 5 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/Config.in b/Config.in
index a6e280b885..6e3a7986bf 100644
--- a/Config.in
+++ b/Config.in
@@ -711,6 +711,26 @@ config BR2_REPRODUCIBLE
 	  This is labeled as an experimental feature, as not all
 	  packages behave properly to ensure reproducibility.
 
+config BR2_USER_HOST_CLANG_AS_CROSS_COMPILER
+	bool "Use Clang as cross-compiler (experimental)"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on BR2_HOST_GCC_AT_LEAST_4_8
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
+	depends on BR2_TOOLCHAIN_HAS_THREADS
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on !BR2_TOOLCHAIN_HAS_GCC_BUG_64735 # std::shared_future
+	depends on !BR2_STATIC_LIBS
+	depends on BR2_USE_WCHAR # std::wstring
+	select BR2_PACKAGE_HOST_CLANG
+	help
+	  This option will force Buildroot to use Clang as cross-compiler
+	  instead of GCC. A GCC toolchain (internal or external) is still
+	  needed to build with Clang.
+
+	  This is labeled as an experimental feature, since we are
+	  expecting some build and runtime issues for number of packages
+	  (bootloaders, kernel).
+
 endmenu
 
 comment "Security Hardening Options"
diff --git a/package/Makefile.in b/package/Makefile.in
index 0a7899c852..aebf4edd1b 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -200,9 +200,6 @@ endif
 # Define TARGET_xx variables for all common binutils/gcc
 TARGET_AR       = $(TARGET_CROSS)ar
 TARGET_AS       = $(TARGET_CROSS)as
-TARGET_CC       = $(TARGET_CROSS)gcc
-TARGET_CPP      = $(TARGET_CROSS)cpp
-TARGET_CXX      = $(TARGET_CROSS)g++
 TARGET_FC       = $(TARGET_CROSS)gfortran
 TARGET_LD       = $(TARGET_CROSS)ld
 TARGET_NM       = $(TARGET_CROSS)nm
@@ -211,6 +208,16 @@ TARGET_READELF  = $(TARGET_CROSS)readelf
 TARGET_OBJCOPY  = $(TARGET_CROSS)objcopy
 TARGET_OBJDUMP  = $(TARGET_CROSS)objdump
 
+ifeq ($(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y)
+TARGET_CC       = $(HOST_DIR)/bin/clang
+TARGET_CPP      = $(HOST_DIR)/bin/clang-cpp
+TARGET_CXX      = $(HOST_DIR)/bin/clang++
+else
+TARGET_CC       = $(TARGET_CROSS)gcc
+TARGET_CPP      = $(TARGET_CROSS)cpp
+TARGET_CXX      = $(TARGET_CROSS)g++
+endif
+
 ifeq ($(BR2_STRIP_strip),y)
 STRIP_STRIP_DEBUG := --strip-debug
 TARGET_STRIP = $(TARGET_CROSS)strip
diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index 148df8e611..674dedc746 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -14,6 +14,11 @@ CLANG_LICENSE_FILES = LICENSE.TXT
 CLANG_SUPPORTS_IN_SOURCE_BUILD = NO
 CLANG_INSTALL_STAGING = YES
 
+# Allow host-clang to be build as part of the toolchain
+ifeq ($(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y)
+HOST_CLANG_ADD_TOOLCHAIN_DEPENDENCY = NO
+endif
+
 HOST_CLANG_DEPENDENCIES = host-llvm host-libxml2
 CLANG_DEPENDENCIES = llvm host-clang
 
diff --git a/toolchain/toolchain-buildroot/toolchain-buildroot.mk b/toolchain/toolchain-buildroot/toolchain-buildroot.mk
index b30cc332d2..da10ee2662 100644
--- a/toolchain/toolchain-buildroot/toolchain-buildroot.mk
+++ b/toolchain/toolchain-buildroot/toolchain-buildroot.mk
@@ -12,6 +12,13 @@ BR_LIBC = $(call qstrip,$(BR2_TOOLCHAIN_BUILDROOT_LIBC))
 
 TOOLCHAIN_BUILDROOT_DEPENDENCIES = host-gcc-final
 
+# Make sure the clang cross-compiler is built before
+# generating Buildroot.cmake file from an
+# TOOLCHAIN_CMAKE_INSTALL_FILES hook.
+ifeq ($(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y)
+TOOLCHAIN_BUILDROOT_DEPENDENCIES += host-clang
+endif
+
 TOOLCHAIN_BUILDROOT_ADD_TOOLCHAIN_DEPENDENCY = NO
 
 $(eval $(virtual-package))
diff --git a/toolchain/toolchain-external/toolchain-external.mk b/toolchain/toolchain-external/toolchain-external.mk
index dd07884c7e..a7157ce7fe 100644
--- a/toolchain/toolchain-external/toolchain-external.mk
+++ b/toolchain/toolchain-external/toolchain-external.mk
@@ -15,6 +15,13 @@ ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
 TOOLCHAIN_EXTERNAL_DEPENDENCIES += musl-compat-headers
 endif
 
+# Make sure the clang cross-compiler is built before
+# generating Buildroot.cmake file from an
+# TOOLCHAIN_CMAKE_INSTALL_FILES hook.
+ifeq ($(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y)
+TOOLCHAIN_BUILDROOT_DEPENDENCIES += host-clang
+endif
+
 $(eval $(virtual-package))
 
 # Ensure the external-toolchain package has a prefix defined.
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 10/11] toolchain: add a warning when Clang is used as cross-compiler
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (8 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 09/11] core: allow to use Clang as cross-compiler Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  2019-09-06  9:09 ` [Buildroot] [PATCH 11/11] linux: don't set -Wno-attribute-alias flag " Romain Naour
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 toolchain/Config.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/toolchain/Config.in b/toolchain/Config.in
index bd2c547ff1..570f029cac 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -37,6 +37,12 @@ config BR2_TOOLCHAIN_USES_MUSL
 	select BR2_TOOLCHAIN_HAS_UCONTEXT
 	select BR2_TOOLCHAIN_SUPPORTS_PIE if !BR2_STATIC_LIBS
 
+if BR2_USER_HOST_CLANG_AS_CROSS_COMPILER
+comment "-------------------------------------------------------"
+comment "Clang will be used as C/C++ cross-compiler !           "
+comment "-------------------------------------------------------"
+endif
+
 choice
 	prompt "Toolchain type"
 	help
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 11/11] linux: don't set -Wno-attribute-alias flag when Clang is used as cross-compiler
  2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
                   ` (9 preceding siblings ...)
  2019-09-06  9:09 ` [Buildroot] [PATCH 10/11] toolchain: add a warning when Clang is used " Romain Naour
@ 2019-09-06  9:09 ` Romain Naour
  10 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06  9:09 UTC (permalink / raw)
  To: buildroot

Clang stop the build due to -Werror and -Wunknown-warning-option:

error: unknown warning option '-Wno-attribute-alias'; did you mean '-Wattributes'? [-Werror,-Wunknown-warning-option]

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 linux/linux.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/linux/linux.mk b/linux/linux.mk
index d381c96d85..93d80d85e6 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -145,7 +145,8 @@ endif
 # abusing those aliases for system call entry points, in order to
 # sanitize the arguments passed from user space in registers.
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435
-ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
+# Clang doesn't support -Wno-attribute-alias
+ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8):$(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y:)
 LINUX_MAKE_ENV += KCFLAGS=-Wno-attribute-alias
 endif
 
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 06/11] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS
  2019-09-06  9:09 ` [Buildroot] [PATCH 06/11] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS Romain Naour
@ 2019-09-06 15:58   ` Romain Naour
  0 siblings, 0 replies; 17+ messages in thread
From: Romain Naour @ 2019-09-06 15:58 UTC (permalink / raw)
  To: buildroot

Hi all,

Le 06/09/2019 ? 11:09, Romain Naour a ?crit?:
> Using TARGET_CROSS expect using GCC compiler, instead use
> TARGET_CC and TARGET_CXX for the case where Clang is
> used as cross-compiler.
> 
> Signed-off-by: Romain Naour <romain.naour@smile.fr>
> Cc: Matt Weber <matthew.weber@rockwellcollins.com>
> Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
> ---
>  package/meson/cross-compilation.conf.in | 4 ++--
>  package/meson/meson.mk                  | 3 ++-
>  package/pkg-meson.mk                    | 3 ++-
>  3 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/package/meson/cross-compilation.conf.in b/package/meson/cross-compilation.conf.in
> index fc8e27f7eb..86347e9e4e 100644
> --- a/package/meson/cross-compilation.conf.in
> +++ b/package/meson/cross-compilation.conf.in
> @@ -4,8 +4,8 @@
>  # - Buildroot's 'target' is Meson's 'host'
>  
>  [binaries]
> -c = '@TARGET_CROSS at gcc'
> -cpp = '@TARGET_CROSS at g++'
> +c = '@TARGET_CC@'
> +cpp = '@TARGET_CXX@'
>  ar = '@TARGET_CROSS at ar'
>  strip = '@TARGET_CROSS at strip'
>  pkgconfig = '@HOST_DIR@/usr/bin/pkg-config'
> diff --git a/package/meson/meson.mk b/package/meson/meson.mk
> index 3267581fc6..1f836ef070 100644
> --- a/package/meson/meson.mk
> +++ b/package/meson/meson.mk
> @@ -54,7 +54,8 @@ HOST_MESON_SED_CXXFLAGS = $(if $(strip $(TARGET_CXXFLAGS)),`printf '"%s"$(comma)
>  # own flags if they need to.
>  define HOST_MESON_INSTALL_CROSS_CONF
>  	mkdir -p $(HOST_DIR)/etc/meson
> -	sed -e "s%@TARGET_CROSS@%$(TARGET_CROSS)%g" \

Sorry, we must keep TARGET_CROSS for other toolchain binaries (as etc).

> +	sed -e "s%@TARGET_CC@%$(TARGET_CC)%g" \
> +	    -e "s%@TARGET_CXX@%$(TARGET_CXX)%g" \

Only TARGET_CC and TARGET_CXX must be explicitly be set.

>  	    -e "s%@TARGET_ARCH@%$(HOST_MESON_TARGET_CPU_FAMILY)%g" \
>  	    -e "s%@TARGET_CPU@%$(HOST_MESON_TARGET_CPU)%g" \
>  	    -e "s%@TARGET_ENDIAN@%$(HOST_MESON_TARGET_ENDIAN)%g" \
> diff --git a/package/pkg-meson.mk b/package/pkg-meson.mk
> index 0b811d1cc0..9821636c28 100644
> --- a/package/pkg-meson.mk
> +++ b/package/pkg-meson.mk
> @@ -71,7 +71,8 @@ $(2)_MESON_SED_CXXFLAGS = $$(if $$(strip $$($(2)_CXXFLAGS)),`printf '"%s"$$(comm
>  define $(2)_CONFIGURE_CMDS
>  	rm -rf $$($$(PKG)_SRCDIR)/build
>  	mkdir -p $$($$(PKG)_SRCDIR)/build
> -	sed -e "s%@TARGET_CROSS@%$$(TARGET_CROSS)%g" \

Same here.

Best regards,
Romain

> +	sed -e "s%@TARGET_CC@%$(TARGET_CC)%g" \
> +	    -e "s%@TARGET_CXX@%$(TARGET_CXX)%g" \
>  	    -e "s%@TARGET_ARCH@%$$(HOST_MESON_TARGET_CPU_FAMILY)%g" \
>  	    -e "s%@TARGET_CPU@%$$(GCC_TARGET_CPU)%g" \
>  	    -e "s%@TARGET_ENDIAN@%$$(call LOWERCASE,$$(BR2_ENDIAN))%g" \
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler
  2019-09-06  9:09 ` [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler Romain Naour
@ 2019-09-07  3:11   ` Matthew Weber
  2019-09-07  3:17     ` Matthew Weber
  2019-09-07  8:02     ` Romain Naour
  0 siblings, 2 replies; 17+ messages in thread
From: Matthew Weber @ 2019-09-07  3:11 UTC (permalink / raw)
  To: buildroot

Romain,

On Fri, Sep 6, 2019 at 4:10 AM Romain Naour <romain.naour@smile.fr> wrote:
>
> Apply a patch contributed by Luis Marques on the Busybox mailing list [1]
> fixing a runtime issue (segfault) when busybox is compiled by Clang.
>
> The patch disable the compiler optimizations for Clang/LLVM only.
>
> Without this patch, busybox segfault with several applets
> (login on aarch64 using Clang 8.0.1, init on x86_64 using Clang 9.0.0rc3)
>
> [1] http://lists.busybox.net/pipermail/busybox/2019-June/087337.html
>

Got a "crtbegin.o no such file or directory" error when I setup a
build using master with qemu_aarch64_virt_defconfig (updated for
prebuilt external toolchain and enabling clang as cross-compiler).
https://paste.ubuntu.com/p/wxrmVTGVvp/

From your comment earlier on irc that you tested with 9.0.1 (x86_64
and aarch64), I wonder if this error is a difference between building
with clang 8.0.1 and 9.

I was able to build compiler-rt & libfuzzer with your series applied
and pass a runtime test (system still cross compiled with gcc but
using "[01/11] package/clang: help host-clang to find our external
toolchain" to find the sysroot).  This was instead of using the -B
option when building libfuzzer as part of the runtime test.

Matt

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler
  2019-09-07  3:11   ` Matthew Weber
@ 2019-09-07  3:17     ` Matthew Weber
  2019-09-07  8:02     ` Romain Naour
  1 sibling, 0 replies; 17+ messages in thread
From: Matthew Weber @ 2019-09-07  3:17 UTC (permalink / raw)
  To: buildroot

Romain,

On Fri, Sep 6, 2019 at 10:11 PM Matthew Weber
<matthew.weber@rockwellcollins.com> wrote:
>
> Romain,
>
> On Fri, Sep 6, 2019 at 4:10 AM Romain Naour <romain.naour@smile.fr> wrote:
> >
> > Apply a patch contributed by Luis Marques on the Busybox mailing list [1]
> > fixing a runtime issue (segfault) when busybox is compiled by Clang.
> >
> > The patch disable the compiler optimizations for Clang/LLVM only.
> >
> > Without this patch, busybox segfault with several applets
> > (login on aarch64 using Clang 8.0.1, init on x86_64 using Clang 9.0.0rc3)
> >
> > [1] http://lists.busybox.net/pipermail/busybox/2019-June/087337.html
> >
>
> Got a "crtbegin.o no such file or directory" error when I setup a
> build using master with qemu_aarch64_virt_defconfig (updated for
> prebuilt external toolchain and enabling clang as cross-compiler).
> https://paste.ubuntu.com/p/wxrmVTGVvp/
>

# find output/host/ -name  crtbegin.o
output/host/opt/ext-toolchain/lib/gcc/aarch64-linux-gnu/8.3.0/crtbegin.o
# output/host/bin/clang -print-search-dirs
programs: =/accts/mlweber1/tmp.M0HlOc7IKF-buildroot/output/host/bin:/..//bin
libraries: =/accts/mlweber1/tmp.M0HlOc7IKF-buildroot/output/host/lib/clang/8.0.1:/accts/mlweber1/tmp.M0HlOc7IKF-buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/lib/../lib64:/accts/mlweber1/tmp.M0HlOc7IKF-buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64:/accts/mlweber1/tmp.M0HlOc7IKF-buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/lib:/accts/mlweber1/tmp.M0HlOc7IKF-buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib


> From your comment earlier on irc that you tested with 9.0.1 (x86_64
> and aarch64), I wonder if this error is a difference between building
> with clang 8.0.1 and 9.
>
> I was able to build compiler-rt & libfuzzer with your series applied
> and pass a runtime test (system still cross compiled with gcc but
> using "[01/11] package/clang: help host-clang to find our external
> toolchain" to find the sysroot).  This was instead of using the -B
> option when building libfuzzer as part of the runtime test.
>
> Matt



-- 

Matthew Weber | Associate Director Software Engineer | Commercial Avionics

COLLINS AEROSPACE

400 Collins Road NE, Cedar Rapids, Iowa 52498, USA

Tel: +1 319 295 7349 | FAX: +1 319 263 6099

matthew.weber at collins.com | collinsaerospace.com



CONFIDENTIALITY WARNING: This message may contain proprietary and/or
privileged information of Collins Aerospace and its affiliated
companies. If you are not the intended recipient, please 1) Do not
disclose, copy, distribute or use this message or its contents. 2)
Advise the sender by return email. 3) Delete all copies (including all
attachments) from your computer. Your cooperation is greatly
appreciated.


Any export restricted material should be shared using my
matthew.weber at corp.rockwellcollins.com address.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler
  2019-09-07  3:11   ` Matthew Weber
  2019-09-07  3:17     ` Matthew Weber
@ 2019-09-07  8:02     ` Romain Naour
  2019-09-09 13:49       ` [Buildroot] [External] " Matthew Weber
  1 sibling, 1 reply; 17+ messages in thread
From: Romain Naour @ 2019-09-07  8:02 UTC (permalink / raw)
  To: buildroot

Hi Matt,

Le 07/09/2019 ? 05:11, Matthew Weber a ?crit?:
> Romain,
> 
> On Fri, Sep 6, 2019 at 4:10 AM Romain Naour <romain.naour@smile.fr> wrote:
>>
>> Apply a patch contributed by Luis Marques on the Busybox mailing list [1]
>> fixing a runtime issue (segfault) when busybox is compiled by Clang.
>>
>> The patch disable the compiler optimizations for Clang/LLVM only.
>>
>> Without this patch, busybox segfault with several applets
>> (login on aarch64 using Clang 8.0.1, init on x86_64 using Clang 9.0.0rc3)
>>
>> [1] http://lists.busybox.net/pipermail/busybox/2019-June/087337.html
>>
> 
> Got a "crtbegin.o no such file or directory" error when I setup a
> build using master with qemu_aarch64_virt_defconfig (updated for
> prebuilt external toolchain and enabling clang as cross-compiler).
> https://paste.ubuntu.com/p/wxrmVTGVvp/

Thanks for testing the series :)

Ok, the "crtbegin.o no such file or directory" error mean that realpath command
failed. It failed because the GCC external toolchain was not installed when the
realpath command is executed, this is due to :

# Allow host-clang to be build as part of the toolchain
ifeq ($(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y)
HOST_CLANG_ADD_TOOLCHAIN_DEPENDENCY = NO
endif

I fixed this issue by adding an explicit dependency on toolchain-external:

# Help host-clang to find our external toolchain, use a relative path from the clang
# installation directory to the external toolchain installation directory in
order to
# not hardcode the toolchain absolute path.
# Install the GCC external toolchain before executing realpath command.
ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
HOST_CLANG_DEPENDENCIES += toolchain-external
HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath
--relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`
endif

I'll send a v2 shortly.

> 
> From your comment earlier on irc that you tested with 9.0.1 (x86_64
> and aarch64), I wonder if this error is a difference between building
> with clang 8.0.1 and 9.

No no, that's me breaking my own patch :p

> 
> I was able to build compiler-rt & libfuzzer with your series applied
> and pass a runtime test (system still cross compiled with gcc but
> using "[01/11] package/clang: help host-clang to find our external
> toolchain" to find the sysroot).  This was instead of using the -B
> option when building libfuzzer as part of the runtime test.

That's great :)

I'll try to upstream the patch then. I think Clang doesn't like when the
toolchain sysroot is relocated because it doesn't seem to take into account the
GCC search patch.

Maybe your libfuzzer may be added at the end of the series (with a dependency on
Clang cross-compiler option)?

Best regards,
Romain

> 
> Matt
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Buildroot] [External] Re: [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler
  2019-09-07  8:02     ` Romain Naour
@ 2019-09-09 13:49       ` Matthew Weber
  0 siblings, 0 replies; 17+ messages in thread
From: Matthew Weber @ 2019-09-09 13:49 UTC (permalink / raw)
  To: buildroot

Romain,

On Sat, Sep 7, 2019 at 3:02 AM Romain Naour <romain.naour@smile.fr> wrote:
>
> Hi Matt,
>
> Le 07/09/2019 ? 05:11, Matthew Weber a ?crit :
> > Romain,
> >
> > On Fri, Sep 6, 2019 at 4:10 AM Romain Naour <romain.naour@smile.fr> wrote:
> >>
> >> Apply a patch contributed by Luis Marques on the Busybox mailing list [1]
> >> fixing a runtime issue (segfault) when busybox is compiled by Clang.
> >>
> >> The patch disable the compiler optimizations for Clang/LLVM only.
> >>
> >> Without this patch, busybox segfault with several applets
> >> (login on aarch64 using Clang 8.0.1, init on x86_64 using Clang 9.0.0rc3)
> >>
> >> [1] https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.busybox.net_pipermail_busybox_2019-2DJune_087337.html&d=DwIDaQ&c=ilBQI1lupc9Y65XwNblLtw&r=y1sOV0GV8NZUkffv7oCRxs2Sd3nOBS-NxDM3NY8lOgs&m=gE7oHor6AQZYHYD00ApKk2X5MH2LVRR_EyXIt5jiU4A&s=VKnAVOuzWWTy3aWJijmMwPLpl9NkHk2zZ5nx7u0A-mA&e=
> >>
> >
> > Got a "crtbegin.o no such file or directory" error when I setup a
> > build using master with qemu_aarch64_virt_defconfig (updated for
> > prebuilt external toolchain and enabling clang as cross-compiler).
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__paste.ubuntu.com_p_wxrmVTGVvp_&d=DwIDaQ&c=ilBQI1lupc9Y65XwNblLtw&r=y1sOV0GV8NZUkffv7oCRxs2Sd3nOBS-NxDM3NY8lOgs&m=gE7oHor6AQZYHYD00ApKk2X5MH2LVRR_EyXIt5jiU4A&s=8olVqcVp_os9SDrgZ_W2pw6WsPZiOXiJqkBAI8aqnAI&e=
>
> Thanks for testing the series :)
>
> Ok, the "crtbegin.o no such file or directory" error mean that realpath command
> failed. It failed because the GCC external toolchain was not installed when the
> realpath command is executed, this is due to :
>
> # Allow host-clang to be build as part of the toolchain
> ifeq ($(BR2_USER_HOST_CLANG_AS_CROSS_COMPILER),y)
> HOST_CLANG_ADD_TOOLCHAIN_DEPENDENCY = NO
> endif
>
> I fixed this issue by adding an explicit dependency on toolchain-external:
>
> # Help host-clang to find our external toolchain, use a relative path from the clang
> # installation directory to the external toolchain installation directory in
> order to
> # not hardcode the toolchain absolute path.
> # Install the GCC external toolchain before executing realpath command.
> ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
> HOST_CLANG_DEPENDENCIES += toolchain-external
> HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath
> --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`
> endif
>
> I'll send a v2 shortly.
>
> >
> > From your comment earlier on irc that you tested with 9.0.1 (x86_64
> > and aarch64), I wonder if this error is a difference between building
> > with clang 8.0.1 and 9.
>
> No no, that's me breaking my own patch :p
>
> >
> > I was able to build compiler-rt & libfuzzer with your series applied
> > and pass a runtime test (system still cross compiled with gcc but
> > using "[01/11] package/clang: help host-clang to find our external
> > toolchain" to find the sysroot).  This was instead of using the -B
> > option when building libfuzzer as part of the runtime test.
>
> That's great :)
>
> I'll try to upstream the patch then. I think Clang doesn't like when the
> toolchain sysroot is relocated because it doesn't seem to take into account the
> GCC search patch.
>
> Maybe your libfuzzer may be added at the end of the series (with a dependency on
> Clang cross-compiler option)?

I think the current compiler RT run-time test case is still valid as
you could use the libfuzzer as a way to test the compiler-rt is
working when your primary system is built with GCC.  However you do
have a point that libfuzzer could be added as a package when
compiler-rt is enabled and Clang is the cross-compiler.  I think I'd
still have to keep a copy in the run-time test br2-external for the
test case?

Matt

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-09-09 13:49 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06  9:09 [Buildroot] [PATCH 00/11] Add the support for Clang cross-compiler Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 01/11] package/clang: help host-clang to find our external toolchain Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 02/11] package/llvm: add the version major variable Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 03/11] package/clang: " Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 04/11] package/clang: install a toolchain-wrapper for the host clang cross-compiler Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 05/11] linux: override CC for the case CC is not GCC Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 06/11] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS Romain Naour
2019-09-06 15:58   ` Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 07/11] package/busybox: fix applets runtime issue when building with clang cross-compiler Romain Naour
2019-09-07  3:11   ` Matthew Weber
2019-09-07  3:17     ` Matthew Weber
2019-09-07  8:02     ` Romain Naour
2019-09-09 13:49       ` [Buildroot] [External] " Matthew Weber
2019-09-06  9:09 ` [Buildroot] [PATCH 08/11] package/clang: add a host entry for clang Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 09/11] core: allow to use Clang as cross-compiler Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 10/11] toolchain: add a warning when Clang is used " Romain Naour
2019-09-06  9:09 ` [Buildroot] [PATCH 11/11] linux: don't set -Wno-attribute-alias flag " Romain Naour

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.