Skip to contentSkip to conversation

Fix all linker scripts for older binutils versions (pre-2.16)

PATCH New Wolfgang Denk 2 participants 15 messages Aug 17, 2009 – Aug 23, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Commit f62fb99941c6 fixed handling of all rodata sections by using a wildcard combined with calls to ld's builtin functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(). Unfortunately these functions were only introduced with biunutils version 2.16, so the modification broke building with all tool chains using older binutils.

This patch makes it work again. This is done by omitting the use of these functions for such old tool chains. This will result in slightly larger target binaries, as the rodata sections are no longer in optimal order alignment-wise which reauls in unused gaps, but the effect was found to be insignificant - especially compared to the fact that you cannot build U-Boot at all in the current state.

As ld seems to have no support for conditionals we run the linker script through the C preprocessor which can be easily used to remove the unwanted function calls.

Note that the C preprocessor must be run with the "-ansi" (or a "-std=") option to make sure all the system-specific predefined macros outside the reserved namespace are suppressed. Otherise, cpp might for example substitute "powerpc" to "1", thus corrupting for example "OUTPUT_ARCH(powerpc)" etc.

---
Compile tested on ARM and PPC, with ELDK 3.1, 3.1.1, 4.1 and 4.2, on ARM both with and without USE_PRIVATE_LIBGCC=yes.

I'm not sure if this is to be considered a bug fix (if you have to use an older tool chain, it certainly solves a serious problem of the current code) and should go into the current release, or if we should rather wait with this for the next version. Comments welcome.

Mike, I am aware that Blackfin is already using the C preprocessor to generate it's linker scripts. I guess this step can now be folded into this general mechanism. Do you want to provide such a patch, or shall I do it?

 Makefile                                      |   15 +++++++++++----
 board/netstar/Makefile                        |    9 ++++++---
 board/voiceblue/Makefile                      |   11 +++++++----
 config.mk                                     |   12 +++++++++++-
 nand_spl/board/amcc/acadia/Makefile           |    7 +++++--
 nand_spl/board/amcc/bamboo/Makefile           |    7 +++++--
 nand_spl/board/amcc/canyonlands/Makefile      |    7 +++++--
 nand_spl/board/amcc/kilauea/Makefile          |    7 +++++--
 nand_spl/board/amcc/sequoia/Makefile          |    7 +++++--
 nand_spl/board/freescale/mpc8313erdb/Makefile |    7 +++++--
 nand_spl/board/freescale/mx31pdk/Makefile     |    7 +++++--
 nand_spl/board/samsung/smdk6400/Makefile      |    7 +++++--
 nand_spl/board/sheldon/simpc8313/Makefile     |    7 +++++--
 onenand_ipl/board/apollon/Makefile            |    7 +++++--
 15 files changed, 86 insertions(+), 33 deletions(-)
Makefile +11 -4
index 329e0f5..2636ac0 100644
@@ -326,11 +326,13 @@ GEN_UBOOT = \
 		cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
 			--start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
 			-Map u-boot.map -o u-boot
-$(obj)u-boot:		depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT)
+$(obj)u-boot:	depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
 		$(GEN_UBOOT)
 ifeq ($(CONFIG_KALLSYMS),y)
-		smap=`$(call SYSTEM_MAP,u-boot) | awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \
-		$(CC) $(CFLAGS) -DSYSTEM_MAP="\"$${smap}\"" -c common/system_map.c -o $(obj)common/system_map.o
+		smap=`$(call SYSTEM_MAP,u-boot) | \
+			awk '$$2 ~ /[tTwW]/ {printf $$1 $$3 "\\\\000"}'` ; \
+		$(CC) $(CFLAGS) -DSYSTEM_MAP="\"$${smap}\"" \
+			-c common/system_map.c -o $(obj)common/system_map.o
 		$(GEN_UBOOT) $(obj)common/system_map.o
 endif
 
@@ -349,6 +351,9 @@ $(SUBDIRS):	depend
 $(LDSCRIPT):	depend
 		$(MAKE) -C $(dir $@) $(notdir $@)
 
+$(obj)u-boot.lds: $(LDSCRIPT)
+		$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 $(NAND_SPL):	$(TIMESTAMP_FILE) $(VERSION_FILE) $(obj)include/autoconf.mk
 		$(MAKE) -C nand_spl/board/$(BOARDDIR) all
 
@@ -3653,10 +3658,12 @@ clean:
 	       $(obj)board/trab/trab_fkt   $(obj)board/voiceblue/eeprom   \
 	       $(obj)board/armltd/{integratorap,integratorcp}/u-boot.lds  \
 	       $(obj)lib_blackfin/u-boot.lds				  \
+	       $(obj)u-boot.lds						  \
 	       $(obj)cpu/blackfin/bootrom-asm-offsets.[chs]
 	@rm -f $(obj)include/bmp_logo.h
-	@rm -f $(obj)nand_spl/{u-boot-spl,u-boot-spl.map,System.map}
+	@rm -f $(obj)nand_spl/{u-boot.lds,u-boot-spl,u-boot-spl.map,System.map}
 	@rm -f $(obj)onenand_ipl/onenand-{ipl,ipl.bin,ipl-2k.bin,ipl-4k.bin,ipl.map}
+	@rm -f $(obj)onenand_ipl/u-boot.lds
 	@rm -f $(TIMESTAMP_FILE) $(VERSION_FILE)
 	@find $(OBJTREE) -type f \
 		\( -name 'core' -o -name '*.bak' -o -name '*~' \
board/netstar/Makefile +6 -3
index 8f35f93..11578b7 100644
@@ -50,8 +50,8 @@ all:	$(obj).depend $(LIB) $(obj)eeprom.srec $(obj)eeprom.bin \
 $(LIB):	$(OBJS) $(SOBJS)
 	$(AR) $(ARFLAGS) $@ $^
 
-$(obj)eeprom.srec:	$(obj)eeprom.o $(obj)eeprom_start.o
-	cd $(lnk) && $(LD) -T $(LDSCRIPT) -g -Ttext $(LOAD_ADDR) \
+$(obj)eeprom.srec:	$(obj)eeprom.o $(obj)eeprom_start.o $(obj)u-boot.lds
+	cd $(lnk) && $(LD) -T $(obj)u-boot.lds -g -Ttext $(LOAD_ADDR) \
 		-o $(<:.o=) -e eeprom eeprom.o eeprom_start.o \
 		-L$(obj)../../examples/standalone -lstubs \
 		-L$(obj)../../lib_generic -lgeneric \
@@ -78,10 +78,13 @@ $(obj)crcit.o:	crcit.c
 $(obj)crc32.o:	$(SRCTREE)/lib_generic/crc32.c
 	$(HOSTCC) $(HOSTCFLAGS) -DUSE_HOSTCC -o $@ -c $<
 
+$(obj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 clean:
 	rm -f $(SOBJS) $(OBJS) $(obj)eeprom $(obj)eeprom.srec \
 		$(obj)eeprom.bin $(obj)crcek $(obj)crcek.srec \
-		$(obj)crcek.bin
+		$(obj)crcek.bin $(obj)u-boot.lds
 
 distclean:	clean
 	rm -f $(LIB) core *.bak $(obj).depend
board/voiceblue/Makefile +7 -4
index 7bb92a6..121c717 100644
@@ -44,8 +44,8 @@ all:	$(obj).depend $(LIB) $(obj)eeprom.srec $(obj)eeprom.bin
 $(LIB):	$(OBJS) $(SOBJS)
 	$(AR) $(ARFLAGS) $@ $(OBJS) $(SOBJS)
 
-$(obj)eeprom.srec:	$(obj)eeprom.o $(obj)eeprom_start.o
-	cd $(lnk) && $(LD) -T $(LDSCRIPT) -g -Ttext $(LOAD_ADDR) \
+$(obj)eeprom.srec:	$(obj)eeprom.o $(obj)eeprom_start.o $(obj)u-boot.lds
+	cd $(lnk) && $(LD) -T $(obj)u-boot.lds -g -Ttext $(LOAD_ADDR) \
 		-o $(<:.o=) -e eeprom eeprom.o eeprom_start.o \
 		-L$(obj)../../examples/standalone -lstubs \
 		-L$(obj)../../lib_generic -lgeneric \
@@ -55,11 +55,14 @@ $(obj)eeprom.srec:	$(obj)eeprom.o $(obj)eeprom_start.o
 $(obj)eeprom.bin:	$(obj)eeprom.srec
 	$(OBJCOPY) -I srec -O binary $< $@ 2>/dev/null
 
+$(obj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 clean:
 	rm -f $(SOBJS) $(OBJS) $(obj)eeprom \
 		$(obj)eeprom.srec $(obj)eeprom.bin \
-		$(obj)eeprom.o $(obj)eeprom_start.o
-
+		$(obj)eeprom.o $(obj)eeprom_start.o \
+		 $(obj)u-boot.lds
 
 distclean:	clean
 	rm -f $(LIB) core *.bak $(obj).depend
config.mk +11 -1
index 0c6d1d1..7bc7315 100644
@@ -166,11 +166,21 @@ endif
 
 AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
 
-LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS)
+LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
 ifneq ($(TEXT_BASE),)
 LDFLAGS += -Ttext $(TEXT_BASE)
 endif
 
+# Special flags for CPP when processing the linker script
+# Linker versions prior to 2.16 don't understand the builting
+# functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
+ifeq ($(shell $(LD) -v | \
+	sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/[ \1 -lt 2 ] || [ \2 -lt 16 ] \&\& echo old_ld/p' | \
+	sh),old_ld)
+LDPPFLAGS += -D'SORT_BY_ALIGNMENT(x)=x' -D'SORT_BY_NAME(x)=x'
+endif
+
+
 # Location of a usable BFD library, where we define "usable" as
 # "built for ${HOST}, supports ${TARGET}".  Sensible values are
 # - When cross-compiling: the root of the cross-environment
nand_spl/board/amcc/acadia/Makefile +5 -2
index 822f82f..f37425e 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -50,7 +50,7 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
@@ -60,6 +60,9 @@ $(nandobj)System.map:	$(nandobj)u-boot-spl
 		grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
 		sort > $(nandobj)System.map
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 # from cpu directory
nand_spl/board/amcc/bamboo/Makefile +5 -2
index 2932927..5fcf290 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -49,11 +49,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 # from cpu directory
nand_spl/board/amcc/canyonlands/Makefile +5 -2
index 84b1454..f77e459 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -54,11 +54,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 # from cpu directory
nand_spl/board/amcc/kilauea/Makefile +5 -2
index 8a062fe..bc21744 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -49,11 +49,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 # from cpu directory
nand_spl/board/amcc/sequoia/Makefile +5 -2
index 462005f..54ea7c7 100644
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -49,11 +49,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 # from cpu directory
nand_spl/board/freescale/mpc8313erdb/Makefile +5 -2
index 1a8f6ff..a13e7e2 100644
@@ -29,7 +29,7 @@ PAD_TO := 0xfff04000
 include $(TOPDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -54,11 +54,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 $(obj)start.S:
nand_spl/board/freescale/mx31pdk/Makefile +5 -2
index a9572ba..0e13d5d 100644
@@ -4,7 +4,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_PRELOADER -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_PRELOADER -DCONFIG_NAND_SPL
 
@@ -30,11 +30,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $@
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 #########################################################################
 
 $(obj)%.o:	$(SRCTREE)/cpu/arm1136/%.S
nand_spl/board/samsung/smdk6400/Makefile +5 -2
index ae9eb2a..0fdda25 100644
@@ -30,7 +30,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -54,11 +54,14 @@ $(nandobj)u-boot-spl-16k.bin: $(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 # from cpu directory
nand_spl/board/sheldon/simpc8313/Makefile +5 -2
index 20199c7..6920fe8 100644
@@ -29,7 +29,7 @@ TEXT_BASE := 0xfff00000
 include $(TOPDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(nandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_NAND_SPL
 
@@ -54,11 +54,14 @@ $(nandobj)u-boot-spl-16k.bin:	$(nandobj)u-boot-spl
 $(nandobj)u-boot-spl.bin:	$(nandobj)u-boot-spl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(nandobj)u-boot-spl:	$(OBJS)
+$(nandobj)u-boot-spl:	$(OBJS) $(nandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS) \
 		-Map $(nandobj)u-boot-spl.map \
 		-o $(nandobj)u-boot-spl
 
+$(nandobj)u-boot.lds: $(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links for common files
 
 $(obj)start.S:
onenand_ipl/board/apollon/Makefile +5 -2
index 49a8e90..193efff 100644
@@ -3,7 +3,7 @@ include $(TOPDIR)/config.mk
 include $(TOPDIR)/onenand_ipl/board/$(BOARDDIR)/config.mk
 
 LDSCRIPT= $(TOPDIR)/onenand_ipl/board/$(BOARDDIR)/u-boot.onenand.lds
-LDFLAGS	= -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
+LDFLAGS	= -Bstatic -T $(onenandobj)u-boot.lds -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
 AFLAGS	+= -DCONFIG_PRELOADER -DCONFIG_ONENAND_IPL
 CFLAGS	+= -DCONFIG_PRELOADER -DCONFIG_ONENAND_IPL
 OBJCFLAGS += --gap-fill=0x00
@@ -34,10 +34,13 @@ $(onenandobj)onenand-ipl-4k.bin:	$(onenandobj)onenand-ipl
 $(onenandobj)onenand-ipl.bin:	$(onenandobj)onenand-ipl
 	$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
 
-$(onenandobj)onenand-ipl:	$(OBJS)
+$(onenandobj)onenand-ipl:	$(OBJS) $(onenandobj)u-boot.lds
 	cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
 		-Map [email protected] -o $@
 
+$(onenandobj)u-boot.lds:	$(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links from common files
 
 # from cpu directory
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Quoted 4 lines · On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:

Mike, I am aware that Blackfin is already using the C preprocessor to generate it's linker scripts. I guess this step can now be folded into this general mechanism. Do you want to provide such a patch, or shall I do it?

toolchains that are older than binutils-2.17 wont work with the Blackfin port, so compatibility with pre-2.16 isnt something this port needs to worry about -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090817/37d9b50e/attachment.pgp

#2 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Dear Mike,

Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 5 lines

Mike, I am aware that Blackfin is already using the C preprocessor to generate it's linker scripts. I guess this step can now be folded into this general mechanism. Do you want to provide such a patch, or shall I do it?

toolchains that are older than binutils-2.17 wont work with the Blackfin port, so compatibility with pre-2.16 isnt something this port needs to worry about

Agreed, but the cpp step is now _always_ performed, and in your case twice - first in your board directory, and then again by the top level Makefile. You could save the local run now.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
God runs electromagnetics by wave theory on  Monday,  Wednesday,  and
Friday,  and the Devil runs them by quantum theory on Tuesday, Thurs-
day, and Saturday.                                   -- William Bragg
#3 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Quoted 6 lines · On Monday 17 August 2009 15:31:30 Wolfgang Denk wrote:
Quoted 5 lines · Mike
Quoted 4 lines

Mike, I am aware that Blackfin is already using the C preprocessor to generate it's linker scripts. I guess this step can now be folded into this general mechanism. Do you want to provide such a patch, or shall I do it?

Quoted 7 lines
Quoted 3 lines

toolchains that are older than binutils-2.17 wont work with the Blackfin port, so compatibility with pre-2.16 isnt something this port needs to worry about

Agreed, but the cpp step is now _always_ performed, and in your case twice - first in your board directory, and then again by the top level Makefile. You could save the local run now.

ok, i missed that aspect. i think the changes needed are:

lib_blackfin/Makefile:

	-$(obj)u-boot.lds: u-boot.lds.S
	-   $(CPP) $(CPPFLAGS) -D__ASSEMBLY__ -P $^ > $@
lib_blackfin/config.mk:
	-LDSCRIPT = $(obj)lib_$(ARCH)/u-boot.lds
	+LDSCRIPT = $(obj)lib_$(ARCH)/u-boot.lds.S

i can post a patch once yours gets merged
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090817/05d6cb28/attachment.pgp

#4 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Dear Mike Frysinger,

Quoted 4 lines · In message <[email protected]> you wrote:
Quoted 3 lines

twice - first in your board directory, and then again by the top level Makefile. You could save the local run now.

Quoted 8 lines

ok, i missed that aspect. i think the changes needed are:

lib_blackfin/Makefile:

	-$(obj)u-boot.lds: u-boot.lds.S
	-   $(CPP) $(CPPFLAGS) -D__ASSEMBLY__ -P $^ > $@
lib_blackfin/config.mk:
	-LDSCRIPT = $(obj)lib_$(ARCH)/u-boot.lds
	+LDSCRIPT = $(obj)lib_$(ARCH)/u-boot.lds.S

Right. I just have no easy way to test this...

Quoted 1 line

i can post a patch once yours gets merged

Thanks a lot in advance.

There is a slight difference, though - I'm calling CPP with the "-ansi" switch to make sure that all system-specific predefined macros outside the reserved namespace are suppressed, i. e. only those starting with double-underscores will be seen. I am pretty sure that this is actually what you want, too.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Our business is run on trust.  We trust you will pay in advance.
#5 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Quoted 5 lines · On Monday 17 August 2009 16:24:45 Wolfgang Denk wrote:

There is a slight difference, though - I'm calling CPP with the "-ansi" switch to make sure that all system-specific predefined macros outside the reserved namespace are suppressed, i. e. only those starting with double-underscores will be seen. I am pretty sure that this is actually what you want, too.

afaik, i only rely on __XXX__ defines from the toolchain and no XXX. if it does break something, that's good anyways so i can go fix it ;).
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090817/4c60ff1d/attachment.pgp

author Applied
#6 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

In reply to Wolfgang Denk
Quoted 41 lines · In message <[email protected]> I wrote:

Commit f62fb99941c6 fixed handling of all rodata sections by using a wildcard combined with calls to ld's builtin functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(). Unfortunately these functions were only introduced with biunutils version 2.16, so the modification broke building with all tool chains using older binutils.

This patch makes it work again. This is done by omitting the use of these functions for such old tool chains. This will result in slightly larger target binaries, as the rodata sections are no longer in optimal order alignment-wise which reauls in unused gaps, but the effect was found to be insignificant - especially compared to the fact that you cannot build U-Boot at all in the current state.

As ld seems to have no support for conditionals we run the linker script through the C preprocessor which can be easily used to remove the unwanted function calls.

Note that the C preprocessor must be run with the "-ansi" (or a "-std=") option to make sure all the system-specific predefined macros outside the reserved namespace are suppressed. Otherise, cpp might for example substitute "powerpc" to "1", thus corrupting for example "OUTPUT_ARCH(powerpc)" etc.

---
Compile tested on ARM and PPC, with ELDK 3.1, 3.1.1, 4.1 and 4.2, on ARM both with and without USE_PRIVATE_LIBGCC=yes.

I'm not sure if this is to be considered a bug fix (if you have to use an older tool chain, it certainly solves a serious problem of the current code) and should go into the current release, or if we should rather wait with this for the next version. Comments welcome.

Mike, I am aware that Blackfin is already using the C preprocessor to generate it's linker scripts. I guess this step can now be folded into this general mechanism. Do you want to provide such a patch, or shall I do it?

Quoted 15 lines
 Makefile                                      |   15 +++++++++++----
 board/netstar/Makefile                        |    9 ++++++---
 board/voiceblue/Makefile                      |   11 +++++++----
 config.mk                                     |   12 +++++++++++-
 nand_spl/board/amcc/acadia/Makefile           |    7 +++++--
 nand_spl/board/amcc/bamboo/Makefile           |    7 +++++--
 nand_spl/board/amcc/canyonlands/Makefile      |    7 +++++--
 nand_spl/board/amcc/kilauea/Makefile          |    7 +++++--
 nand_spl/board/amcc/sequoia/Makefile          |    7 +++++--
 nand_spl/board/freescale/mpc8313erdb/Makefile |    7 +++++--
 nand_spl/board/freescale/mx31pdk/Makefile     |    7 +++++--
 nand_spl/board/samsung/smdk6400/Makefile      |    7 +++++--
 nand_spl/board/sheldon/simpc8313/Makefile     |    7 +++++--
 onenand_ipl/board/apollon/Makefile            |    7 +++++--
 15 files changed, 86 insertions(+), 33 deletions(-)

Applied.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Do we define evil as the absence of goodness? It seems only  logical
that shit happens--we discover this by the process of elimination."
                                                        -- Larry Wall
#7 lore raw

PATCH 1/1 Blackfin: use common code to preprocess linker script

In reply to Wolfgang Denk

Now that the common code preprocesses the linker script, the Blackfin code no longer needs to do it.

---
 lib_blackfin/Makefile  |    5 +----
 lib_blackfin/config.mk |    2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)
lib_blackfin/Makefile +1 -4
index 4bdf6d3..cbf47f0 100644
@@ -48,12 +48,9 @@ COBJS-y	+= string.o
 SRCS	:= $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(SOBJS-y) $(COBJS-y))
 
-$(LIB):	$(obj).depend $(OBJS) $(obj)u-boot.lds
+$(LIB):	$(obj).depend $(OBJS)
 	$(AR) $(ARFLAGS) $@ $(OBJS)
 
-$(obj)u-boot.lds: u-boot.lds.S
-	$(CPP) $(CPPFLAGS) -D__ASSEMBLY__ -P $^ > $@
-
 #########################################################################
 
 # defines $(obj).depend target
lib_blackfin/config.mk +1 -1
index 0dd2ac6..a7e3658 100644
@@ -62,5 +62,5 @@ endif
 LDR_FLAGS += $(LDR_FLAGS-y)
 
 ifeq ($(wildcard $(TOPDIR)/board/$(BOARD)/u-boot.lds*),)
-LDSCRIPT = $(obj)lib_$(ARCH)/u-boot.lds
+LDSCRIPT = $(obj)lib_$(ARCH)/u-boot.lds.S
 endif
Signature · 1 line
1.6.4
#8 lore raw

PATCH 1/1 Blackfin: use common code to preprocess linker script

Dear Mike Frysinger,

Quoted 8 lines · In message <[email protected]> you wrote:

Now that the common code preprocesses the linker script, the Blackfin code no longer needs to do it.

---
 lib_blackfin/Makefile  |    5 +----
 lib_blackfin/config.mk |    2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

Aplied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"You're just jealous." "What, of an overgrown puppy  with  a  single-
figure IQ?"                      - Terry Pratchett, _Moving Pictures_
#9 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

In reply to Wolfgang Denk

config.mk endif · line 173

Quoted 11 lines · On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:
config.mk +7 -0
@@ -166,11 +166,21 @@ endif
+# Special flags for CPP when processing the linker script
+# Linker versions prior to 2.16 don't understand the builting
+# functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
+ifeq ($(shell $(LD) -v | \
+	sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/[ \1 -lt 2
 ] || [ \2 -lt 16 ] \&\& echo old_ld/p' | \ +	sh),old_ld)
+LDPPFLAGS += -D'SORT_BY_ALIGNMENT(x)=x' -D'SORT_BY_NAME(x)=x'
+endif

now that it's in the tree, i took a closer look ... guess i should have earlier, but oh well

this check will fail with binutils 3.0+ because of the minor check for 16 without a corresponding major check.

rather than making it specific to the sort problem, why not generalize it. extract the major and minor versions and export them to the preprocessor of the linker script. then the linker script input can use these to handle macroing away the SORT_xxx stuff. if there's concern about duplicating these macros, then we can start an asm-generic/u-boot.lds.h for people to include and centralize the logic. and next time there is backwards-compatibility issues, it's trivial to support since we have the support structure in place.

the way it's written now causes ld to get executed every time config.mk is included. my current test shows that is like 80 times, or 79 useless runs. even if we make this a bit smarter (saving the output in a var and exporting it), that cuts things down to like 60 executions. considering this test is only used by the linker script code, why not keep it in the top-level Makefile.

stderr is not redirected which means if the linker outputs something to that, it can quickly cause a lot of excess noise.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090822/2d24ec5a/attachment.pgp

#10 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Dear Mike Frysinger,

Quoted 17 lines · In message <[email protected]> you wrote:

config.mk endif · line 173

Quoted 11 lines · On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:
config.mk +7 -0
@@ -166,11 +166,21 @@ endif
+# Special flags for CPP when processing the linker script
+# Linker versions prior to 2.16 don't understand the builting
+# functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
+ifeq ($(shell $(LD) -v | \
+	sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/[ \1 -lt 2
 ] || [ \2 -lt 16 ] \&\& echo old_ld/p' | \ +	sh),old_ld)
+LDPPFLAGS +=3D -D'SORT_BY_ALIGNMENT(x)=3Dx' -D'SORT_BY_NAME(x)=3Dx'
+endif

now that it's in the tree, i took a closer look ... guess i should have earlier, but oh well

Quoted 2 lines

this check will fail with binutils 3.0+ because of the minor check for 16 without a corresponding major check.

Well, the "\1 -lt 2" is the major check, isn't it?

Quoted 7 lines

rather than making it specific to the sort problem, why not generalize it. extract the major and minor versions and export them to the preprocessor of the linker script. then the linker script input can use these to handle macroing away the SORT_xxx stuff. if there's concern about duplicating these macros, then we can start an asm-generic/u-boot.lds.h for people to include and centralize the logic. and next time there is backwards-compatibility issues, it's trivial to support since we have the support structure in place.

Good idea...

Quoted 6 lines

the way it's written now causes ld to get executed every time config.mk is included. my current test shows that is like 80 times, or 79 useless runs. even if we make this a bit smarter (saving the output in a var and exporting it), that cuts things down to like 60 executions. considering this test is only used by the linker script code, why not keep it in the top-level Makefile.

Patches welcome...

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Command, n.:
            Statement presented by a human and accepted by a computer
in such a manner as to make the human feel as if he is in control.
#11 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Quoted 17 lines · On Sunday 23 August 2009 01:34:38 Wolfgang Denk wrote:
Quoted 15 lines · Mike Frysinger

config.mk endif · line 172

Quoted 11 lines · On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:
config.mk +7 -1
@@ -166,11 +166,21 @@ endif
+# Special flags for CPP when processing the linker script
+# Linker versions prior to 2.16 don't understand the builting
+# functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
+ifeq ($(shell $(LD) -v | \
+	sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/[ \1
-lt 2 ] || [ \2 -lt 16 ] \&\& echo old_ld/p' | \ +	sh),old_ld)
+LDPPFLAGS +=3D -D'SORT_BY_ALIGNMENT(x)=3Dx' -D'SORT_BY_NAME(x)=3Dx'
+endif

this check will fail with binutils 3.0+ because of the minor check for 16 without a corresponding major check.

Quoted 1 line

Well, the "\1 -lt 2" is the major check, isn't it?

here is how the shell code looks:
[ $major -lt 2 ] || [ $minor -lt 16 ] && echo old_ld

and the way shell logic works, the echo is executed if either of those tests fail. what you really wanted was:
[ $major -lt 2 ] || [ $major -eq 2 -a $minor -lt 16 ] && echo old_ld

fairly common bug that comes up when people try processing tool versions on a major.minor.micro basis

but this is largely irrelevant if we move the logic from the build system to the header file as this will (should) get fixed in the process

Quoted 8 lines
Quoted 6 lines

the way it's written now causes ld to get executed every time config.mk is included. my current test shows that is like 80 times, or 79 useless runs. even if we make this a bit smarter (saving the output in a var and exporting it), that cuts things down to like 60 executions. considering this test is only used by the linker script code, why not keep it in the top-level Makefile.

Patches welcome...

i wanted to make sure we were on the same page before sending patches -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090823/82efd88f/attachment.pgp

#12 lore raw

PATCH 1/1 Fix all linker scripts for older binutils versions (pre-2.16)

Dear Mike Frysinger,

Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 5 lines
Quoted 3 lines

this check will fail with binutils 3.0+ because of the minor check for 16 without a corresponding major check.

Well, the "\1 -lt 2" is the major check, isn't it?

here is how the shell code looks:
[ $major -lt 2 ] || [ $minor -lt 16 ] && echo old_ld

Oops.

Quoted 3 lines

and the way shell logic works, the echo is executed if either of those tests fail. what you really wanted was:
[ $major -lt 2 ] || [ $major -eq 2 -a $minor -lt 16 ] && echo old_ld

Right you are. Silly me.

Thanks for catching this in time.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
In general, they do what you want, unless you want consistency.
                                    - Larry Wall in the perl man page
#13 lore raw

PATCH 1/1 start a linker script helper file

In reply to Wolfgang Denk

Start a common header file for common linker script code (such as workarounds for older linkers) rather than doing this in the build system.

As fallout, we no longer execute the linker every time config.mk is included by a build file (which can easily be 70+ times), but rather only execute it once.

This also fixes a bug in the major version checking by creating a macro to easily compare versions and keep people from making the same common mistake (forgetting to check major and minor together).

---
note: rather than update every linker script and add an #include, i forced it by using -include $(TOPDIR)/include/u-boot/u-boot.lds.h. i think this is sane going forward.

also, i picked include/u-boot/ over include/asm-generic/ as the former seemed like a better u-boot-specific dir. linux uses include/asm-generic/. doesnt matter much to me.

 Makefile                    |    8 ++++++++
 config.mk                   |   10 ----------
 include/u-boot/u-boot.lds.h |   25 +++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100644 include/u-boot/u-boot.lds.h
Makefile +8 -0
index 96cca23..63d7c97 100644
@@ -267,6 +267,14 @@ endif
 PLATFORM_LIBS += $(PLATFORM_LIBGCC)
 export PLATFORM_LIBS
 
+# Special flags for CPP when processing the linker script.
+# Pass the version down so we can handle backwards compatibility
+# on the fly.
+LDPPFLAGS += \
+	-include $(TOPDIR)/include/u-boot/u-boot.lds.h \
+	$(shell $(LD) --version | \
+	  sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
+
 ifeq ($(CONFIG_NAND_U_BOOT),y)
 NAND_SPL = nand_spl
 U_BOOT_NAND = $(obj)u-boot-nand.bin
config.mk +0 -10
index 7bc7315..8852157 100644
@@ -171,16 +171,6 @@ ifneq ($(TEXT_BASE),)
 LDFLAGS += -Ttext $(TEXT_BASE)
 endif
 
-# Special flags for CPP when processing the linker script
-# Linker versions prior to 2.16 don't understand the builting
-# functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
-ifeq ($(shell $(LD) -v | \
-	sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/[ \1 -lt 2 ] || [ \2 -lt 16 ] \&\& echo old_ld/p' | \
-	sh),old_ld)
-LDPPFLAGS += -D'SORT_BY_ALIGNMENT(x)=x' -D'SORT_BY_NAME(x)=x'
-endif
-
-
 # Location of a usable BFD library, where we define "usable" as
 # "built for ${HOST}, supports ${TARGET}".  Sensible values are
 # - When cross-compiling: the root of the cross-environment
include/u-boot/u-boot.lds.h new file +25 -0
new file mode 100644
index 0000000..ead37d0
@@ -0,0 +1,25 @@
+/*
+ * Linker script helper macros
+ *
+ * Copyright (c) 2009 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef __U_BOOT_LDS__
+#define __U_BOOT_LDS__
+
+/* See if the linker version is at least the specified version */
+#define LD_AT_LEAST(major, minor) \
+	((major > LD_MAJOR) || (major == LD_MAJOR && minor <= LD_MINOR))
+
+/*
+ * Linker versions prior to 2.16 don't understand the builtin
+ * functions SORT_BY_ALIGNMENT() and SORT_BY_NAME(), so disable these
+ */
+#if !LD_AT_LEAST(2, 16)
+# define SORT_BY_ALIGNMENT(x) x
+# define SORT_BY_NAME(x) x
+#endif
+
+#endif
Signature · 1 line
1.6.4
author Applied
#14 lore raw

PATCH 1/1 start a linker script helper file

Dear Mike Frysinger,

Quoted 21 lines · In message <[email protected]> you wrote:

Start a common header file for common linker script code (such as workarounds for older linkers) rather than doing this in the build system.

As fallout, we no longer execute the linker every time config.mk is included by a build file (which can easily be 70+ times), but rather only execute it once.

This also fixes a bug in the major version checking by creating a macro to easily compare versions and keep people from making the same common mistake (forgetting to check major and minor together).

---
note: rather than update every linker script and add an #include, i forced it by using -include $(TOPDIR)/include/u-boot/u-boot.lds.h. i think this is sane going forward.

also, i picked include/u-boot/ over include/asm-generic/ as the former seemed like a better u-boot-specific dir. linux uses include/asm-generic/. doesnt matter much to me.

Quoted 5 lines
 Makefile                    |    8 ++++++++
 config.mk                   |   10 ----------
 include/u-boot/u-boot.lds.h |   25 +++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100644 include/u-boot/u-boot.lds.h

That's version 2, right?

Applied. Thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Cogito cogito ergo cogito sum - "I think that I  think,  therefore  I
think that I am."          - Ambrose Bierce, "The Devil's Dictionary"