[coreboot] r794 - in coreboot-v3/util: . sectionchecker

svn at coreboot.org svn at coreboot.org
Thu Aug 21 19:43:04 CEST 2008

Author: hailfinger
Date: 2008-08-21 19:43:04 +0200 (Thu, 21 Aug 2008)
New Revision: 794

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. Same applies to any
sections with relocation entries which can not be resolved during
link time.

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. It also triggers on local static variables.

Features of this checker:
- It doesn't only check for non-empty .data and .bss, but also for
unknown sections which would be a problem.
- It gives you the offending filename, the section and the variable
- It won't stop after the first error and will tell you about all errors
for a given file list.

This found a long-standing bug introduced in r729 and fixed in r786.
It also broke the build of every Geode target in the v3 tree because
they had multiple bugs. And it broke the build of the K8 code because
of a bug there.
Other fixes resulting from this checker are in r790 and r791.

Ron already fixed some of the bugs uncovered by this checker.

Tested for all possible variations of .data and .bss usage.

Sample output follows:
  CC      build/coreboot.initram (XIP)
  CHECK   initram (non-empty writable/allocatable sections)
build/coreboot.initram_partiallylinked.o: section .data: foo1
build/coreboot.initram_partiallylinked.o: section .bss: foo2
build/coreboot.initram_partiallylinked.o: section .data.rel.ro.local:
make: *** [build/coreboot.initram] Error 1

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Acked-by: Segher Boessenkool <segher at kernel.crashing.org> 

Added: coreboot-v3/util/sectionchecker/sectionchecker
--- coreboot-v3/util/sectionchecker/sectionchecker	                        (rev 0)
+++ coreboot-v3/util/sectionchecker/sectionchecker	2008-08-21 17:43:04 UTC (rev 794)
@@ -0,0 +1,58 @@
+# This file is part of the coreboot project.
+# Copyright (C) 2008 Carl-Daniel Hailfinger
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+# This program checks whether a given list of files ($3+) has any writable
+# and allocatable non-empty sections. If so, the name of the file, the name of
+# the section and the symbols in that section are printed and an error is
+# returned.
+# This is extremely useful for stage1 and initram correctness because
+# the .data* and .bss sections are silently dropped. All accesses there
+# would wreak havoc (silent discard of writes or silent corruption of
+# unspecified memory or cache).
+# The string parsing used here heavily depends on the textual form of
+# GNU objdump output and on the instruction architecture of the files.
+shift 2
+for a in $*; do
+	# Look for sections which have WRITE and ALLOC flags set.
+	$READELF -St $a|
+		grep -B2 "WRITE.*ALLOC"|
+		grep -B1 "^ \+[[:alnum:]]\+ \+[0-9a-f]\+ \+[0-9a-f]\+ \+0*[1-9a-f]"|
+		grep "^ \+\[ *[0-9]\+"|
+		cut -f 2 -d"]"|
+		sed "s/^[[:blank:]]*//"|
+		while read b; do
+			echo -n "$a: section $b: "
+			$OBJDUMP -t --section=$b $a|
+				grep -i "^[0-9a-f]\{8\}"|
+				grep -v "00000000 [^ ]\+$"|
+				sed "s/.* //"|
+				xargs echo
+		done
+	grep ""
+# Invert the result
+test $? -ne 0

More information about the coreboot mailing list