public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sam Edwards <cfsworks@gmail.com>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	u-boot@lists.denx.de, trini@konsulko.com
Cc: caleb.connolly@linaro.org, sumit.garg@linaro.org,
	Simon Glass <sjg@chromium.org>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Kever Yang <kever.yang@rock-chips.com>,
	Michal Simek <michal.simek@amd.com>,
	Yegor Yefremov <yegorslists@googlemail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Shiji Yang <yangshiji66@outlook.com>,
	Bin Meng <bmeng@tinylab.org>
Subject: Re: [PATCH 2/6] arm: clean up v7 and v8 linker scripts for bss_start/end
Date: Wed, 6 Mar 2024 00:32:56 -0700	[thread overview]
Message-ID: <6c502584-df1c-44e4-9fa4-70d73a4ae07e@gmail.com> (raw)
In-Reply-To: <20240304090113.1410575-3-ilias.apalodimas@linaro.org>

On 3/4/24 02:01, Ilias Apalodimas wrote:
> commit 3ebd1cbc49f0 ("arm: make __bss_start and __bss_end__ compiler-generated")
> and
> commit f84a7b8f54db ("ARM: Fix __bss_start and __bss_end in linker scripts")
> were moving the bss_start/end on c generated variables that were
> injected in their own sections. The reason was that we needed relative
> relocations for position independent code and linker bugs back then
> prevented us from doing so.
> 
> However, the linker documentation pages states that symbols that are
> defined within a section definition will create a relocatable
> type with the value being a fixed offset from the base of a section.
> This have been fixed since 2016 [1]. So let's start cleaning this up
> starting with the bss_start and bss_end variables. Convert them into
> symbols within the .bss section definition.
> 
> [0] https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_mono/ld.html#SEC13
> [1] commit 6b3b0ab89663 ("Make linker assigned symbol dynamic only for shared object")
> 
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Tested-by: Caleb Connolly <caleb.connolly@linaro.org> # Qualcomm sdm845
> ---
>   arch/arm/cpu/armv8/u-boot-spl.lds        | 14 +++-----------
>   arch/arm/cpu/armv8/u-boot.lds            | 15 +++------------
>   arch/arm/cpu/u-boot.lds                  | 22 ++++------------------
>   arch/arm/lib/sections.c                  |  2 --
>   arch/arm/mach-rockchip/u-boot-tpl-v8.lds | 14 +++-----------
>   arch/arm/mach-zynq/u-boot.lds            | 21 +++------------------
>   6 files changed, 16 insertions(+), 72 deletions(-)
> 
> diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds b/arch/arm/cpu/armv8/u-boot-spl.lds
> index 7cb9d731246d..16fddb46e9cb 100644
> --- a/arch/arm/cpu/armv8/u-boot-spl.lds
> +++ b/arch/arm/cpu/armv8/u-boot-spl.lds
> @@ -63,18 +63,10 @@ SECTIONS
>   
>   	_image_binary_end = .;
>   
> -	.bss_start (NOLOAD) : {
> -		. = ALIGN(8);
> -		KEEP(*(.__bss_start));
> -	} >.sdram
> -
> -	.bss (NOLOAD) : {
> +	.bss : {
> +		__bss_start = .;
>   		*(.bss*)
> -		 . = ALIGN(8);
> -	} >.sdram
> -
> -	.bss_end (NOLOAD) : {
> -		KEEP(*(.__bss_end));
> +		__bss_end = .;
>   	} >.sdram
>   
>   	/DISCARD/ : { *(.rela*) }
> diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
> index fb6a30c922f7..c4ee10ebc3ff 100644
> --- a/arch/arm/cpu/armv8/u-boot.lds
> +++ b/arch/arm/cpu/armv8/u-boot.lds
> @@ -149,19 +149,10 @@ SECTIONS
>   
>   	_end = .;
>   
> -	. = ALIGN(8);
> -
> -	.bss_start : {
> -		KEEP(*(.__bss_start));
> -	}
> -
> -	.bss : {
> +	.bss ALIGN(8): {
> +		__bss_start = .;
>   		*(.bss*)
> -		 . = ALIGN(8);
> -	}
> -
> -	.bss_end : {
> -		KEEP(*(.__bss_end));
> +		__bss_end = .;
>   	}
>   
>   	/DISCARD/ : { *(.dynsym) }
> diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
> index 7724c9332c3b..90d329b1ebe0 100644
> --- a/arch/arm/cpu/u-boot.lds
> +++ b/arch/arm/cpu/u-boot.lds
> @@ -206,27 +206,13 @@ SECTIONS
>   		*(.mmutable)
>   	}
>   
> -/*
> - * Compiler-generated __bss_start and __bss_end, see arch/arm/lib/bss.c
> - * __bss_base and __bss_limit are for linker only (overlay ordering)
> - */
> -
> -	.bss_start __rel_dyn_start (OVERLAY) : {
> -		KEEP(*(.__bss_start));
> -		__bss_base = .;
> -	}
> -
> -	.bss __bss_base (OVERLAY) : {
> +	.bss ALIGN(4): {

Hi Ilias,

I have been reviewing this patchset by diffing output binaries and 
linker maps between successive patches. Most of the patches in this 
series result in no change to the output binary whatsoever (which also 
means, no regressions!) but this one does have a change: .bss is being 
moved after .mmutable. You should be able to see this yourself by 
comparing `u-boot.map` after a successful build, before and after 
applying this patch.

Since the current u-boot.lds puts .bss right after __image_copy_end 
(which makes sense) and uses OVERLAY to overlap .rel.dyn (which... I 
guess makes sense, if U-Boot zero-initializes .bss after applying 
relocations), perhaps this patch should be moving the .bss section up 
there in the .lds, putting (OVERLAY) back, and adding a comment to the 
effect of "These sections occupy the same memory, but their lifetimes do 
not overlap: U-Boot initializes .bss only after applying relocations and 
therefore after it doesn't need .rel.dyn any more."

We might also decide that the overlay memory-saving trick isn't actually 
all that important anymore and that .bss should have a new home. Someone 
far more seasoned than I should be the one to make that decision though.

The rest of the patchset looks great! I'll add my tags to those in a bit.

Cheers,
Sam

> +		__bss_start = .;
>   		*(.bss*)
> -		 . = ALIGN(4);
> -		 __bss_limit = .;
> -	}
> -
> -	.bss_end __bss_limit (OVERLAY) : {
> -		KEEP(*(.__bss_end));
> +		__bss_end = .;
>   	}
>   
> -	.dynsym _image_binary_end : { *(.dynsym) }
> +	.dynsym  : { *(.dynsym) }
>   	.dynbss : { *(.dynbss) }
>   	.dynstr : { *(.dynstr*) }
>   	.dynamic : { *(.dynamic*) }
> diff --git a/arch/arm/lib/sections.c b/arch/arm/lib/sections.c
> index 857879711c6a..8e8bd5797e16 100644
> --- a/arch/arm/lib/sections.c
> +++ b/arch/arm/lib/sections.c
> @@ -19,8 +19,6 @@
>    * aliasing warnings.
>    */
>   
> -char __bss_start[0] __section(".__bss_start");
> -char __bss_end[0] __section(".__bss_end");
>   char __image_copy_start[0] __section(".__image_copy_start");
>   char __image_copy_end[0] __section(".__image_copy_end");
>   char __rel_dyn_start[0] __section(".__rel_dyn_start");
> diff --git a/arch/arm/mach-rockchip/u-boot-tpl-v8.lds b/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
> index 74618eba591b..b7887194026e 100644
> --- a/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
> +++ b/arch/arm/mach-rockchip/u-boot-tpl-v8.lds
> @@ -56,18 +56,10 @@ SECTIONS
>   
>   	_image_binary_end = .;
>   
> -	.bss_start (NOLOAD) : {
> -		. = ALIGN(8);
> -		KEEP(*(.__bss_start));
> -	}
> -
> -	.bss (NOLOAD) : {
> +	.bss ALIGN(8) : {
> +		__bss_start = .;
>   		*(.bss*)
> -		 . = ALIGN(8);
> -	}
> -
> -	.bss_end (NOLOAD) : {
> -		KEEP(*(.__bss_end));
> +		__bss_end = .;
>   	}
>   
>   	/DISCARD/ : { *(.dynsym) }
> diff --git a/arch/arm/mach-zynq/u-boot.lds b/arch/arm/mach-zynq/u-boot.lds
> index 3b7c9d515f8b..8d3259821719 100644
> --- a/arch/arm/mach-zynq/u-boot.lds
> +++ b/arch/arm/mach-zynq/u-boot.lds
> @@ -102,26 +102,11 @@ SECTIONS
>   
>   	_image_binary_end = .;
>   
> -/*
> - * Compiler-generated __bss_start and __bss_end, see arch/arm/lib/bss.c
> - * __bss_base and __bss_limit are for linker only (overlay ordering)
> - */
> -
> -	.bss_start __rel_dyn_start (OVERLAY) : {
> -		KEEP(*(.__bss_start));
> -		__bss_base = .;
> -	}
> -
> -	.bss __bss_base (OVERLAY) : {
> +	.bss ALIGN(4): {
> +		__bss_start = .;
>   		*(.bss*)
> -		 . = ALIGN(8);
> -		 __bss_limit = .;
> -	}
> -
> -	.bss_end __bss_limit (OVERLAY) : {
> -		KEEP(*(.__bss_end));
> +		__bss_end = .;
>   	}
> -
>   	/*
>   	 * Zynq needs to discard these sections because the user
>   	 * is expected to pass this image on to tools for boot.bin

  reply	other threads:[~2024-03-06  7:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04  9:01 [PATCH 0/6] Clean up arm linker scripts Ilias Apalodimas
2024-03-04  9:01 ` [PATCH 1/6] arm: baltos: remove custom linker script Ilias Apalodimas
2024-03-04  9:01 ` [PATCH 2/6] arm: clean up v7 and v8 linker scripts for bss_start/end Ilias Apalodimas
2024-03-06  7:32   ` Sam Edwards [this message]
2024-03-06  9:08     ` Ilias Apalodimas
2024-03-06 10:11       ` Ilias Apalodimas
2024-03-04  9:01 ` [PATCH 3/6] arm: fix __efi_runtime_rel_start/end definitions Ilias Apalodimas
2024-03-06  7:35   ` Sam Edwards
2024-03-04  9:01 ` [PATCH 4/6] arm: clean up v7 and v8 linker scripts for __rel_dyn_start/end Ilias Apalodimas
2024-03-06  7:35   ` Sam Edwards
2024-03-04  9:01 ` [PATCH 5/6] arm: fix __efi_runtime_start/end definitions Ilias Apalodimas
2024-03-06  8:14   ` Sam Edwards
2024-03-06  9:13     ` Ilias Apalodimas
2024-03-06 22:19       ` Sam Edwards
2024-03-07  6:50         ` Ilias Apalodimas
2024-03-08 13:22           ` Ilias Apalodimas
2024-03-08 14:14             ` Ilias Apalodimas
2024-03-08 15:10               ` Ilias Apalodimas
2024-03-04  9:01 ` [PATCH 6/6] arm: move image_copy_start/end to linker symbols Ilias Apalodimas
2024-03-06  8:22   ` Sam Edwards
2024-03-06  9:35     ` Ilias Apalodimas
2024-03-06 10:37       ` Ilias Apalodimas
2024-03-06 13:23         ` Ilias Apalodimas
2024-03-06 23:08           ` Sam Edwards
2024-03-07  6:55             ` Ilias Apalodimas
2024-03-07 16:45               ` Ilias Apalodimas

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=6c502584-df1c-44e4-9fa4-70d73a4ae07e@gmail.com \
    --to=cfsworks@gmail.com \
    --cc=bmeng@tinylab.org \
    --cc=caleb.connolly@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kever.yang@rock-chips.com \
    --cc=michal.simek@amd.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=sumit.garg@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    --cc=yangshiji66@outlook.com \
    --cc=yegorslists@googlemail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox