Avoid R_ARM_ABS32 for bss start and end references
Subsystems (2)
RFC PATCH 1/1 Avoid R_ARM_ABS32 for bss start and end references
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
arch/arm/cpu/u-boot.lds +9 -3
@@ -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*) }
lib/Makefile +1 -0
@@ -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
lib/bss.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright 2013 Albert ARIBAUD <[email protected]> +* +* 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__")));
Signature · 1 line
1.7.10.4
RFC PATCH 1/1 Avoid R_ARM_ABS32 for bss start and end references
Quoted 2 lines · Albert ARIBAUD
This patch SHOULD NOT BE applied in any official U-boot tree! It is submitted as an RFC and a request to test.
I can confirm that this patch applied on top of 9c748e0 worked for my two kirkwood boards. One is in mainline (ib62x0) and one is not.
RFC PATCH 1/1 Avoid R_ARM_ABS32 for bss start and end references -- tester(s) needed for non-ARM architectures also
Hi Luka,
Quoted 8 lines · Luka Perkov
Quoted 2 lines · Albert ARIBAUD
This patch SHOULD NOT BE applied in any official U-boot tree! It is submitted as an RFC and a request to test.
I can confirm that this patch applied on top of 9c748e0 worked for my two kirkwood boards. One is in mainline (ib62x0) and one is not.
Tested-by Luka Perkov <[email protected]>
Thanks Luka!
Anyone available to test on a non-ARM architecture? I can provide the patched linker script if testing on a mainline-supported target.
Amicalement,
Signature · 1 line
Albert.
RFC PATCH 1/1 Avoid R_ARM_ABS32 for bss start and end references -- tester(s) needed for non-ARM architectures also
Hi Albert,
Quoted 12 lines · Albert ARIBAUD
Hi Luka,
Quoted 7 lines · Luka Perkov
Quoted 2 lines · Albert ARIBAUD
This patch SHOULD NOT BE applied in any official U-boot tree! It is submitted as an RFC and a request to test.
I can confirm that this patch applied on top of 9c748e0 worked for my two kirkwood boards. One is in mainline (ib62x0) and one is not.
Quoted 6 lines
Quoted 1 line
Tested-by Luka Perkov <[email protected]>Thanks Luka!
Anyone available to test on a non-ARM architecture? I can provide the patched linker script if testing on a mainline-supported target.
I can on AVR32, would you provide the linker script (atstk1002 preferred, but AFAIR all AVR32 targets use the same linker script)? I think we should apply this change on top of "Refactor linker-generated arrays", am I right?
Best regards
Andreas Bie?mann
RFC PATCH 1/1 Avoid R_ARM_ABS32 for bss start and end references -- tester(s) needed for non-ARM architectures also
Hi Andreas,
Quoted 17 lines · Andreas Bie?mann
Hi Albert,
Quoted 14 lines · Albert ARIBAUD
Hi Luka,
Quoted 8 lines · Luka Perkov
Quoted 2 lines · Albert ARIBAUD
This patch SHOULD NOT BE applied in any official U-boot tree! It is submitted as an RFC and a request to test.
I can confirm that this patch applied on top of 9c748e0 worked for my two kirkwood boards. One is in mainline (ib62x0) and one is not.
Tested-by Luka Perkov <[email protected]>
Quoted 7 lines
Quoted 4 lines
Thanks Luka!
Anyone available to test on a non-ARM architecture? I can provide the patched linker script if testing on a mainline-supported target.
I can on AVR32, would you provide the linker script (atstk1002 preferred, but AFAIR all AVR32 targets use the same linker script)?
Yes, there is a single linker script for AVR. Do you have a URL handy for the AVR toolchain you're using?
Quoted 2 lines
I think we should apply this change on top of "Refactor linker-generated arrays", am I right?
It uses the same methods as the linker lists one, and eventually it will be part of the series, but it is autonomous -- no need to apply anything else.
Thanks for your help!
Quoted 3 lines
Best regards
Andreas Bie?mann
Amicalement,
Signature · 1 line
Albert.
RFC PATCH 1/1 Avoid R_ARM_ABS32 for bss start and end references -- tester(s) needed for non-ARM architectures also
Hi Albert,
Quoted 7 lines · Albert ARIBAUD
Hi Andreas,
Quoted 2 lines · Andreas Bie?mann
Hi Albert,
Quoted 7 lines
Quoted 4 lines · Albert ARIBAUD
I can on AVR32, would you provide the linker script (atstk1002 preferred, but AFAIR all AVR32 targets use the same linker script)?
Yes, there is a single linker script for AVR. Do you have a URL handy for the AVR toolchain you're using?
No, I use a self patched OSELAS toolchain, I like to push the changes mainline but haven't managed yet.
I know buildroot and openwrt has toolchain support for avr32 and AFAIR Mike Frysinger has a set of pre-compiled toolchains including a AVR32 one [1].
Quoted 7 lines
Quoted 3 lines
I think we should apply this change on top of "Refactor linker-generated arrays", am I right?
It uses the same methods as the linker lists one, and eventually it will be part of the series, but it is autonomous -- no need to apply anything else.
Ok.
Best regards
Andreas Bie?mann
[1] http://article.gmane.org/gmane.comp.boot-loaders.u-boot/117404