From patchwork Sat Sep 7 09:40:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Naour X-Patchwork-Id: 1159315 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.138; helo=whitealder.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="yyzF1gkM"; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46QTvT5pvrz9sNk for ; Sat, 7 Sep 2019 19:41:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 4DEBF87DF2; Sat, 7 Sep 2019 09:41:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ykjCV9rGTGtN; Sat, 7 Sep 2019 09:41:02 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 7916287E35; Sat, 7 Sep 2019 09:40:59 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id B65011BF401 for ; Sat, 7 Sep 2019 09:40:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id A049020767 for ; Sat, 7 Sep 2019 09:40:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id M24BVkfSCA7N for ; Sat, 7 Sep 2019 09:40:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by silver.osuosl.org (Postfix) with ESMTPS id 810BD204B7 for ; Sat, 7 Sep 2019 09:40:45 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id g207so8787540wmg.5 for ; Sat, 07 Sep 2019 02:40:45 -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=gFb3uIKy5QSf2QNnS1TK76TKwLGxBZTV6hfz+bPG7/Y=; b=yyzF1gkMyb1AqZ+BF8/aB1t8QXtKgmDPe7peTRWjUUuR6Q/cc13xU4eeDQGYmHDn/u 2tdcMbo1Mp1LW+VNfHxxleDRDzjjDW9FGkhWK0+O9h5cc5GJcZukWfdh4SFOgW1yAEMc WtS/Rd1a2judGCEEU7etlRvgm8KfJ2+N7/uR38n/RZNQOCAQTRTN/a2+7P2AQ549V8Ku Oo59sdmZJFDKfTWZE/BlNFF7PO8wF2Wek5JvD4z1wBslspj586dOi3YCeC5knmeqk2TN tyi0l1jP1Oqf65AIenfVBPFdj93G/u5kyzLzJPcT4nOuhuYn6Ob6/JwlJirP0kCjJt4J lnyQ== 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=gFb3uIKy5QSf2QNnS1TK76TKwLGxBZTV6hfz+bPG7/Y=; b=VO5YnJmThMTGgrYkD1y6JYPJn6Q91d+hH/2CECiHozSAPbv8UwsQBAJYA7Up4+F0bu LQjYYUnIawn5S4VnWqVHcXCqh3wiQHN7ous+fGxTdLbxuzygfzYTLFI3rnObhGAOTNoz q9LZfy+Xs876OC1p/S6trYhY+wS1GEzDqlKsP3Fkjump14lLufNyXZLlnTJeFqqCZ6Nn D4XYbxId27T/wbgj3cMEwbOBn2596/eT2Jr+FOxDqf/v9sRouX4KK3e6E5JThq80YLfV hrA029+YTpspbrGzr7ztcGApNAKL/UZWbPShrCN/n5aAv1YzuG4q6wgWCM8loK9dYisV 4W4A== X-Gm-Message-State: APjAAAWEoMwtLAjjK0qAO4X0G/x1qDrJQyb/iqmA4z6sd6gtVGEYqs8O uM2kbKx7zJ33LviOr9285LRYEU0heT4= X-Google-Smtp-Source: APXvYqzGtZ09OugwpjF7N4+McElfuGpuXCZaOZ8fOk3fYxX38xTkpTQbTMYZzBG8fh3/2AAeu92TlA== X-Received: by 2002:a1c:f50c:: with SMTP id t12mr11003089wmh.49.1567849243855; Sat, 07 Sep 2019 02:40:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Sep 2019 02:40:43 -0700 (PDT) From: Romain Naour To: buildroot@buildroot.org Date: Sat, 7 Sep 2019 11:40:25 +0200 Message-Id: <20190907094027.9537-11-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 10/12] core: allow to use Clang as cross-compiler 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" 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 virtual package 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). Buildroot.cmake can be used by a cmake package as soon as the toolchain package is installed. Install the GCC external toolchain before executing realpath command by adding an explicit dependency on toolchain-external. Without this dependency, host-clang may be build before toolchain-external when BR2_USER_HOST_CLANG_AS_CROSS_COMPILER=y, so the realpath fail to set GCC_INSTALL_PREFIX leading to "crtbegin.o no such file or directory" error while linking applications. Only Glibc toolchain has been tested. Signed-off-by: Romain Naour Cc: Matt Weber Cc: Valentin Korenblit Tested-by: Matt Weber --- v2: fix typo TOOLCHAIN_{BUILDROOT,EXTERNAL}_DEPENDENCIES in toolchain-external.mk Install the GCC external toolchain before executing realpath command. Move host-clang dependency to toolchain virtual package since host-clang now depends on external-toolchain. Add Glibc toolchain dependency --- Config.in | 23 +++++++++++++++++++++++ package/Makefile.in | 13 ++++++++++--- package/clang/clang.mk | 7 +++++++ toolchain/toolchain/toolchain.mk | 7 +++++++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Config.in b/Config.in index a6e280b885..dc2e5f7320 100644 --- a/Config.in +++ b/Config.in @@ -711,6 +711,29 @@ 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_TOOLCHAIN_USES_GLIBC + 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). + + Note: Only Glibc toolchain has been tested. + 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..36703f5d8a 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 @@ -106,7 +111,9 @@ 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. +# 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 diff --git a/toolchain/toolchain/toolchain.mk b/toolchain/toolchain/toolchain.mk index 17fb62147e..d945e27aac 100644 --- a/toolchain/toolchain/toolchain.mk +++ b/toolchain/toolchain/toolchain.mk @@ -10,6 +10,13 @@ else ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y) TOOLCHAIN_DEPENDENCIES += toolchain-external 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_DEPENDENCIES += host-clang +endif + TOOLCHAIN_ADD_TOOLCHAIN_DEPENDENCY = NO # Apply a hack that Rick Felker suggested[1] to avoid conflicts between libc