Original Post

A while ago I used the existing gccvb patches to write new ones for gcc4. It’s quite possible that they contain bugs.
So far I haven’t tested code compiled with this version on a real VB, but it runs well in Reality Boy.

Attachments:
27 Replies

Cool… that’s been on my long list of things to do once I get around to it… now I can cross it off 😉 .

DogP

tarsius4 wrote:
Just to follow up on my compilation problem: I successfully built GCC 4.4.2, used it to compile the VB demo from the dev wiki, and ran it on Mednafen.

Did you need to also download gmp, mpc, and mpfr and if so, what versions did you use? I’m trying to build the 4.4.2 toolchain on my Mac OS X machine and although I can get binutils and gcc built successfully at first, building newlib results in a segfault upon processing the first file:

v810-cc -B/Users/blitter/Downloads/gccvb.org/newlib_build/v810/newlib/ -isystem /Users/blitter/Downloads/gccvb.org/newlib_build/v810/newlib/targ-include -isystem /Users/blitter/Downloads/gccvb.org/newlib-1.17.0/newlib/libc/include -DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" -DPACKAGE_VERSION=\"1.17.0\" -DPACKAGE_STRING=\"newlib\ 1.17.0\" -DPACKAGE_BUGREPORT=\"\"  -I. -I../../../../../newlib-1.17.0/newlib/libc/stdlib -O2 -DPREFER_SIZE_OVER_SPEED -mv810  -DMISSING_SYSCALL_NAMES -fno-builtin      -g -O2   -c -o lib_a-__adjust.o `test -f '__adjust.c' || echo '../../../../../newlib-1.17.0/newlib/libc/stdlib/'`__adjust.c
../../../../../newlib-1.17.0/newlib/libc/stdlib/__adjust.c: In function ‘__adjust’:
../../../../../newlib-1.17.0/newlib/libc/stdlib/__adjust.c:44: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
make[5]: *** [lib_a-__adjust.o] Error 1
make[4]: *** [all-recursive] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-target-newlib] Error 2
make: *** [all] Error 2
macbookpro:newlib_build blitter$ 

Any other VB devs out there using Macs? FWIW I’m building using gcc 4.2.1 from Apple’s latest XCode devkit.

Okay, I just ran into a really annoying bug, (especially with the compo deadline right on the horizon.) I finally got the chance to spend a few hours coding today, and after working all the minor kinks out of my code, I tried to compile… and got this mess:

/tmp/ccexA19C.o: In function `_collide':
main.c:(.text+0x1a8a): undefined reference to `_memcpy'

There’s more of that pertaining to several other functions, and I’ve reduced it down to the fact that it’s affecting all of my functions that take a struct as a parameter. I’m assuming this is a glitch on the compiler end… Does anyone have any tips? I guess this is is my fault for not testing out structs earlier…

Are you passing the struct, or the pointer to the struct? You should be passing just the pointer. How about posting an example of what you’re calling and your function prototype?

DogP

Derr, thanks DogP, I didn’t know I had to pass pointers, I was trying to pass the structs by value. Changing that solved my problem. Is there a particular reason we can’t pass by value? For example, right now I have a procedure that does this:

void add_ship(ship);

void add_ship(ship i) {
    ships[end_ship] = i;
    end_ship++;
    if (end_ship > NUM_SHIPS-1)
	end_ship = 0;
}

(On a side note, I didn’t realize until earlier today that malloc() didn’t work, so I’m doing some kind of hackish queue implementation with an array) I really have done more C++ stuff than C stuff, so I’m not exactly sure what to do here if I can only use pointers… I tried looking into passing by reference earlier and I guess C doesn’t have that. (I probably should know this…) I also thought I could just dereference the pointer, but that gave me the same memcpy problem. Is the only solution something like:

void add_ship(ship*);

void add_ship(ship *i) {
    ships[end_ship].x = i->x;
    ships[end_ship].y = i->y;
    //Etc...
    end_ship++;
    if (end_ship > NUM_SHIPS-1)
	end_ship = 0;
}

Ship has a lot of fields in it, so I’d rather not go about it that way. Do you have a better way to do this?

You SHOULDN’T pass a struct by value because it could take a LONG time every time you go into the function, if the struct is very large, and possibly overload the stack. That would copy the struct to stack… and you CAN’T do it because memcpy isn’t implemented in gccvb. It would be pretty pointless to do, since you most likely don’t want a temporary copy on the stack.

Something like: ships[end_ship] = i; shouldn’t have worked whether it was in a function or not either, since that should also require memcpy. The way to do it is to use copymem (check your lib, since there’s probably a few different ones). Basically, it’ll just copy the data from the location of one struct to another struct.

Do something like:
copymem((void*) ships[end_ship], (void*) i, sizeof(ship)); . IIRC it’s copymem(destination, source, size), but you should check, and I’m probably missing &’s or *’s somewhere in there, but you should be able to figure it out.

And yes, malloc doesn’t work… you need to do your own memory management.

DogP

Thanks for the tips DogP. This is what I get for spending the last couple years working almost exclusively in Java. I guess I just need to think at a lower level.

 

Write a reply

You must be logged in to reply to this topic.