From patchwork Sat Sep 7 09:40:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Naour X-Patchwork-Id: 1159304 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=smile.fr Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=smile-fr.20150623.gappssmtp.com header.i=@smile-fr.20150623.gappssmtp.com header.b="RXScq54f"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46QTv64C49z9sP3 for ; Sat, 7 Sep 2019 19:40:50 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 2EAA388049; Sat, 7 Sep 2019 09:40:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sDK5I+WiFKF5; Sat, 7 Sep 2019 09:40:44 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 00EF188543; Sat, 7 Sep 2019 09:40:44 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 877661BF86C for ; Sat, 7 Sep 2019 09:40:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 13A9488002 for ; Sat, 7 Sep 2019 09:40:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OzCFI65UUVrD for ; Sat, 7 Sep 2019 09:40:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by hemlock.osuosl.org (Postfix) with ESMTPS id 3E37087F5D for ; Sat, 7 Sep 2019 09:40:36 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id y135so9070274wmc.1 for ; Sat, 07 Sep 2019 02:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smile-fr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Awondix1XoRsidClA3CSOyfkyZgEmufT4O/89xh6LnA=; b=RXScq54fH5iLgjHF6IdhPIczMp0aDe/AdX7JCL2XI6jVQCbUIZYdyLWUshoxm8CkY5 H/3jNcbvtck1V7cBgb3wH0oDqfJbnzdu9lFEL0gM12r6WIZDjRQooioFubZ0BgCXJvAP PLQagXlLOAAkguWGyT+ufTC9q+30FcRWeE6geJUuS6T4CGc33uaOqf1ZBjcRk+nIZg9i vu5lqFYvzUGffteKS0TxAhb2giUr4/ibAH7+gAmLWjZWgzJEdwxMbinV3T5qFKYk2WBM 65GVpeVH151NlJZHE6K5k7xK/cVWsSDeXYQLRwB553ilfpBtR4Quy3WoNwx1kbcljb29 6vNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Awondix1XoRsidClA3CSOyfkyZgEmufT4O/89xh6LnA=; b=lUQJ4gybIiLHxnGuQ9pNxCsZbi8yvE5eF6TtKbajmG6etkgRRgli48vsTuhI7W25HI RCjr9kig3o2P7LF/4J0X2etdgMZU3t0kvU/Lg6qtUjnHyQEQezskp2UDnGjALcP8NW2x tJkmoujEseuS/j8HWcRd19nSOmUaOMuF/l05YQdtSPOteMx0K89pSupo8JIt4HrryGr5 OODpxSPXjsl84JUGRFenopWFssI53RLxbt+6boB5F3Tr6X1aOSn3IvbSC/nWucsNrXth vgD2sCryQol13fPDPzAgHaMOr8eT2WLKiiN8Mtg42I79cV88iD9nAs9Tau9YYTxpXKI0 iNlw== X-Gm-Message-State: APjAAAV6W2yu1nvsuqx7NgpRUFHt0Rudmlvx4yy8Q7zOof559NAgvyAg p8L4SADUocqLiZ03I3yBCHOJFlJMyy8= X-Google-Smtp-Source: APXvYqxYwIUAN+mgpl0LSMaZ7nG1nd3ANrWjjg43FXiMEyygpCchDthPuau45K2aVOFigyd2lwY7Bw== X-Received: by 2002:a1c:f607:: with SMTP id w7mr10886729wmc.84.1567849234193; Sat, 07 Sep 2019 02:40:34 -0700 (PDT) Received: from P-ASN-Evian.home (2a01cb0589880c00c543929d43aec786.ipv6.abo.wanadoo.fr. [2a01:cb05:8988:c00:c543:929d:43ae:c786]) by smtp.gmail.com with ESMTPSA id f13sm6384700wrq.3.2019.09.07.02.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Sep 2019 02:40:33 -0700 (PDT) From: Romain Naour To: buildroot@buildroot.org Date: Sat, 7 Sep 2019 11:40:16 +0200 Message-Id: <20190907094027.9537-2-romain.naour@smile.fr> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190907094027.9537-1-romain.naour@smile.fr> References: <20190907094027.9537-1-romain.naour@smile.fr> MIME-Version: 1.0 Subject: [Buildroot] [PATCH v2 01/12] package/clang: help host-clang to find our external toolchain X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Naour , Valentin Korenblit Errors-To: buildroot-bounces@busybox.net Sender: "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 Cc: Matthew Weber Cc: Valentin Korenblit Tested-by: Matt Weber --- 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 +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/-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 +--- +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))