From patchwork Sun Mar 7 04:25:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1448591 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.a=rsa-sha256 header.s=default header.b=OLmtQhge; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DtT7j1FhHz9sW8 for ; Sun, 7 Mar 2021 15:31:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 27504828B3; Sun, 7 Mar 2021 05:27:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="OLmtQhge"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8DF0782842; Sun, 7 Mar 2021 05:26:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.2 Received: from mail.nic.cz (mail.nic.cz [IPv6:2001:1488:800:400::400]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 10A6D827D2 for ; Sun, 7 Mar 2021 05:26:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=nic.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.behun@nic.cz Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTPSA id A8FA5140ADF; Sun, 7 Mar 2021 05:26:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1615091168; bh=iMUxiParYgRbBTOo3Ycq4qUonQzx7Xo99eEZZb4MiHE=; h=From:To:Date; b=OLmtQhgeCI26eHCikM4nqAq0cpMCnIDWLjuvC8v3OW6UkHYcKQegaV9yE4LRB++8+ gy+LvxctRI3Z579vnsS8AdO7WQwO54ApBnw5y5BkYL9Bf/ljKGkixf0bJou1D1zlxS Hd2FOxCLZ+I0hXF8Fb7t7dP8i40VgCCDH8l243vs= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de, Simon Glass , Heiko Schocher , Patrick Delaunay , Patrice CHOTARD , Miquel Raynal , Tom Rini , =?utf-8?q?Pali_Roh=C3=A1r?= , Stefan Roese , Heinrich Schuchardt , Alexander Graf , Marek Vasut , Neil Armstrong , Ryder Lee , Adam Ford , Bin Meng Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot 20/39] sandbox: use sections instead of symbols for getopt array boundaries Date: Sun, 7 Mar 2021 05:25:19 +0100 Message-Id: <20210307042538.21229-21-marek.behun@nic.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210307042538.21229-1-marek.behun@nic.cz> References: <20210307042538.21229-1-marek.behun@nic.cz> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean In style of linked lists, instead of declaring symbols for boundaries of getopt options array in the linker script, declare corresponding sections and retrieve the boundaries via static inline functions. Without this clang's LTO produces binary without any getopt options, because for some reason it thinks that array is empty (start and end symbols are at the same address). Signed-off-by: Marek BehĂșn --- arch/sandbox/cpu/os.c | 3 ++- arch/sandbox/cpu/start.c | 3 ++- arch/sandbox/cpu/u-boot-spl.lds | 8 +++++--- arch/sandbox/cpu/u-boot.lds | 8 +++++--- arch/sandbox/include/asm/sections.h | 21 ++++++++++++++++++--- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 3d8af0a52b..6d4fecee1d 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -327,7 +327,8 @@ static struct option *long_opts; int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) { - struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start; + struct sandbox_cmdline_option **sb_opt = + __u_boot_sandbox_option_start(); size_t num_options = __u_boot_sandbox_option_count(); size_t i; diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 483a264040..05dc04d43a 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -58,7 +58,8 @@ static int h_compare_opt(const void *p1, const void *p2) int sandbox_early_getopt_check(void) { struct sandbox_state *state = state_get_current(); - struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start; + struct sandbox_cmdline_option **sb_opt = + __u_boot_sandbox_option_start(); size_t num_options = __u_boot_sandbox_option_count(); size_t i; int max_arg_len, max_noarg_len; diff --git a/arch/sandbox/cpu/u-boot-spl.lds b/arch/sandbox/cpu/u-boot-spl.lds index 649abeb5ee..3a86595e85 100644 --- a/arch/sandbox/cpu/u-boot-spl.lds +++ b/arch/sandbox/cpu/u-boot-spl.lds @@ -13,9 +13,11 @@ SECTIONS KEEP(*(SORT(.u_boot_list*))); } - __u_boot_sandbox_option_start = .; - _u_boot_sandbox_getopt : { KEEP(*(.u_boot_sandbox_getopt)) } - __u_boot_sandbox_option_end = .; + _u_boot_sandbox_getopt : { + *(.u_boot_sandbox_getopt_start) + KEEP(*(.u_boot_sandbox_getopt)) + *(.u_boot_sandbox_getopt_end) + } } INSERT AFTER .data; diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds index 936da5e140..1d917a3244 100644 --- a/arch/sandbox/cpu/u-boot.lds +++ b/arch/sandbox/cpu/u-boot.lds @@ -13,9 +13,11 @@ SECTIONS KEEP(*(SORT(.u_boot_list*))); } - __u_boot_sandbox_option_start = .; - _u_boot_sandbox_getopt : { *(.u_boot_sandbox_getopt) } - __u_boot_sandbox_option_end = .; + _u_boot_sandbox_getopt : { + *(.u_boot_sandbox_getopt_start) + *(.u_boot_sandbox_getopt) + *(.u_boot_sandbox_getopt_end) + } .__efi_runtime_start : { *(.__efi_runtime_start) diff --git a/arch/sandbox/include/asm/sections.h b/arch/sandbox/include/asm/sections.h index fbc1bd11a3..f4351ae7db 100644 --- a/arch/sandbox/include/asm/sections.h +++ b/arch/sandbox/include/asm/sections.h @@ -13,12 +13,27 @@ struct sandbox_cmdline_option; -extern struct sandbox_cmdline_option *__u_boot_sandbox_option_start[], - *__u_boot_sandbox_option_end[]; +static inline struct sandbox_cmdline_option ** +__u_boot_sandbox_option_start(void) +{ + static char start[0] __aligned(4) __attribute__((unused)) + __section(".u_boot_sandbox_getopt_start"); + + return (struct sandbox_cmdline_option **)&start; +} + +static inline struct sandbox_cmdline_option ** +__u_boot_sandbox_option_end(void) +{ + static char end[0] __aligned(4) __attribute__((unused)) + __section(".u_boot_sandbox_getopt_end"); + + return (struct sandbox_cmdline_option **)&end; +} static inline size_t __u_boot_sandbox_option_count(void) { - return __u_boot_sandbox_option_end - __u_boot_sandbox_option_start; + return __u_boot_sandbox_option_end() - __u_boot_sandbox_option_start(); } #endif