[U-Boot] [RFC] [PATCH] Avoid R_ARM_ABS32 for bss start and end references

Albert ARIBAUD albert.u.boot at aribaud.net
Tue Feb 12 18:27:27 CET 2013


This patch is intended to be patch 2/2 of my first patch to remove
R_ARM_ABS32 relocation types from ARM builds.

With this change, the type of ARM references to __bss_start
and __bss_end__ is changed from R_ARM_ABS32 to R_ARM_RELATIVE.
It should have no functional impact, as it only affects the
resolution of references to __bss_start and __bss_end__ before
relocation, and no code should ever perform such references...
so far. References performed after relocation are unchanged by
this patch.

This patch SHOULD NOT BE applied in any official U-boot tree! It is
submitted as an RFC and a request to test.

This patch can only work on ARM; it will not work on any ARM target
that uses another linker script than arch/arm/cpu/u-boot.lds, and it
will not work on any non-ARM target.

HOWEVER, if you can test it on one of these targets, then please do
so by manually patching the appropriate linker script the same way
arch/arm/cpu/u-boot.lds is patched here.

If you are keen on testing but don't know how to patch your linker
script, just let me know which target you intend to test on, and which
linker script you need patched, and I'll do a v2 / v3... of this RFC.

The goal here is to help me ensure the patch works well on enough
targets that I can safely start the tedious work of patching all 150+
linker scripts.
---
 arch/arm/cpu/u-boot.lds |   12 +++++++++---
 lib/Makefile            |    1 +
 lib/bss.c               |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 lib/bss.c

diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index e6b202b..e1bc8e7 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -81,11 +81,17 @@ SECTIONS
 		*(.mmutable)
 	}
 
-	.bss __rel_dyn_start (OVERLAY) : {
-		__bss_start = .;
+	.bss_start __rel_dyn_start (OVERLAY) : {
+		KEEP(*(.__bss_start));
+	}
+
+	.bss __bss_start (OVERLAY) : {
 		*(.bss*)
 		 . = ALIGN(4);
-		__bss_end__ = .;
+		 ___bssend___ = .;
+	}
+	.bss_end ___bssend___ (OVERLAY) : {
+		KEEP(*(.__bss_end__));
 	}
 
 	/DISCARD/ : { *(.dynstr*) }
diff --git a/lib/Makefile b/lib/Makefile
index 86ca1a6..73ee160 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)libgeneric.o
 
+COBJS-y += bss.o
 ifndef CONFIG_SPL_BUILD
 COBJS-$(CONFIG_ADDR_MAP) += addr_map.o
 COBJS-$(CONFIG_BCH) += bch.o
diff --git a/lib/bss.c b/lib/bss.c
new file mode 100644
index 0000000..5678f30
--- /dev/null
+++ b/lib/bss.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2013 Albert ARIBAUD <albert.u.boot at aribaud.net>
+ * 
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/**
+ * These two symbols are declared in a C file so that the linker
+ * uses R_ARM_RELATIVE relocation, rather than the R_ARM_ABS32 one
+ * it would use if the symbols were defined in the linker file.
+ * Using only R_ARM_RELATIVE relocation ensures that references to
+ * the symbols are correct after as well as before relocation.
+ * 
+ * As the symbols do not require any content, and as we cannot define
+ * them as 'void', we go for the next best thing, 'struct {}'.
+ */
+
+struct {} __bss_start __attribute__((used,section(".__bss_start")));
+struct {} __bss_end__ __attribute__((used,section(".__bss_end__")));
-- 
1.7.10.4



More information about the U-Boot mailing list