Subject: Re: crtbegin.c won't compile
To: None <netbsd-help@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 05/26/1999 18:13:13
In article <99052609453700.00202@scintillate> strawberry@toth.org.uk (Chrissy Lloyd) writes:
>On running 'make build' in /usr/src I get:
>
>all ===> lib/csu/i386_elf
>cc -O2 -fPIC -Werror  -DLIBC_SCCS -DPIC -DDYNAMIC -DELFSIZE=32 -I/usr/src/lib/csu/i386_elf/../../../libexec/ld.elf_so -I/usr/src/lib/csu/i386_elf/../common_elf -c /usr/src/lib/csu/i386_elf/../common_elf/crtbegin.c -o crtbegin.o
>/usr/src/lib/csu/i386_elf/../common_elf/crtbegin.c:62: section attributes are not supported for this target
>/usr/src/lib/csu/i386_elf/../common_elf/crtbegin.c:64: section attributes are not supported for this target
>/usr/src/lib/csu/i386_elf/../common_elf/crtbegin.c:94: section attributes are not supported for this target
>/usr/src/lib/csu/i386_elf/../common_elf/crtbegin.c:112: section attributes are not supported for this target
>*** Error code 1
>
>I am using NetBSD1.3/i386 with a 1.4_BETA kernel.
>gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

You are trying to build ELF userland with a non ELF compiler...
[you must have OBJECT_FMT=ELF in /etc/mk.conf or something].

If you really want to convert to elf, I've appended my makemeELF script,
but it is really, really dangerous to use...

christos


#!/bin/sh
#
# Copyright (c) 1999 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Christos Zoulas.
#
# 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.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#        This product includes software developed by the NetBSD
#        Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.

VERSION=1.4
FREESPACE=10000
EMDIR=/emul/aout/.
LIB="lib*.so.*"
LIBEXEC="cc1 cc1obj cc1plus collect2 cpp f771 ld.so"
BIN="ar as c89 cc cpp nm g++ g77 gcc ld strip"
DIRECTORIES="usr/lib usr/libexec usr/bin"
MKCONF=/etc/mk.conf
GNU=/usr/src/gnu

bail()
{
    echo "$0: *ERROR*: $@" 1>&2
    exit 1
}

nospace()
{
    bail "$EMDIR has only ${1}K free and I need ${FREESPACE}K"
}

noaout()
{
    bail "Please create $EMDIR with at least ${FREESPACE}K free"
}

badcopy() 
{
    bail "An error occured while copying [exit $1]"
}

nodirectory() 
{
    bail "Cannot make directory $1"
}

bademul()
{
    bail "You kernel does not appear to search in $EMDIR" 
}

badkernel()
{
    bail "You kernel does not appear to support COMPAT_AOUT" 
}

baddotdot()
{
    bail "You kernel does not appear to support '/../' in COMPAT_AOUT" 
}

notroot()
{
    bail "This program needs to be run as root"
}

makefailed()
{
    bail "Make had errors"
}

copy()
{
    echo -n "$0: Copying from $1..."
    eval cd $1 && tar -czf - $2 | (cd $EMDIR/new/$1 && tar -xzpf -)
    if [ $? != 0 ]; then
	badcopy $?
    else
	echo "done"
    fi
}

makeone()
{
    make $1 > /dev/null
    if [ $? != 0 ]
    then
	makefailed
    fi
}

makeme()
{
    cd $1
    echo -n "$0: running make in $1: cleaning..."
    makeone clean
    echo -n "depending..."
    makeone depend
    echo -n "including..."
    makeone includes
    echo -n "building..."
    makeone 
    echo "done"
}

getobjfmt()
{
    printf '.include "'$MKCONF'"\nall:\n\t@echo $(OBJECT_FMT)\n' | make -f -
}

uid=`id -u`
if [ $uid != 0 ]; then
    notroot
fi

if [ -d $EMDIR ]; then
    echo "$0: Cool, you have $EMDIR already made for me"
else
    noaout
fi

space=`df -k $EMDIR | grep -v Filesystem | awk '{ print $4 }'`

if [ $space -lt $FREESPACE ]; then
    nospace $space 
else
    echo "$0: And it has ${space}K free"
fi

echo "$0: Lemme make a copy of your shared libraries, and compiler tools"

echo "$0: Making directories"
for i in $DIRECTORIES
do
    mkdir -p $EMDIR/new/$i
    if [ $? != 0 ]; then
	nodirectory $EMDIR/new/$i
    fi
done

copy /usr/lib "$LIB"
copy /usr/libexec "$LIBEXEC"
copy /usr/bin "$BIN"

echo "$0: Making sure that your a.out emulation works properly."

cd $EMDIR && mv new/usr .	# enable emulation paths
cd /usr/lib; DIR=`pwd`
if [ $DIR = "/usr/lib" ]; then
    cd $EMDIR && mv usr new	# disable emulation paths
    bademul
fi
cd /../usr/lib; DIR=`pwd`
if [ $DIR != "/usr/lib" ]; then
    cd $EMDIR && mv usr new	# disable emulation paths
    baddotdot
fi

cd /../usr/libexec
mv ld.so ld.so.save
/usr/bin/who 1>&2 2> /dev/null
if [ $? != 0 ]; then
    mv ld.so.save ld.so
    cd $EMDIR && mv usr new	# disable emulation paths
    badkernel
fi

# Setup destdir so that it references the real root.
DESTDIR=/..
export DESTDIR

OBJECT_FMT=`getobjfmt`

if [ "$OBJECT_FMT" = "ELF" ]; then
    echo "$0: Removing OBJECT_FMT=ELF from $MKCONF"
    grep -v OBJECT_FMT $MKCONF > $MKCONF.new && mv $MKCONF.new $MKCONF
else
    echo "$0: Ok, there is no OBJECT_FMT statement in your $MKCONF"
fi

echo "$0: Now I am going to try to build the compiler tools"

echo "$0: Making sure that libbfd is up-to-date"
makeme $GNU/lib/libbfd

echo "$0: Making sure that the common binutils code is up-to-date"
makeme $GNU/usr.bin/binutils/common

if [ "$OBJECT_FMT" != "ELF" ]; then
    echo "$0: Adding OBJECT_FMT=ELF to $MKCONF"
    echo "OBJECT_FMT=ELF" >> $MKCONF
else
    echo "$0: Cool, you already have set OBJECT_FMT=ELF in your $MKCONF"
fi

echo "$0: Making fake crtbegin.o and crtend.o in /usr/lib"
cd / && cd usr && cd lib
for i in crtbegin.o crtbeginS.o crtend.o crtendS.o; do
    touch $i
done

for i in binutils/nm binutils/strip binutils/ar ld.new gas.new; do
    makeme $GNU/usr.bin/$i
done

for i in binutils/nm binutils/strip binutils/ar ld.new gas.new; do
    cd $GNU/usr.bin/$i
    makeone install
done

echo "$0: We are all done. We have installed the new compile tools"
echo "$0: and now you can make build and end up with an elf system"
echo "$0: Remember to set DESTDIR=/.. in your makes; Good luck"