Page 1 of 1

Opcode and Null errors in Cross Compiler

Posted: Sat Sep 01, 2012 5:03 pm
by shacknetisp
I compiled a cross compiler using the wiki's instructions, and it compiled and ran simple programs.
But when I ran this program:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char **argv)
{
char buf[128]
for(;;)
{
gets(buf); //wrong code, I know, but I entered only the letter 'L'
if(!strcmp(buf,"exit\n"))
exit(1);
else
printf("...\n");
}
}
either an Invalid Opcode exception or a Null pointer dereference happened.
This code worked fine when I used linux's gcc.
So, I was wondering if anyone else had this problem,and/ / or how I could fix it.
Thank!

Re: Opcode and Null errors in Cross Compiler

Posted: Sun Sep 02, 2012 3:34 am
by JamesM
A cross compiler isn't designed to build standalone applications for your host system. That's what your host compiler is for.

Re: Opcode and Null errors in Cross Compiler

Posted: Sun Sep 02, 2012 3:41 am
by Antti
I would say that more information is needed. I did not check your previous message history to see if this was somehow related to previous posts. I think a thread should be "stand-alone" and contain all the essential information. In this case, what is the host and the target system? Did you run this compiled code on your host system or on the target system?

Edit: JamesM answered faster with a good answer. Please continue.

Re: Opcode and Null errors in Cross Compiler

Posted: Sun Sep 02, 2012 2:49 pm
by shacknetisp
Sorry for not clarifiing it enough. The Compiler was built to run programs on my OS.

Re: Opcode and Null errors in Cross Compiler

Posted: Sun Sep 02, 2012 3:44 pm
by Combuster
The compiler is the least likely source of errors, so it must be either you using it incorrectly, or irrelevant altogether if you simply exposed a bug elsewhere. There are way too many options here. At least, it's so highly specific to your OS that nobody else will know the exact cause from merely the symptoms.

In other words, time for you to do the guru meditation.

If we are to help, we need some basics. So, you are using it to compile code with only your source and header files, bundle it into an OS image, then try executing it from your shell? You are also cloning some existing OS? How does it load binaries? What did you change?

And probably the most interesting questions: What is the faulting address? To which line of source code does it correspond?

Re: Opcode and Null errors in Cross Compiler

Posted: Mon Sep 03, 2012 3:05 am
by bluemoon
If you are working on 64 bit OS, the red-zone may cause random exception.

Re: Opcode and Null errors in Cross Compiler

Posted: Mon Sep 03, 2012 7:24 am
by shacknetisp
It's working now!!! I still don't know why is didn't, but soon I should find out. Thanks!
EDIT: Oops, Now It is not. But I'll just see if I can figure it out.

Re: Opcode and Null errors in Cross Compiler

Posted: Mon Sep 03, 2012 8:00 am
by Antti
This is a little bit offtopic but I have been wondering how it is possible that an OS developer has succesfully made a system that is capable of executing "a standard program written in C" (with a standard executable format) and still have these kind of problems.

The problem is not the fact that the specific program does not work. It is the problem solving and debugging skills that make me wonder. This seems to be a case that should quite easily be solved when compared to the steps that are needed to get this far.

Do not misunderstand what I mean. This applies in general and not only to this thread.