public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
@ 2009-08-17 12:00 Wolfgang Denk
  2009-08-17 19:14 ` Mike Frysinger
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-17 12:00 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Mike Frysinger <vapier@gentoo.org>
---
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(-)

diff --git a/Makefile b/Makefile
index 329e0f5..2636ac0 100644
--- a/Makefile
+++ b/Makefile
@@ -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 '*~' \
diff --git a/board/netstar/Makefile b/board/netstar/Makefile
index 8f35f93..11578b7 100644
--- a/board/netstar/Makefile
+++ b/board/netstar/Makefile
@@ -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
diff --git a/board/voiceblue/Makefile b/board/voiceblue/Makefile
index 7bb92a6..121c717 100644
--- a/board/voiceblue/Makefile
+++ b/board/voiceblue/Makefile
@@ -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
diff --git a/config.mk b/config.mk
index 0c6d1d1..7bc7315 100644
--- a/config.mk
+++ b/config.mk
@@ -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
diff --git a/nand_spl/board/amcc/acadia/Makefile b/nand_spl/board/amcc/acadia/Makefile
index 822f82f..f37425e 100644
--- a/nand_spl/board/amcc/acadia/Makefile
+++ b/nand_spl/board/amcc/acadia/Makefile
@@ -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
diff --git a/nand_spl/board/amcc/bamboo/Makefile b/nand_spl/board/amcc/bamboo/Makefile
index 2932927..5fcf290 100644
--- a/nand_spl/board/amcc/bamboo/Makefile
+++ b/nand_spl/board/amcc/bamboo/Makefile
@@ -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
diff --git a/nand_spl/board/amcc/canyonlands/Makefile b/nand_spl/board/amcc/canyonlands/Makefile
index 84b1454..f77e459 100644
--- a/nand_spl/board/amcc/canyonlands/Makefile
+++ b/nand_spl/board/amcc/canyonlands/Makefile
@@ -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
diff --git a/nand_spl/board/amcc/kilauea/Makefile b/nand_spl/board/amcc/kilauea/Makefile
index 8a062fe..bc21744 100644
--- a/nand_spl/board/amcc/kilauea/Makefile
+++ b/nand_spl/board/amcc/kilauea/Makefile
@@ -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
diff --git a/nand_spl/board/amcc/sequoia/Makefile b/nand_spl/board/amcc/sequoia/Makefile
index 462005f..54ea7c7 100644
--- a/nand_spl/board/amcc/sequoia/Makefile
+++ b/nand_spl/board/amcc/sequoia/Makefile
@@ -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
diff --git a/nand_spl/board/freescale/mpc8313erdb/Makefile b/nand_spl/board/freescale/mpc8313erdb/Makefile
index 1a8f6ff..a13e7e2 100644
--- a/nand_spl/board/freescale/mpc8313erdb/Makefile
+++ b/nand_spl/board/freescale/mpc8313erdb/Makefile
@@ -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:
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index a9572ba..0e13d5d 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -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
diff --git a/nand_spl/board/samsung/smdk6400/Makefile b/nand_spl/board/samsung/smdk6400/Makefile
index ae9eb2a..0fdda25 100644
--- a/nand_spl/board/samsung/smdk6400/Makefile
+++ b/nand_spl/board/samsung/smdk6400/Makefile
@@ -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
diff --git a/nand_spl/board/sheldon/simpc8313/Makefile b/nand_spl/board/sheldon/simpc8313/Makefile
index 20199c7..6920fe8 100644
--- a/nand_spl/board/sheldon/simpc8313/Makefile
+++ b/nand_spl/board/sheldon/simpc8313/Makefile
@@ -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:
diff --git a/onenand_ipl/board/apollon/Makefile b/onenand_ipl/board/apollon/Makefile
index 49a8e90..193efff 100644
--- a/onenand_ipl/board/apollon/Makefile
+++ b/onenand_ipl/board/apollon/Makefile
@@ -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 $@.map -o $@
 
+$(onenandobj)u-boot.lds:	$(LDSCRIPT)
+	$(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
+
 # create symbolic links from common files
 
 # from cpu directory
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 12:00 [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Wolfgang Denk
@ 2009-08-17 19:14 ` Mike Frysinger
  2009-08-17 19:31   ` Wolfgang Denk
  2009-08-21 21:14 ` Wolfgang Denk
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2009-08-17 19:14 UTC (permalink / raw)
  To: u-boot

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 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 19:14 ` Mike Frysinger
@ 2009-08-17 19:31   ` Wolfgang Denk
  2009-08-17 20:15     ` Mike Frysinger
  0 siblings, 1 reply; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-17 19:31 UTC (permalink / raw)
  To: u-boot

Dear Mike,

In message <200908171514.54018.vapier@gentoo.org> you 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

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

-- 
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 19:31   ` Wolfgang Denk
@ 2009-08-17 20:15     ` Mike Frysinger
  2009-08-17 20:24       ` Wolfgang Denk
  0 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2009-08-17 20:15 UTC (permalink / raw)
  To: u-boot

On Monday 17 August 2009 15:31:30 Wolfgang Denk wrote:
> Mike 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
>
> 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 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 20:15     ` Mike Frysinger
@ 2009-08-17 20:24       ` Wolfgang Denk
  2009-08-17 20:31         ` Mike Frysinger
  0 siblings, 1 reply; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-17 20:24 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <200908171615.45626.vapier@gentoo.org> you wrote:
>
> > 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

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

> 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

-- 
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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 20:24       ` Wolfgang Denk
@ 2009-08-17 20:31         ` Mike Frysinger
  0 siblings, 0 replies; 15+ messages in thread
From: Mike Frysinger @ 2009-08-17 20:31 UTC (permalink / raw)
  To: u-boot

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 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 12:00 [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Wolfgang Denk
  2009-08-17 19:14 ` Mike Frysinger
@ 2009-08-21 21:14 ` Wolfgang Denk
  2009-08-22 23:50 ` [U-Boot] [PATCH] Blackfin: use common code to preprocess linker script Mike Frysinger
  2009-08-23  0:00 ` [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Mike Frysinger
  3 siblings, 0 replies; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-21 21:14 UTC (permalink / raw)
  To: u-boot


In message <1250510453-30567-1-git-send-email-wd@denx.de> 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.
> 
> Signed-off-by: Wolfgang Denk <wd@denx.de>
> Cc: Mike Frysinger <vapier@gentoo.org>
> ---
> 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(-)

Applied.

Best regards,

Wolfgang Denk

-- 
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Blackfin: use common code to preprocess linker script
  2009-08-17 12:00 [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Wolfgang Denk
  2009-08-17 19:14 ` Mike Frysinger
  2009-08-21 21:14 ` Wolfgang Denk
@ 2009-08-22 23:50 ` Mike Frysinger
  2009-08-23 20:25   ` Wolfgang Denk
  2009-08-23  0:00 ` [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Mike Frysinger
  3 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2009-08-22 23:50 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 lib_blackfin/Makefile  |    5 +----
 lib_blackfin/config.mk |    2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/lib_blackfin/Makefile b/lib_blackfin/Makefile
index 4bdf6d3..cbf47f0 100644
--- a/lib_blackfin/Makefile
+++ b/lib_blackfin/Makefile
@@ -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
diff --git a/lib_blackfin/config.mk b/lib_blackfin/config.mk
index 0dd2ac6..a7e3658 100644
--- a/lib_blackfin/config.mk
+++ b/lib_blackfin/config.mk
@@ -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
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-17 12:00 [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Wolfgang Denk
                   ` (2 preceding siblings ...)
  2009-08-22 23:50 ` [U-Boot] [PATCH] Blackfin: use common code to preprocess linker script Mike Frysinger
@ 2009-08-23  0:00 ` Mike Frysinger
  2009-08-23  5:34   ` Wolfgang Denk
  3 siblings, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2009-08-23  0:00 UTC (permalink / raw)
  To: u-boot

On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:
> --- a/config.mk
> +++ b/config.mk
> @@ -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 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-23  0:00 ` [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Mike Frysinger
@ 2009-08-23  5:34   ` Wolfgang Denk
  2009-08-23  6:09     ` Mike Frysinger
  2009-08-23  6:47     ` [U-Boot] [PATCH] start a linker script helper file Mike Frysinger
  0 siblings, 2 replies; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-23  5:34 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <200908222000.22345.vapier@gentoo.org> you wrote:
>
> On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:
> > --- a/config.mk
> > +++ b/config.mk
> > @@ -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
> 
> 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?

> 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...

> 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

-- 
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.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-23  5:34   ` Wolfgang Denk
@ 2009-08-23  6:09     ` Mike Frysinger
  2009-08-23 19:30       ` Wolfgang Denk
  2009-08-23  6:47     ` [U-Boot] [PATCH] start a linker script helper file Mike Frysinger
  1 sibling, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2009-08-23  6:09 UTC (permalink / raw)
  To: u-boot

On Sunday 23 August 2009 01:34:38 Wolfgang Denk wrote:
> Mike Frysinger wrote:
> > On Monday 17 August 2009 08:00:53 Wolfgang Denk wrote:
> > > --- a/config.mk
> > > +++ b/config.mk
> > > @@ -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.
>
> 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

> > 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 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] start a linker script helper file
  2009-08-23  5:34   ` Wolfgang Denk
  2009-08-23  6:09     ` Mike Frysinger
@ 2009-08-23  6:47     ` Mike Frysinger
  2009-08-23 20:41       ` Wolfgang Denk
  1 sibling, 1 reply; 15+ messages in thread
From: Mike Frysinger @ 2009-08-23  6:47 UTC (permalink / raw)
  To: u-boot

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).

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
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

diff --git a/Makefile b/Makefile
index 96cca23..63d7c97 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/config.mk b/config.mk
index 7bc7315..8852157 100644
--- a/config.mk
+++ b/config.mk
@@ -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
diff --git a/include/u-boot/u-boot.lds.h b/include/u-boot/u-boot.lds.h
new file mode 100644
index 0000000..ead37d0
--- /dev/null
+++ b/include/u-boot/u-boot.lds.h
@@ -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
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16)
  2009-08-23  6:09     ` Mike Frysinger
@ 2009-08-23 19:30       ` Wolfgang Denk
  0 siblings, 0 replies; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-23 19:30 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <200908230209.10484.vapier@gentoo.org> you wrote:
>
> > > 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.

> 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

-- 
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] Blackfin: use common code to preprocess linker script
  2009-08-22 23:50 ` [U-Boot] [PATCH] Blackfin: use common code to preprocess linker script Mike Frysinger
@ 2009-08-23 20:25   ` Wolfgang Denk
  0 siblings, 0 replies; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-23 20:25 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1250985022-11108-1-git-send-email-vapier@gentoo.org> you wrote:
> Now that the common code preprocesses the linker script, the Blackfin code
> no longer needs to do it.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
>  lib_blackfin/Makefile  |    5 +----
>  lib_blackfin/config.mk |    2 +-
>  2 files changed, 2 insertions(+), 5 deletions(-)

Aplied, thanks.

Best regards,

Wolfgang Denk

-- 
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_

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [U-Boot] [PATCH] start a linker script helper file
  2009-08-23  6:47     ` [U-Boot] [PATCH] start a linker script helper file Mike Frysinger
@ 2009-08-23 20:41       ` Wolfgang Denk
  0 siblings, 0 replies; 15+ messages in thread
From: Wolfgang Denk @ 2009-08-23 20:41 UTC (permalink / raw)
  To: u-boot

Dear Mike Frysinger,

In message <1251010079-10475-1-git-send-email-vapier@gentoo.org> 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).
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
> ---
> 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

That's version 2, right?

Applied. Thanks.

Best regards,

Wolfgang Denk

-- 
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"

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-08-23 20:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-17 12:00 [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Wolfgang Denk
2009-08-17 19:14 ` Mike Frysinger
2009-08-17 19:31   ` Wolfgang Denk
2009-08-17 20:15     ` Mike Frysinger
2009-08-17 20:24       ` Wolfgang Denk
2009-08-17 20:31         ` Mike Frysinger
2009-08-21 21:14 ` Wolfgang Denk
2009-08-22 23:50 ` [U-Boot] [PATCH] Blackfin: use common code to preprocess linker script Mike Frysinger
2009-08-23 20:25   ` Wolfgang Denk
2009-08-23  0:00 ` [U-Boot] [PATCH] Fix all linker scripts for older binutils versions (pre-2.16) Mike Frysinger
2009-08-23  5:34   ` Wolfgang Denk
2009-08-23  6:09     ` Mike Frysinger
2009-08-23 19:30       ` Wolfgang Denk
2009-08-23  6:47     ` [U-Boot] [PATCH] start a linker script helper file Mike Frysinger
2009-08-23 20:41       ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox