PDA

View Full Version : Building a working dc toolchain



Neuromancer88
October 21st, 2010, 06:46
Hello,

I'm trying to get a working dreamcast toolchain in ubuntu, but I've had little success.

Currently I'm attempting to use:
binutils-2.20.1
gcc-4.4.5.tar.bz2 (the gcc-4.4.4 patch included with KOS applies cleanly, and I've also tried gcc-4.4.4 repeatedly as well with no changes)
newlib-1.18.0

I've tried using kos/utils/dc-chain/Makefile to get things going. The makefile won't give me libgcc, so some arm/sound related portion of kos fails because it can't find libgcc.

I've reversed engineered the makefile a bit and created my own lame script (hey it's a work in progress) for compiling the toolchain, adding support for building and installing libgcc. KOS will now compile, however, all the examples fail with symbol errors:

/dreamcast/kos/lib/dreamcast/libkallisti.a(init.o): In function `arch_shutdown':
/dreamcast/kos/kernel/arch/dreamcast/kernel/init.c:244: undefined reference to `_fini'
/dreamcast/kos/lib/dreamcast/libkallisti.a(init.o): In function `arch_main':
/dreamcast/kos/kernel/arch/dreamcast/kernel/init.c:196: undefined reference to `_init'
collect2: ld returned 1 exit status
make: *** [2ndmix.elf] Error 1

Can anyone tell me what's causing these symbol errors?

Here's how I'm building everything:
Binutils sh:
../binutils-2.20.1/configure --target=sh-elf --prefix=/dreamcast/dc/sh-elf
make -j#
make install

Binutils arm:
../binutils-2.20.1/configure --target=arm-elf --prefix=/dreamcast/dc/arm-elf
make -j#
make install

gcc bootstrap:
../gcc-4.4.5/configure --target=sh-elf --prefix=/dreamcast/dc/sh-elf --without-headers --with-newlib --enable-languages=c --disable-libssp --disable-tls --disable-nls --with-multilib-list=m4-single-only,m4-nofpu,m4 --with-endian=little --with-cpu=m4-single-only
make -j# all-gcc all-target-libgcc
make install-gcc install-target-libgcc

newlib:
../newlib-1.18.0/configure --target=sh-elf --prefix=/dreamcast/dc/sh-elf

make all install CC_FOR_TARGET=/dreamcast/dc/sh-elf/bin/sh-elf-gcc AS_FOR_TARGET=/dreamcast/dc/sh-elf/bin/sh-elf-as LD_FOR_TARGET=/dreamcast/dc/sh-elf/bin/sh-elf-ld AR_FOR_TARGET=/dreamcast/dc/sh-elf/bin/sh-elf-ar RANLIB_FOR_TARGET=/dreamcast/dc/sh-elf/bin/sh-elf-ranlib

newlib includes fixup:
cp /dreamcast/kos/include/pthread.h /dreamcast/dc/sh-elf/include/
cp /dreamcast/dc/kos/include/sys/_pthread.h /dreamcast/dc/sh-elf/include/sys/
cp /dreamcast/dc/kos/include/sys/sched.h /dreamcast/dc/sh-elf/include/sys/
ln -nsf /dreamcast/dc/kos/include/kos /dreamcast/dc/sh-elf/include/
ln -nsf /dreamcast/dc/kos/kernel/arch/dreamcast/include/arch /dreamcast/dc/sh-elf/include/
ln -nsf /dreamcast/dc/kos/kernel/arch/dreamcast/include/dc /dreamcast/dc/sh-elf/include/


gcc final sh:
../gcc-4.4.5/configure --target=sh-elf --prefix=/dreamcast/dc/sh-elf --without-headers --with-newlib --enable-languages=c,c++ --disable-libssp --disable-tls --disable-nls --with-multilib-list=m4-single-only,m4-nofpu,m4 --with-endian=little --with-cpu=m4-single-only
make -j# all-gcc all-target-libgcc
make install-gcc install-target-libgcc

gcc final arm:
../gcc-4.4.5/configure --target=arm-elf --prefix=/dreamcast/dc/arm-elf --without-headers --without-headers --with-newlib --enable-languages=c --with-arch=armv4 --disable-libssp --disable-tls --disable-nls
make -j# all-gcc all-target-libgcc
make install-gcc install-target-libgcc


Note: KOS is able to compile this way.

BlueCrab
October 21st, 2010, 12:45
I've tried using kos/utils/dc-chain/Makefile to get things going. The makefile won't give me libgcc, so some arm/sound related portion of kos fails because it can't find libgcc.There really shouldn't be any issues with the ARM libgcc, as it should be built by dc-chain just fine. Not sure what's going wrong there, but I know I've had no problems building it (or at least it works fine under Mac OS X).

EDIT: Ah... its probably that its doing "make install-gcc"... Not sure why that's the way it is in the dc-chain Makefile, it should just be "make install" and things should just work... I'll fix that at some point.


/dreamcast/kos/lib/dreamcast/libkallisti.a(init.o): In function `arch_shutdown':
/dreamcast/kos/kernel/arch/dreamcast/kernel/init.c:244: undefined reference to `_fini'
/dreamcast/kos/lib/dreamcast/libkallisti.a(init.o): In function `arch_main':
/dreamcast/kos/kernel/arch/dreamcast/kernel/init.c:196: undefined reference to `_init'
collect2: ld returned 1 exit status
make: *** [2ndmix.elf] Error 1

Can anyone tell me what's causing these symbol errors?What I believe may be causing that is that somehow your KOS_LDFLAGS has -nostartfiles in it (which it shouldn't for GCC 4.x). After you've sourced your environ script, do "echo $KOS_LDFLAGS" and let me know what it says.

For reference, here's what mine say (and I know my toolchain works just fine):

$ echo $KOS_LDFLAGS
-ml -m4-single-only -Wl,-Ttext=0x8c010000 -T/Users/lj/Projects/clean/cadcdev/kos/utils/ldscripts/shlelf.xc -nodefaultlibs -L/Users/lj/Projects/clean/cadcdev/kos/lib/dreamcast -L/Users/lj/Projects/clean/cadcdev/kos/addons/lib/dreamcast

Neuromancer88
October 21st, 2010, 21:16
Looks like my my ld flags are the same as your's:

echo $KOS_LDFLAGS
-ml -m4-single-only -Wl,-Ttext=0x8c010000 -T/dreamcast/kos/utils/ldscripts/shlelf.xc -nodefaultlibs -L/dreamcast/kos/lib/dreamcast -L/dreamcast/kos/addons/lib/dreamcast

If I can find some time today, I'll set gcc to install with "make install" and see if that makes any difference.

Neuromancer88
October 21st, 2010, 21:36
No difference in changing how I build gcc. I'm now doing:
make -j12
make install

Going from 12 jobs to 1 doesn't make a difference either (not that I'd expect it to anyway).

BlueCrab
October 22nd, 2010, 00:24
Doing just "make install" would only change that libgcc wasn't installed.

Someone else over at dcemulation had a similar problem with _init and _fini. I'm not entirely sure how he fixed it though, in all honesty... Here's a link to the relevant discussion: http://dcemulation.org/phpBB/viewtopic.php?f=29&t=100060&start=60 . Perhaps you might try asking in that topic...

Neuromancer88
October 22nd, 2010, 04:21
Could've been because my environment was in a state of flux from all the different things I've tried, but I've since retried building 2ndmix and I get:

/dreamcast/kos/examples/dreamcast/2ndmix$ make
rm -f 2ndmix.elf
rm -f romdisk.img
kos-cc -c 2ndmix.c -o 2ndmix.o
2ndmix.c: In function 'font_init':
2ndmix.c:699: warning: pointer targets in passing argument 1 of 'load_pcx' differ in signedness
2ndmix.c:364: note: expected 'char *' but argument is of type 'uint8 *'
/dreamcast/kos/utils/genromfs/genromfs -f romdisk.img -d romdisk_boot -v -x .svn
0 rom 4cc10261 [0xffffffff, 0xffffffff] 37777777777, sz 0, at 0x0
1 . [0x808 , 0x4e0081 ] 0040755, sz 0, at 0x20
1 .. [0x808 , 0x4e0073 ] 0040755, sz 0, at 0x40 [link to 0x20 ]
1 e-79014.s3m [0x808 , 0x4e009f ] 0100644, sz 215944, at 0x60
/dreamcast/kos/utils/bin2o/bin2o romdisk.img romdisk romdisk.o
kos-cc -o 2ndmix.elf 2ndmix.o romdisk.o
/dreamcast/dc/sh-elf/lib/gcc/sh-elf/4.4.5/crt1.o: In function `stack_k':
(.text+0x60): undefined reference to `_stack'
/dreamcast/dc/sh-elf/lib/gcc/sh-elf/4.4.5/crt1.o: In function `main_k':
(.text+0x6c): undefined reference to `___setup_argv_and_call_main'
/dreamcast/kos/lib/dreamcast/libkallisti.a(init.o): In function `arch_abort':
/dreamcast/kos/kernel/arch/dreamcast/kernel/init.c:309: undefined reference to `_arch_real_exit'
/dreamcast/kos/lib/dreamcast/libkallisti.a(init.o): In function `arch_return':
/dreamcast/kos/kernel/arch/dreamcast/kernel/init.c:271: undefined reference to `_arch_real_exit'
/dreamcast/kos/lib/dreamcast/libkallisti.a(exec.o): In function `arch_exec_at':
/dreamcast/kos/kernel/arch/dreamcast/kernel/exec.c:88: undefined reference to `__arch_old_stack'
/dreamcast/kos/kernel/arch/dreamcast/kernel/exec.c:88: undefined reference to `__arch_old_sr'
/dreamcast/kos/kernel/arch/dreamcast/kernel/exec.c:88: undefined reference to `__arch_old_vbr'
/dreamcast/kos/kernel/arch/dreamcast/kernel/exec.c:88: undefined reference to `__arch_old_fpscr'
collect2: ld returned 1 exit status
make: *** [2ndmix.elf] Error 1

Any ideas on this particular error?

Neuromancer88
October 22nd, 2010, 07:26
SUCCESS!

Turns out as I was making this script to get around the issues I was having with kos/utils/dc-chain, I was applying the gcc patch correctly. Took a lot of grepping to figure what library was actually supposed to have these symbols.

What a n00bish mistake.

Now I'll to try a demo and see if it runs.