Page 1 of 1

c++ compiler

Posted: Tue Nov 11, 2014 8:12 am
by simon
Hi,

the c/c++ cross toolchain manual builds a c and c++ cross compiler. I did some tests yesterday. m68k-elf-g++ compiles .cpp fine but when I try to run the generated .bas the Kiwi crashes.
I suspect a problem with the linker skript (kiwi.ld) and/or the c runtime library (crt0.S). Maybe the handling of constructors and destructors is buggy. At least I never touched that code and may did remove parts of it. I don't know...
Your help is highly appreciated. :)

Simon

Re: c++ compiler

Posted: Tue Nov 11, 2014 10:56 am
by SteveMoody
I tried writing some C++ code to test but i was getting problem in building it. I seemed to be getting quite a lot of linker issues. I assumed it was down to my toolchain.I didn't look into it much at the time.

It could be that if you're program is compiling but crashing on run that it is down to the constructor. I would guess that it needs to know where in RAM it can allocate memory.

Re: c++ compiler

Posted: Tue Nov 11, 2014 1:47 pm
by simon
Yeah, that's what I think. The crt0 does some stuff with the constructors including setting up lists for later destructors. I may skip the whole c++ stuff again and start porting another c-written game. I still have some nice ideas. :-)

Re: c++ compiler

Posted: Sat Nov 15, 2014 4:27 pm
by simon
I found the issue. The _start is at a different address. In addition the address changes with different settings. I altered the Makefile to meet the new condition. Now we are able to use c++ with Kiwi. :)

Re: c++ compiler

Posted: Sat Nov 15, 2014 7:01 pm
by linux68k
Hi Simon

Have you posted the updates to the make file?

Thanks
Tony

Re: c++ compiler

Posted: Sat Nov 15, 2014 8:31 pm
by simon
I haven't checked in a c++ project (with the new Makefile) yet, but here you are.

Code: Select all

CC=/usr/bin/m68k-elf-gcc
CXX=/usr/bin/m68k-elf-g++
OBJCOPY=/usr/bin/m68k-elf-objcopy
OBJDUMP=/usr/bin/m68k-elf-objdump
OBJS=Cell.o  Gameboard.o  GameOfLife.o  GOFMain.o
CFLAGS=-m68000 -O3 -foptimize-sibling-calls -fomit-frame-pointer -Tkiwi.ld
CXXFLAGS=-m68000 -O3 -foptimize-sibling-calls -fomit-frame-pointer -Tkiwi.ld
LDFLAGS=-Tkiwi.ld
NAME=gol

FORMAT=binary

all:    $(NAME) $(NAME).bin $(NAME).bas

$(NAME).bas:    $(OBJS)
        $(eval ADDR:=$(shell $(OBJDUMP) -t $(NAME)|grep " _start" |  cut -d' ' -f 1 | tr -d '\n' | tail -c4 | xxd -ps))
        hexdump -ve '1/1 "%.2X"' binary.bas | sed "s/34323134/$(ADDR)/g" | xxd -r -p > $(NAME).bas
        cat $(NAME).bin >> $(NAME).bas

$(NAME):        $(OBJS)
        $(CXX) -o $(NAME) $(OBJS) $(CXXFLAGS)

$(NAME).bin:    $(OBJS)
        $(OBJCOPY) $(NAME) -O$(FORMAT) $(NAME).bin

clean:
        rm $(NAME) $(NAME).bin $(NAME).bas *.o