[coreboot] [PATCH] v3: section correctness checker

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Wed Aug 20 17:18:11 CEST 2008


On 20.08.2008 15:33, Carl-Daniel Hailfinger wrote:
> v3 does not handle .data and .bss sections in stage1 and initram. We
> simply hope they are unused/empty and will get runtime
> crashes/corruption/malfunction if they are not empty.
>
> Check for the emptiness of these sections and abort the build on error.
> This triggers on all stage1/initram global variables which are not
> declared the right way.
>
> This found a long-standing bug introduced in r729 and fixed in r576.
> It also breaks the build of every Geode target in the v3 tree because
> they have multiple bugs. And it breaks the build of the K8 code because
> of a bug there.
>
> Tested for all possible variations of .data and .bss usage.
>
> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
>   

Better checker follows. It does not only tell you the name of the object
file with the bug, it even gives you the variable name which caused the bug:
  CHECK   initram (non-empty .data sections)
/sources/tmptrees/corebootv3-check_illegal_global_vars/build/coreboot.initram_partiallylinked.o:
first_time.3526
make: ***
[/sources/tmptrees/corebootv3-check_illegal_global_vars/build/coreboot.initram]
Error 1

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: corebootv3-check_illegal_global_vars/arch/x86/Makefile
===================================================================
--- corebootv3-check_illegal_global_vars/arch/x86/Makefile	(revision 790)
+++ corebootv3-check_illegal_global_vars/arch/x86/Makefile	(working copy)
@@ -143,6 +143,30 @@
 	$(Q)# 0x4000 - 0x100, we will end up with a 4 gig file.
 	$(Q)# I wonder if that behavior is on purpose.
 
+	$(Q)# .data and .bss must be empty because they aren't handled
+	$(Q)printf "  CHECK   stage0 (non-empty .data sections)\n"
+	$(Q)objdump -h $(STAGE0_OBJ)| grep "^$(obj)/\|\.data"|\
+		grep -v "\.data[[:blank:]]\+00000000[[:blank:]]"|\
+		grep -B1 "\.data"| grep "^$(obj)/"|\
+		cut -f 1 -d:| while read a; do \
+		echo -n "$$a: "; \
+		objdump -t --section=.data $$a|\
+		grep -i "^[0-9a-f]\{8\}"|grep -v "00000000 [^ ]\+$$"|\
+		sed "s/.* //"| xargs echo; \
+		done| \
+		grep "^$(obj)/"; test $$? -ne 0
+	$(Q)printf "  CHECK   stage0 (non-empty .bss sections)\n"
+	$(Q)objdump -h $(STAGE0_OBJ)| grep "^$(obj)/\|\.bss"|\
+		grep -v "\.bss[[:blank:]]\+00000000[[:blank:]]"|\
+		grep -B1 "\.bss"| grep "^$(obj)/"|\
+		cut -f 1 -d:| while read a; do \
+		echo -n "$$a: "; \
+		objdump -t --section=.bss $$a|\
+		grep -i "^[0-9a-f]\{8\}"|grep -v "00000000 [^ ]\+$$"|\
+		sed "s/.* //"| xargs echo; \
+		done| \
+		grep "^$(obj)/"; test $$? -ne 0
+
 	$(Q)# Note: we invoke gcc (instead of ld directly) here, as we hit
 	$(Q)# strange problems in the past. It seems that only gcc knows how
 	$(Q)# to properly invoke ld.
@@ -264,6 +288,33 @@
 $(obj)/coreboot.initram $(obj)/coreboot.initram.map: $(obj)/stage0.init $(obj)/stage0-prefixed.o $(INITRAM_SRC)
 	$(Q)printf "  CC      $(subst $(shell pwd)/,,$(@)) (XIP)\n"
 	$(Q)$(CC) $(INITCFLAGS) -fPIE -c -combine $(INITRAM_SRC) -o $(obj)/coreboot.initram_partiallylinked.o
+
+	$(Q)# .data and .bss must be empty because they aren't handled
+	$(Q)printf "  CHECK   initram (non-empty .data sections)\n"
+	$(Q)objdump -h $(obj)/coreboot.initram_partiallylinked.o|\
+		grep "^$(obj)/\|\.data"|\
+		grep -v "\.data[[:blank:]]\+00000000[[:blank:]]"|\
+		grep -B1 "\.data"| grep "^$(obj)/"|\
+		cut -f 1 -d:| while read a; do \
+		echo -n "$$a: "; \
+		objdump -t --section=.data $$a|\
+		grep -i "^[0-9a-f]\{8\}"|grep -v "00000000 [^ ]\+$$"|\
+		sed "s/.* //"| xargs echo; \
+		done| \
+		grep "^$(obj)/"; test $$? -ne 0
+	$(Q)printf "  CHECK   initram (non-empty .bss sections)\n"
+	$(Q)objdump -h $(obj)/coreboot.initram_partiallylinked.o|\
+		grep "^$(obj)/\|\.bss"|\
+		grep -v "\.bss[[:blank:]]\+00000000[[:blank:]]"|\
+		grep -B1 "\.bss"| grep "^$(obj)/"|\
+		cut -f 1 -d:| while read a; do \
+		echo -n "$$a: "; \
+		objdump -t --section=.bss $$a|\
+		grep -i "^[0-9a-f]\{8\}"|grep -v "00000000 [^ ]\+$$"|\
+		sed "s/.* //"| xargs echo; \
+		done| \
+		grep "^$(obj)/"; test $$? -ne 0
+
 	$(Q)printf "  WRAP    $(subst $(shell pwd)/,,$(@)) (PIC->non-PIC)\n"
 	$(Q)$(NM) --undefined-only $(obj)/coreboot.initram_partiallylinked.o |\
 		grep -v _GLOBAL_OFFSET_TABLE_ | grep " U " | sed "s/^ *U //" |\


-- 
http://www.hailfinger.org/





More information about the coreboot mailing list