]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: clean up v7 and v8 linker scripts for bss_start/end
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Fri, 15 Mar 2024 06:43:46 +0000 (08:43 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 29 Mar 2024 14:39:25 +0000 (10:39 -0400)
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 [0].

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 [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] binutils commit 6b3b0ab89663 ("Make linker assigned symbol dynamic only for shared object")
[1] https://sourceware.org/binutils/docs/ld/Expression-Section.html

Tested-by: Caleb Connolly <caleb.connolly@linaro.org> # Qualcomm sdm845
Tested-by: Sam Edwards <CFSworks@gmail.com> # Binary output identical
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
arch/arm/cpu/armv8/u-boot-spl.lds
arch/arm/cpu/armv8/u-boot.lds
arch/arm/cpu/u-boot.lds
arch/arm/lib/sections.c
arch/arm/mach-rockchip/u-boot-tpl-v8.lds
arch/arm/mach-zynq/u-boot.lds

index 7cb9d731246d0fe98b4d330d79c02a3daf9bd46e..8998c4985eac9a060d27a6a65ea53b03e1d09540 100644 (file)
@@ -63,18 +63,11 @@ 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));
+               . = ALIGN(8);
+               __bss_end = .;
        } >.sdram
 
        /DISCARD/ : { *(.rela*) }
@@ -89,3 +82,6 @@ SECTIONS
 #include "linux-kernel-image-header-vars.h"
 #endif
 }
+
+ASSERT(ADDR(.bss) % 8 == 0, \
+       ".bss must be 8-byte aligned");
index fb6a30c922f724026d7b89b0403b3145a4559c77..9640cc7a04b8cf25b68f25526c5eca6d544c8ab2 100644 (file)
@@ -149,19 +149,11 @@ SECTIONS
 
        _end = .;
 
-       . = ALIGN(8);
-
-       .bss_start : {
-               KEEP(*(.__bss_start));
-       }
-
-       .bss : {
+       .bss ALIGN(8): {
+               __bss_start = .;
                *(.bss*)
-                . = ALIGN(8);
-       }
-
-       .bss_end : {
-               KEEP(*(.__bss_end));
+               . = ALIGN(8);
+               __bss_end = .;
        }
 
        /DISCARD/ : { *(.dynsym) }
index 7724c9332c3b012d08b7df05612ae28e5aa528e6..0dfe5f633b16e2044fd884bdc666a8ff1e7024e6 100644 (file)
@@ -207,23 +207,15 @@ SECTIONS
        }
 
 /*
- * Compiler-generated __bss_start and __bss_end, see arch/arm/lib/bss.c
- * __bss_base and __bss_limit are for linker only (overlay ordering)
+ * These sections occupy the same memory, but their lifetimes do
+ * not overlap: U-Boot initializes .bss only after applying dynamic
+ * relocations and therefore after it doesn't need .rel.dyn any more.
  */
-
-       .bss_start __rel_dyn_start (OVERLAY) : {
-               KEEP(*(.__bss_start));
-               __bss_base = .;
-       }
-
-       .bss __bss_base (OVERLAY) : {
+       .bss ADDR(.rel.dyn) (OVERLAY): {
+               __bss_start = .;
                *(.bss*)
-                . = ALIGN(4);
-                __bss_limit = .;
-       }
-
-       .bss_end __bss_limit (OVERLAY) : {
-               KEEP(*(.__bss_end));
+               . = ALIGN(4);
+               __bss_end = .;
        }
 
        .dynsym _image_binary_end : { *(.dynsym) }
index 857879711c6a83574a12299501bb56e2687d3db8..8e8bd5797e1681ac9bd8283c57a4092a2bee4e0e 100644 (file)
@@ -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");
index 74618eba591b3f565e49116298824c19a6457465..712c485d4d0b90b3702095a61f9d5074a33216b4 100644 (file)
@@ -56,18 +56,11 @@ 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));
+               . = ALIGN(8);
+               __bss_end = .;
        }
 
        /DISCARD/ : { *(.dynsym) }
index 3b7c9d515f8b80d26c1cb7e92b57e3a3c2da4b19..3c5008b57392e3a0298042512caf15e08ae6a3ec 100644 (file)
@@ -103,23 +103,15 @@ 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)
+ * These sections occupy the same memory, but their lifetimes do
+ * not overlap: U-Boot initializes .bss only after applying dynamic
+ * relocations and therefore after it doesn't need .rel.dyn any more.
  */
-
-       .bss_start __rel_dyn_start (OVERLAY) : {
-               KEEP(*(.__bss_start));
-               __bss_base = .;
-       }
-
-       .bss __bss_base (OVERLAY) : {
+       .bss ADDR(.rel.dyn) (OVERLAY): {
+               __bss_start = .;
                *(.bss*)
-                . = ALIGN(8);
-                __bss_limit = .;
-       }
-
-       .bss_end __bss_limit (OVERLAY) : {
-               KEEP(*(.__bss_end));
+               . = ALIGN(8);
+               __bss_end = .;
        }
 
        /*