Opcode and Null errors in Cross Compiler

Programming, for all ages and all languages.
Post Reply
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Opcode and Null errors in Cross Compiler

Post 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!
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Opcode and Null errors in Cross Compiler

Post by JamesM »

A cross compiler isn't designed to build standalone applications for your host system. That's what your host compiler is for.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Opcode and Null errors in Cross Compiler

Post 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.
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Opcode and Null errors in Cross Compiler

Post by shacknetisp »

Sorry for not clarifiing it enough. The Compiler was built to run programs on my OS.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Opcode and Null errors in Cross Compiler

Post 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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Opcode and Null errors in Cross Compiler

Post by bluemoon »

If you are working on 64 bit OS, the red-zone may cause random exception.
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Opcode and Null errors in Cross Compiler

Post 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.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Opcode and Null errors in Cross Compiler

Post 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.
Post Reply