From 136345c0190ddf9de628e3543dbed5ba6dcb3495 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sun, 28 Jan 2001 06:39:56 +0000 Subject: [PATCH] Improve kernel bootstrapping: o Use objdump instead of gensetdefs(1) to build the linker sets. o Allow overriding of nm and objdump in resp. genassym.sh and gensetdefs.pl for non-native toolchains. Reviewed by: arch Perl improvements: Jos Backus , benno --- sys/conf/Makefile.alpha | 2 +- sys/conf/Makefile.i386 | 2 +- sys/conf/Makefile.ia64 | 8 +-- sys/conf/Makefile.pc98 | 2 +- sys/conf/Makefile.powerpc | 2 +- sys/conf/kmod.mk | 2 +- sys/ia64/ia64/genassym.sh | 53 ------------------- sys/kern/genassym.sh | 2 +- sys/kern/gensetdefs.pl | 105 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 116 insertions(+), 62 deletions(-) delete mode 100644 sys/ia64/ia64/genassym.sh create mode 100644 sys/kern/gensetdefs.pl diff --git a/sys/conf/Makefile.alpha b/sys/conf/Makefile.alpha index bc749955a890..eee034daa02b 100644 --- a/sys/conf/Makefile.alpha +++ b/sys/conf/Makefile.alpha @@ -177,7 +177,7 @@ setdef1.o: setdef1.c setdefs.h ${NORMAL_C} setdef0.c setdef1.c setdefs.h: Makefile ${OBJS} - @gensetdefs ${OBJS} + @perl5 $S/kern/gensetdefs.pl ${OBJS} # this rule stops ./assym.s in .depend from causing problems ./assym.s: assym.s diff --git a/sys/conf/Makefile.i386 b/sys/conf/Makefile.i386 index 135c8683511e..f42bd2f361b8 100644 --- a/sys/conf/Makefile.i386 +++ b/sys/conf/Makefile.i386 @@ -182,7 +182,7 @@ setdef1.o: setdef1.c setdefs.h ${NORMAL_C} setdef0.c setdef1.c setdefs.h: Makefile ${OBJS} - @gensetdefs ${OBJS} + @perl5 $S/kern/gensetdefs.pl ${OBJS} # this rule stops ./assym.s in .depend from causing problems ./assym.s: assym.s diff --git a/sys/conf/Makefile.ia64 b/sys/conf/Makefile.ia64 index 0739aa9caf93..088b31b9c13c 100644 --- a/sys/conf/Makefile.ia64 +++ b/sys/conf/Makefile.ia64 @@ -20,8 +20,10 @@ CWARNFLAGS= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \ -ansi CC= ia64-unknown-linux-gcc -D__FreeBSD__ -U__linux__ LD= ia64-unknown-linux-ld +NM= ia64-unknown-linux-nm SIZE= ia64-unknown-linux-size OBJCOPY= ia64-unknown-linux-objcopy +OBJDUMP= ia64-unknown-linux-objdump MACHINE_ARCH= ia64 # Which version of config(8) is required. @@ -184,13 +186,13 @@ setdef1.o: setdef1.c setdefs.h ${NORMAL_C} setdef0.c setdef1.c setdefs.h: Makefile ${OBJS} - @gensetdefs ${OBJS} + @OBJDUMP=${OBJDUMP} perl5 $S/kern/gensetdefs.pl ${OBJS} # this rule stops ./assym.s in .depend from causing problems ./assym.s: assym.s -assym.s: $S/$M/$M/genassym.sh genassym.o - sh $S/$M/$M/genassym.sh genassym.o > ${.TARGET} +assym.s: $S/kern/genassym.sh genassym.o + NM=${NM} sh $S/kern/genassym.sh genassym.o > ${.TARGET} genassym.o: $S/$M/$M/genassym.c ${CC} -c ${CFLAGS} $S/$M/$M/genassym.c diff --git a/sys/conf/Makefile.pc98 b/sys/conf/Makefile.pc98 index 7aef2a297ea5..a4bbe93c0c4c 100644 --- a/sys/conf/Makefile.pc98 +++ b/sys/conf/Makefile.pc98 @@ -184,7 +184,7 @@ setdef1.o: setdef1.c setdefs.h ${NORMAL_C} setdef0.c setdef1.c setdefs.h: Makefile ${OBJS} - @gensetdefs ${OBJS} + @perl5 $S/kern/gensetdefs.pl ${OBJS} # this rule stops ./assym.s in .depend from causing problems ./assym.s: assym.s diff --git a/sys/conf/Makefile.powerpc b/sys/conf/Makefile.powerpc index 135c8683511e..f42bd2f361b8 100644 --- a/sys/conf/Makefile.powerpc +++ b/sys/conf/Makefile.powerpc @@ -182,7 +182,7 @@ setdef1.o: setdef1.c setdefs.h ${NORMAL_C} setdef0.c setdef1.c setdefs.h: Makefile ${OBJS} - @gensetdefs ${OBJS} + @perl5 $S/kern/gensetdefs.pl ${OBJS} # this rule stops ./assym.s in .depend from causing problems ./assym.s: assym.s diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk index 03fa4ed11034..6c5b31d00f4a 100644 --- a/sys/conf/kmod.mk +++ b/sys/conf/kmod.mk @@ -131,7 +131,7 @@ PROG= ${KMOD}.ko ${PROG}: ${KMOD}.kld .if ${OBJFORMAT} == elf - gensetdefs ${KMOD}.kld + perl5 @/kern/gensetdefs.pl ${KMOD}.kld ${CC} ${CFLAGS} -c setdef0.c ${CC} ${CFLAGS} -c setdef1.c ${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} setdef0.o ${KMOD}.kld setdef1.o diff --git a/sys/ia64/ia64/genassym.sh b/sys/ia64/ia64/genassym.sh deleted file mode 100644 index c8fd249b2b59..000000000000 --- a/sys/ia64/ia64/genassym.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# $FreeBSD$ - -# Grrr, this should use stdin and stdout, but is encrufted for compatibility. - -usage() { - echo "usage: genassym [-o outfile] objfile" - exit 1 -} - -outfile=/dev/stdout -while getopts "o:" option -do - case "$option" in - o) outfile="$OPTARG";; - *) usage;; - esac -done -shift $(($OPTIND - 1)) -case $# in -1) ;; -*) usage;; -esac - -ia64-unknown-linux-nm "$1" | awk ' -/ C .*sign$/ { - sign = substr($1, length($1) - 3, 4) - sub("^0*", "", sign) - if (sign != "") - sign = "-" -} -/ C .*w0$/ { - w0 = substr($1, length($1) - 3, 4) -} -/ C .*w1$/ { - w1 = substr($1, length($1) - 3, 4) -} -/ C .*w2$/ { - w2 = substr($1, length($1) - 3, 4) -} -/ C .*w3$/ { - w3 = substr($1, length($1) - 3, 4) - w = w3 w2 w1 w0 - sub("^0*", "", w) - if (w == "") - w = "0" - sub("w3$", "", $3) - # This still has minor problems representing INT_MIN, etc. E.g., - # with 32-bit 2''s complement ints, this prints -0x80000000, which - # has the wrong type (unsigned int). - printf("#define\t%s\t%s0x%s\n", $3, sign, w) -} -' 3>"$outfile" >&3 3>&- diff --git a/sys/kern/genassym.sh b/sys/kern/genassym.sh index 071ddb04cb03..54f4330aa10a 100644 --- a/sys/kern/genassym.sh +++ b/sys/kern/genassym.sh @@ -22,7 +22,7 @@ case $# in *) usage;; esac -nm "$1" | awk ' +${NM:='nm'} "$1" | awk ' / C .*sign$/ { sign = substr($1, length($1) - 3, 4) sub("^0*", "", sign) diff --git a/sys/kern/gensetdefs.pl b/sys/kern/gensetdefs.pl new file mode 100644 index 000000000000..ade59faa4661 --- /dev/null +++ b/sys/kern/gensetdefs.pl @@ -0,0 +1,105 @@ +#!/usr/bin/perl -w +# +# Copyright (c) 2001 The FreeBSD Project +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# From src/usr.bin/gensetdefs/gensetdefs.c,v 1.6 2000/09/29 13:29:43 dfr +# +# $FreeBSD$ + +use strict; + +my %sets = (); +my $pointersize = 0; +my $objdump = $ENV{'OBJDUMP'} || 'objdump'; + +# Run objdump over each object file to find all defined linker sets. +# Linker sets are sections with names starting with `.set.' +foreach my $objfile (@ARGV) { + open(SECTION, "$objdump -h $objfile |") or die; + while (
) { + my ($index, $name, $size, $vma, $lma, $offset, $align) = split; + + next unless $name; + + if ($name =~ /^.set./) { + $name =~ s/^.set.//; + $sets{$name} ||= 0; + $sets{$name} += hex "0x$size"; + + # Assume the size of a pointer is equal to it's alignment + # and thus the alignment of the section. + if ($pointersize < eval $align) { + $pointersize = eval $align; + } + } + } + close SECTION; +} + +# Generate our list of set definitions +my @setdefs; +while (my ($name, $size) = each %sets) { + my $elements = $size / $pointersize; + push @setdefs, "DEFINE_SET($name, $elements);\n"; +} + +# Create setdefs.h +open(SETDEFS_H, "> setdefs.h") or die; +print SETDEFS_H sort @setdefs; +close SETDEFS_H; + +# Create setdef0.c +open(SETDEF0_C, "> setdef0.c") or die; +print SETDEF0_C < setdef1.c") or die; +print SETDEF1_C <