You are not logged in.

#1 2009-04-23 10:50:45

jedahu
Member
Registered: 2009-04-23
Posts: 4

[SOLVED] New factor-git PKGBUILD segfault

I have written a PKGBUILD for factor-git. It works fine except for two lines, which result in segfaults. What is odd, is that those lines do not segfault when run interactively in a terminal. I've exhausted my brainpower and need some help on this smile

Here is the PKGBUILD (the two lines are marked with ##############):

# Contributor: jedahu <jedahu@gmail.com>
pkgname=factor-git
pkgver=20090423
pkgrel=1
pkgdesc="Factor is a general purpose, dynamically typed, stack-based programming language."
arch=(i686 x86_64)
url="http://factorcode.org"
license=(BSD)
groups=()
backup=()
depends=(freetype2 mesa libgl)
provides=(factor)
replaces=(factor)
makedepends=(git gcc)
source=()
md5sums=()

_gitroot="git://factorcode.org/git/factor.git"
_gitname="factor"

bootarch="x86.32"
[ $CARCH = x86_64 ] && bootarch="unix-x86.64"
bootimg="boot.$bootarch.image"
bootsrc="http://factorcode.org/images/latest/$bootimg"
chksrc="http://factorcode.org/images/latest/checksums.txt"

__md5() {
    md5sum $1 | awk '{ print $1 }'
}

__checkimg() {
    msg "Checking $bootimg checksum...."
    chksum=$(awk "\$1 == \"$bootimg\" { print \$2 }" checksums.txt)
    imgsum=$(__md5 $bootimg)
    if [ $chksum != $imgsum ]; then
        msg "$bootimg checksum does not match."
        return 1
    fi
}

__getimg() {
    msg "Downloading $bootimg...."
    wget $chksrc || return 1
    wget $bootsrc || return 1
    __checkimg || return 1
}

__bootstrap() {
    make || return 1

    #####################
    ./factor -i=$bootimg || return 1
    #####################

    touch $srcdir/.built
}

build() {
    cd $srcdir

    if [ -d $_gitname ] && [ -f $startdir/src/.built ]; then
        cd $_gitname
        msg "Running factor update script...."

        ############################
        ./build-support/factor.sh update || return 1
        ############################

    elif [ -d $_gitname ] && [ -f $_gitname/$bootimg ]; then
        cd $_gitname
        __checkimg || return 1
    __bootstrap || return 1
    elif [ -d $_gitname ]; then
    cd $_gitname
        __getimg || return 1
    __bootstrap || return 1
    else
        msg "Connecting to factorcode.org GIT server...."
        git clone $_gitroot || return 1
        cd $_gitname
        __getimg || return 1
    __bootstrap || return 1
    fi

    echo $startdir
    mkdir -p $startdir/pkg/usr/bin
    mkdir -p $startdir/pkg/usr/lib/factor
    mkdir -p $startdir/pkg/usr/share/factor

    cp factor $startdir/pkg/usr/bin/f-bin
    cp $startdir/f $startdir/pkg/usr/bin/f
    chmod 0755 $startdir/pkg/usr/bin/*

    cp -a misc extra core basis $startdir/pkg/usr/lib/factor/
    cp factor.image $startdir/pkg/usr/share/factor/
}

And here is the output from running makepkg (in this case, with sources and image files already downloaded, but building factor for the first time):

$ makepkg
==> Determining latest git revision...
  -> Version found: 20090423
==> Making package: factor-git 20090423-1 x86_64 (Thu Apr 23 22:23:36 NZST 2009)
==> Checking Runtime Dependencies...
==> Checking Buildtime Dependencies...
==> Retrieving Sources...
==> Validating source files with md5sums...
==> Extracting Sources...
==> Removing existing pkg/ directory...
==> Entering fakeroot environment...
==> Starting build()...
==> Checking boot.unix-x86.64.image checksum....
make `./build-support/factor.sh make-target`
make[1]: Entering directory `/home/jdh/proj/aur/factor-git/src/factor'
make factor factor-ffi-test CONFIG=vm/Config.linux.x86.64
make[2]: Entering directory `/home/jdh/proj/aur/factor-git/src/factor'
gcc -c -Wall -O3  -fomit-frame-pointer -export-dynamic -DFACTOR_64 -o vm/os-unix.o vm/os-unix.c
...<snipped compile output>...
make[2]: Leaving directory `/home/jdh/proj/aur/factor-git/src/factor'
make[1]: Leaving directory `/home/jdh/proj/aur/factor-git/src/factor'
PKGBUILD: line 48: 31049 Segmentation fault      ./factor -i=$bootimg
==> ERROR: Build Failed.
    Aborting...

To complete the package I do the following:

cd src/factor
./factor -i=boot.unix-x86.64.image  # or boot.x86.32.image
cd -
sed -e 's/\.\/factor/\# \.\/factor/' PKGBUILD >| PKGBUILD.sed   # comment out the failing line
makepkg -p PKGBUILD.sed

The same thing happens on upgrading an already build package.

$ makepkg
==> Determining latest git revision...
  -> Version found: 20090423
==> Making package: factor-git 20090423-1 x86_64 (Thu Apr 23 22:44:55 NZST 2009)
==> Checking Runtime Dependencies...
==> Checking Buildtime Dependencies...
==> Retrieving Sources...
==> Validating source files with md5sums...
==> Extracting Sources...
==> Removing existing pkg/ directory...
==> Entering fakeroot environment...
==> Starting build()...
==> Running factor update script....
Finding OS...
Finding ARCH...
Finding WORD...
OS=linux
ARCH=x86
WORD=64
FACTOR_BINARY=factor
FACTOR_LIBRARY=libfactor.a
FACTOR_IMAGE=factor.image
MAKE_TARGET=linux-x86-64
BOOT_IMAGE=boot.unix-x86.64.image
MAKE_IMAGE_TARGET=unix-x86.64
GIT_PROTOCOL=git
GIT_URL=git://factorcode.org/git/factor.git
DOWNLOADER=wget
CC=gcc
MAKE=make
COPY=cp
DELETE=rm
Checking for chmod...found!
Checking for uname...found!
Checking for git...found!
Checking for wget...found!
Checking for curl...found!
Checking for gcc...found!
Checking for make...found!
Checking for gmake...not found!
Checking for md5sum...found!
Checking for md5...not found!
Checking for cut...found!
Checking gcc version...ok.
Checking for library GL...found.
Checking for library X11...found.
Checking for library pango-1.0...found.
Updating the git repository from factorcode.org...
From git://factorcode.org/git/factor
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Backing up factor...
Done with backup.
rm -f vm/*.o
rm -f factor*.dll libfactor.{a,so,dylib} libfactor-ffi-test.{a,so,dylib} Factor.app/Contents/Frameworks/libfactor.dylib
make factor factor-ffi-test CONFIG=vm/Config.linux.x86.64
make[1]: Entering directory `/home/jdh/proj/aur/factor-git/src/factor'
gcc -c -Wall -O3 -fno-forward-propagate -fomit-frame-pointer -export-dynamic -DFACTOR_64 -o vm/os-unix.o vm/os-unix.c
...<snip successful compile output>...
make[1]: Leaving directory `/home/jdh/proj/aur/factor-git/src/factor'
Deleting old images...
wget http://factorcode.org/images/latest/checksums.txt
--2009-04-23 22:44:59--  http://factorcode.org/images/latest/checksums.txt
Resolving factorcode.org... 69.93.127.154
Connecting to factorcode.org|69.93.127.154|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 273 [text/plain]
Saving to: `checksums.txt'

100%[=====================================================================================================================================================================================================>] 273         --.-K/s   in 0s      

2009-04-23 22:45:00 (36.5 MB/s) - `checksums.txt' saved [273/273]

Factorcode md5: 6731b200fe282a8c683742efd89aa5c1
Disk md5: 6731b200fe282a8c683742efd89aa5c1
Your disk boot image matches the one on factorcode.org.
build-support/factor.sh: line 460:  7464 Segmentation fault      ./$FACTOR_BINARY -i=$BOOT_IMAGE
==> ERROR: Build Failed.
    Aborting...

A similar workaround completes the building process:

cd src/factor
./factor -i=boot.unix-x86.64.image  # or boot.x86.32.image
cd -
sed -e 's/\.\/build/\# \.\/build/' PKGBUILD >| PKGBUILD.sed   # comment out the failing line
makepkg -p PKGBUILD.sed

Does anyone have any idea why "./factor -i=<boot image>" is segfaulting when run via makepkg, but runs fine when started interactively?

Last edited by jedahu (2009-04-24 00:31:28)

Offline

#2 2009-04-23 11:18:36

jedahu
Member
Registered: 2009-04-23
Posts: 4

Re: [SOLVED] New factor-git PKGBUILD segfault

Looks like it's an issue with factor. It still segfaults with "./factor -i=$bootimg" replaced with "factor -run=listener" (existing installation of factor).

Offline

#3 2009-04-23 11:33:22

jedahu
Member
Registered: 2009-04-23
Posts: 4

Re: [SOLVED] New factor-git PKGBUILD segfault

Forgot to include a file. The following should be placed in the same directory as PKGBUILD.

./f

#!/bin/sh
[ ! -d $HOME/.factor ] && mkdir $HOME/.factor
[ ! -d $HOME/.factor/factor.image ] && cp /usr/share/factor/factor.image ~/.factor/
[ ! -h $HOME/.factor/libs ] && ln -s /usr/lib/factor/* ~/.factor/

/usr/bin/f-bin -i=$HOME/.factor/factor.image $*

Offline

#4 2009-04-23 19:25:05

sekenre
Member
Registered: 2009-04-14
Posts: 16

Re: [SOLVED] New factor-git PKGBUILD segfault

Hi Jedahu,

Found your problem. Factor does not like running with the fakeroot environment. If you run makepkg as root with the option --asroot it works fine.

sudo makepkg --asroot

Another suggestion would be to add the option --depth 1 to your git clone command so it only downloads the latest version rather than the full revision history. Works much faster smile

git clone $_gitroot --depth 1

I might suggest also that you don't make the final image part of the package, Just use your factor wrapper script to use the boot image when it is run first by a new user. This will probably halve the size of the final package. Thats just personal preference though.

Cheers,
Sek

Offline

#5 2009-04-24 00:30:46

jedahu
Member
Registered: 2009-04-23
Posts: 4

Re: [SOLVED] New factor-git PKGBUILD segfault

Thanks sekenre!

When I'm done I'll upload it to the AUR.

Offline

Board footer

Powered by FluxBB