c++ compiler

Assembler, C/C++ related topics

c++ compiler

Postby simon » Tue Nov 11, 2014 8:12 am

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
simon
Site Admin
 
Posts: 742
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany

Re: c++ compiler

Postby SteveMoody » Tue Nov 11, 2014 10:56 am

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.
SteveMoody
Developer
 
Posts: 273
Joined: Sat Mar 08, 2014 1:23 pm
Location: South Wales, UK

Re: c++ compiler

Postby simon » Tue Nov 11, 2014 1:47 pm

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. :-)
simon
Site Admin
 
Posts: 742
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany

Re: c++ compiler

Postby simon » Sat Nov 15, 2014 4:27 pm

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. :)
simon
Site Admin
 
Posts: 742
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany

Re: c++ compiler

Postby linux68k » Sat Nov 15, 2014 7:01 pm

Hi Simon

Have you posted the updates to the make file?

Thanks
Tony
linux68k
Developer
 
Posts: 59
Joined: Thu Feb 28, 2013 3:09 am

Re: c++ compiler

Postby simon » Sat Nov 15, 2014 8:31 pm

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
simon
Site Admin
 
Posts: 742
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest