From patchwork Sat Sep 7 09:40:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Naour X-Patchwork-Id: 1159313 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.136; helo=silver.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="cpUEgiK1"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46QTvR3NgMz9sNk for ; Sat, 7 Sep 2019 19:41:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D74E0203AB; Sat, 7 Sep 2019 09:41:05 +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 igRColqvF2eU; Sat, 7 Sep 2019 09:40:53 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id AB8482051E; Sat, 7 Sep 2019 09:40:53 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id ED2181BF401 for ; Sat, 7 Sep 2019 09:40:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id E93C687D93 for ; Sat, 7 Sep 2019 09:40:43 +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 lgrRFl8U3RkO for ; Sat, 7 Sep 2019 09:40:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by whitealder.osuosl.org (Postfix) with ESMTPS id A683486DB3 for ; Sat, 7 Sep 2019 09:40:42 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id c10so8828492wmc.0 for ; Sat, 07 Sep 2019 02:40:42 -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=x4S40M8tAuJhekZswjdehjjEqkc4pVqvlfjViTcHWUU=; b=cpUEgiK15aWE75L7xjbc+p4BzZ0HjTaH/v8YUsgz/OFNbOI7sdtJQD20GsfhOGT2Jr MXlCBSQ9PJjS2Sk4UU8OUSWYPOxc5635SyJNMvPBr3xRvW3H/Sajv15PkO66wAztvgdB QpuKEkluhWHJnetL/BLBaa0BvBiQUscrQrGsZ/31AjEIlbcqEPURpbP6sf4lrOvAFIvb Qzmss9qhue2Ba4t2ErXpUC56DWIVFxUifUUvfLPIYfzs6t8ShNN65zAl5/oh585vJsB2 2tqLKueU5pSsRohGpw7dHvXoVVrlB1V6w5ygpJRyZX/0q8Kc1DVWiJlHQpFFI06GuF+9 FWgQ== 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=x4S40M8tAuJhekZswjdehjjEqkc4pVqvlfjViTcHWUU=; b=jgCpvq6HH5GBo+grVgb5d3U9Lc4bkJxmijiGDO1ybSgigyQCJj5GxmgenAKqaa7PqP or1Q+Wi0zkI4drFqhhELRw3zQpuMlJ/O+8AyZRBaPHLyhpq2DcJCZwKGCQC+7irtj6U3 35C5N57ft4Qu1CxpRL7eWUPUvfV0Jn2Otymg9mQneYcHfU2+ozMxgRUiHyhNWLcg2I/P 8sH83eTlya1hijWF5YNiMpqEdYhmtmDIRPOrJmUC8dSofYwqvHnOY6juqllX9AdaywV5 +6+658+dLhFUzx+5hQyuSE7RaE4T8YlJuB2WhTeSsIyNr3sQQ8ItGNWprhnkf+FDCwWD FmGg== X-Gm-Message-State: APjAAAWvTR9CmM+h/z2cfSzkTD5m1HWOScL3/UNmYEKV/nEcsMf8lOL4 7a8Kaqtv5sI9Ug038oTMu7xYECoKIOs= X-Google-Smtp-Source: APXvYqz0SBlnfH6DOXQwjCa069yZUUEnnP1IAUq5SQYU0eZEp4s0+kHRp8VdiUMC+zTh1/Gr4FTTwA== X-Received: by 2002:a1c:a74f:: with SMTP id q76mr11187382wme.16.1567849240961; Sat, 07 Sep 2019 02:40:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Sep 2019 02:40:40 -0700 (PDT) From: Romain Naour To: buildroot@buildroot.org Date: Sat, 7 Sep 2019 11:40:22 +0200 Message-Id: <20190907094027.9537-8-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 07/12] package/busybox: fix applets runtime issue when building with clang 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: Luis Marques , Romain Naour , Valentin Korenblit Errors-To: buildroot-bounces@busybox.net Sender: "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 Cc: Luis Marques Cc: Matt Weber Cc: Valentin Korenblit Tested-by: Matt Weber --- 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 +Date: Wed, 4 Sep 2019 17:48:39 +0200 +Subject: [PATCH] use BB_GLOBAL_CONST where applicable + +Signed-off-by: Romain Naour +--- + 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 +