Page 1 of 2

argh!! i hate gcc

Posted: Thu Apr 10, 2008 9:34 pm
by kubeos
I am so sick of this compiler!! I was using oslib to build my os but I wasn't happy with the GPL on it, so I got rid of it and replaced it with my own functions, which DO work. But now I'm getting problems with my old routines not working properly unless I make some of their variables volatile (stuff I do bit shifting with). These functions worked find when using oslib. I'm linking everything together the same way etc... blah blah.. Why the heck can't it just compile without stupid optimizations and crap. I've completely had it with anything that optimizes my code.

So now I'm going to scrap the whole thing and start over with the 32-bit version of my ZC compiler.. it may not be optimized, or fast, but at least I know my code will compile EXACTLY as I've written it. I can see why some people like asm...

*sigh*, well, I'm going to go watch TV, drink some beer, get a massage from my GF, and call it a day. Maybe tomorrow I'll try again, ...

Posted: Thu Apr 10, 2008 10:25 pm
by piranha
Well.......you're certainly in touch with your anger.
ya know, I would put something here more useful, like a hint or a suggestion, but i can't really think of any. And actually the only reason that I'm typing all of this into the post and not thinking it is not only that it's after 9:00pm so thinking is angry, but also that this makes this post longer, which in turn makes me feel that this post is legit, even though I know that 90% of it is just this thought.
-JL

hmmm

Posted: Thu Apr 10, 2008 10:41 pm
by kubeos
Well, I took a break and watched some tv.. the only reason I wrote that was to vent some frustration I suppose. Anyway, I don't really want to scrap everything so I'll keep playing around till I get the thing working. I've already put months of work into writing my own fat12 and 16 drivers plus a tiny gui. My only goal is to get rid of any GPL code. That's where all this frustration started. I want an OS that I can release the source to when and IF I feel like it. I just hate being forced into anything.

So next time I feel like ranting and venting frustration I'll open notepad and type it in there.
:lol:

Posted: Thu Apr 10, 2008 10:43 pm
by B.E
This reminds me of an old saying - 'if it ain't broke, don't fix it'.

Posted: Thu Apr 10, 2008 10:45 pm
by piranha
"If it jams, force it. If it breaks, it needed replacing anyway."
"Don't force it, just use a bigger hammer."
----RIP Mr. Rice!-----

-JL

Posted: Fri Apr 11, 2008 1:29 am
by JamesM
OK, so it sounds like you have some issues here.

Firstly, the addition of volatile keywords. Let's get this straight - any variable which can legitimately be modified by something outside the current thread of execution, be that another thread or a signal handler or whatever) should be marked volatile so that if you spin on its value in a loop the compiler doesn't optimise away the memory loads.

Secondly, it's not the compiler's fault that you write shoddy code. If you do however want to disable optimisations, use the "-O0" flag (that's minus capital O, zero).

It sounds like you have issues understanding the language you are writing in.

Cheers,

James

Posted: Fri Apr 11, 2008 10:48 am
by kubeos
Actually my vars where local to the routine and were never modified anywhere other than the routine. If I took off the volatile keyword they wouldn't work.. maybe I don't understand gcc well enough to be using it... but why does it have to mess with what I code. I shouldn't have to be passing -Owhatever. If I wanted any optimizations I'd do it myself. I mean any idiot realizes that

x=x+1;
x=x+1;
x=x+1;

is worse than x=x+3

I dunno, maybe I'm the only guy here who likes to know exactly what is happening with what he writes. With gcc I don't really know what it's doing with my x=x+3. More than a few times I've rewritten a routine in my kernel.asm file so I know exactly what it's doing.

works now

Posted: Fri Apr 11, 2008 11:01 am
by kubeos
SO ANYWAY...

I tried the -O0 and everything now works!! And while it may be satisfying to have my kernel working again WITHOUT oslib.. I'm a little po'd that all I needed was a simple change to my optimization to get it working.

Oh well, thank you for the suggestion.. you saved my computer from going out the window.

Posted: Fri Apr 11, 2008 12:38 pm
by JamesM
Sounds to me like you're not a particularly good coder. Or at least, you don't have the correct attitude for it.

What a sensible person would do is investigate why the code he wrote was unsafe under extremely standard compiler optimisations. GCC defaults to -O2, which is basically just constant folding and loop unrolling. No function inlining or anything weird like that. If your code was as you said it was - totally stack local with no modifications from the outside, I'd be pleased to see a snippet. It is entirely possible that you just "fixed" a symptom of a much larger problem.

Anyway, glad you fixed your problem.

Posted: Fri Apr 11, 2008 6:13 pm
by kubeos
It's possible I'm a terrible coder. But what I do write does work under normal conditions. I've written from scratch a dos based GUI complete with internet programs, browser, web server, mail client, etc. And it all works, extremely well. It's one of my proudest achievements using DJGPP. So maybe my coding skills do suck when it comes to writing freestanding code.

It's not that I don't understand what needs to be done. It's just under normal programming all the linker scripts, libc, etc are already setup properly. With my OS, I have to worry not only about my code, but how it's all getting compiled & linked together. Life would be so much easier if gcc had something like:

gcc -c -OS kernel.c -okernel.o

I actually played around a bit this morning with a very small simple kernel, and compiled it with different -O options. If I used -O0 it wouldn't clear the screen before outputting text (which it was supposed to do), but if I did -O it would work. It's things like this that are annoying me to no end.

Posted: Fri Apr 11, 2008 6:14 pm
by kubeos
I should also mention I'm using DJGPP.. maybe I should move to Cygwin or Linux? Does anyone believe this will make any difference?

Posted: Fri Apr 11, 2008 7:30 pm
by Zenith
First off, DJGPP is for DOS. Cygwin and *n[ui]x would help you greatly now and in the future. Also, consider using a cross-compiler!

Exactly what error messages are you getting with -O2 (the default optimization level, I might add)?

And there is an actual -Os flag for GCC - it optimizes for size instead of speed. :wink:

Posted: Sat Apr 12, 2008 3:16 am
by JamesM
kubeos wrote: I actually played around a bit this morning with a very small simple kernel, and compiled it with different -O options. If I used -O0 it wouldn't clear the screen before outputting text (which it was supposed to do), but if I did -O it would work. It's things like this that are annoying me to no end.
This means your code is broken. As in, it does not comply with the relevant ISO standard. All code that complies with the ISO standards will run perfectly under any number of compiler optimisations.

Posted: Sat Apr 12, 2008 6:08 am
by Craze Frog
JamesM wrote:GCC defaults to -O2, which is basically just constant folding and loop unrolling.
It does a lot more than that.

In fact -O2 doesn't even do loop unrolling. And in fact, even -O0 does constant folding...

(You have 500 000 - 600 000 lines in your work's codebase. You should really know what the most basic compiler switches for your compiler does.)

Posted: Sat Apr 12, 2008 6:23 am
by JamesM
Craze Frog wrote:
JamesM wrote:GCC defaults to -O2, which is basically just constant folding and loop unrolling.
It does a lot more than that.

In fact -O2 doesn't even do loop unrolling. And in fact, even -O0 does constant folding...

(You have 500 000 - 600 000 lines in your work's codebase. You should really know what the most basic compiler switches for your compiler does.)
I didn't say -O0 didn't do constant folding. I was wrong about loop unrolling though.

And my work's codebase is compiled with -O3 all the time. There's no need for me to know options the other levels turn off, as far as work is concerned.

Nice troll by the way, welcome back. :roll: