All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <marek.behun@nic.cz>
To: u-boot@lists.denx.de
Subject: [PATCH u-boot v4 17/36] sandbox: use sections instead of symbols for getopt array boundaries
Date: Thu, 20 May 2021 13:24:06 +0200	[thread overview]
Message-ID: <20210520112425.25166-18-marek.behun@nic.cz> (raw)
In-Reply-To: <20210520112425.25166-1-marek.behun@nic.cz>

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 <marek.behun@nic.cz>
---
 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 b9ad341861..0d21827e1b 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -375,7 +375,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 e87365e800..63ca514ebd 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 18160436a3..6754f4ef6c 100644
--- a/arch/sandbox/cpu/u-boot-spl.lds
+++ b/arch/sandbox/cpu/u-boot-spl.lds
@@ -21,9 +21,11 @@ SECTIONS
 		__priv_data_end = .;
 	}
 
-	__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 a1f509c9ab..6d710618f5 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
-- 
2.26.3

  parent reply	other threads:[~2021-05-20 11:24 UTC|newest]

Thread overview: 111+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20 11:23 [PATCH u-boot v4 00/36] U-Boot LTO (Sandbox + Some ARM boards) Marek Behún
2021-05-20 11:23 ` [PATCH u-boot v4 01/36] regmap: fix a serious pointer casting bug Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-20 19:30     ` Marek Behun
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 02/36] checkpatch: require quotes around section name in the __section() macro Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 03/36] treewide: Convert macro and uses of __section(foo) to __section("foo") Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 04/36] compiler.h: align the __ADDRESSABLE macro with Linux' version Marek Behún
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 05/36] test/py: improve regular expression for ut subtest symbol matcher Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 06/36] string: make memcpy(), memset(), memcmp() and memmove() visible for LTO Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 07/36] efi_loader: fix warning when linking with LTO Marek Behún
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 08/36] efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data Marek Behún
2021-05-25  0:54   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 09/36] efi_loader: add macro for const EFI runtime data Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:23 ` [PATCH u-boot v4 10/36] efi_selftest: compiler flags for efi_selftest_miniapp_exception.o Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 11/36] lib: crc32: put the crc_table variable into efi_runtime_rodata section Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 12/36] Makefile, Makefile.spl: cosmetic change Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 13/36] build: use thin archives instead of incremental linking Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 14/36] build: support building with Link Time Optimizations Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 15/36] build: link with --build-id=none Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 16/36] sandbox: errno: avoid conflict with libc's errno Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` Marek Behún [this message]
2021-05-20 17:51   ` [PATCH u-boot v4 17/36] sandbox: use sections instead of symbols for getopt array boundaries Simon Glass
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 18/36] sandbox: make LTO available Marek Behún
2021-05-25  0:55   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 19/36] sandbox: enable LTO by default Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 20/36] ARM: global_data: make set_gd() work for armv5 and armv6 Marek Behún
2021-05-20 17:51   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 21/36] ARM: make gd a function call for LTO and set via set_gd() Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 22/36] ARM: fix LTO build for some thumb-interwork cases Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 23/36] ARM: fix LTO for imx28_xea Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 24/36] ARM: fix LTO for apf27 Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 25/36] ARM: fix LTO for keystone Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 26/36] ARM: kona: fix clk_bsc_enable() type mismatch for LTO Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 27/36] ARM: imx8m: fix imx_eqos_txclk_set_rate() " Marek Behún
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 28/36] ARM: fix LTO for seaboard Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 29/36] ARM: fix LTO for rockchip and samsung Marek Behún
2021-05-22  2:45   ` Kever Yang
2021-05-25  0:56   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 30/36] ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards) Marek Behún
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 31/36] armv8: SPL: discard relocation information Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 32/36] ata: ahci: fix ahci_link_up() type mismatch for LTO Marek Behún
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 33/36] ARM: make LTO available Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 34/36] ARM: don't use -ffunction-sections/-fdata-sections with LTO build Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 35/36] ARM: don't use --gc-sections with LTO when using private libgcc Marek Behún
2021-05-20 17:52   ` Simon Glass
2021-05-25  0:57   ` Tom Rini
2021-05-20 11:24 ` [PATCH u-boot v4 36/36] ARM: enable LTO for some boards Marek Behún
2021-05-20 18:56   ` Adam Ford
2021-05-21 14:11     ` Tom Rini
2021-05-21 16:00       ` Marek Behún
2021-05-21 16:56         ` Tom Rini
2021-05-24 15:40           ` Tom Rini
2021-05-24 15:58             ` Marek Behun
2021-05-24 16:23               ` Tom Rini
2021-05-24 17:09               ` Tom Rini
2021-05-24 17:44                 ` Tom Rini
2021-05-24 19:19                   ` Marek Behun
2021-05-24 19:56                     ` Tom Rini
2021-05-24 19:54               ` Tom Rini
2021-05-21 16:00       ` Marek Behún
2021-05-25  0:57   ` Tom Rini
2021-06-01 14:59 ` [PATCH u-boot v4 00/36] U-Boot LTO (Sandbox + Some ARM boards) Patrick DELAUNAY
2021-06-01 15:05   ` Tom Rini
2021-06-01 16:22   ` Marek Behún
2021-06-01 16:55     ` Heinrich Schuchardt
2021-06-01 17:23       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210520112425.25166-18-marek.behun@nic.cz \
    --to=marek.behun@nic.cz \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.