Page 1 of 1

Interfacing NASM with GCC or LD

Posted: Wed Sep 05, 2007 1:47 am
by neon
Hey everyone,

Im developing a new makefile, but am running into a strange problem that I have never seen before... My problem is very simular to This thread

Here is the problem:

I have 2 files: Stage3.asm, and Main.c. I can assemble and compile them seperately just fine. However, I am unable to do both.

I recieve this error:
nasm -f elf Stage3.asm -o Stage3.o
gcc Main.c -c
Main.c: In function `main':
Main.c:2: warning: return type of `main' is not `int'
Exiting due to signal SIGSEGV
General Protection Fault at eip=000859cf
eax=fff50000 ebx=fff50000 ecx=000002b8 edx=fff60000 esi=00000c20 edi=00003fc0
ebp=001257f8 esp=001257e4 program=c:\djgpp\bin\as.exe
cs: sel=0257 base=02b80000 limit=7d46ffff
ds: sel=025f base=02b80000 limit=7d46ffff
es: sel=025f base=02b80000 limit=7d46ffff
fs: sel=022f base=00016cb0 limit=0000ffff
gs: sel=026f base=00000000 limit=0010ffff
ss: sel=025f base=02b80000 limit=7d46ffff
App stack: [001258d0..000a58d0] Exceptn stack: [000a5824..000a38e4]

Call frame traceback EIPs:
0x000859cf
0x00081485
0x00082897
0x0000d5d0
0x0001d43d
0x00005de8
0x000853c2
make.exe: *** [all] Error 1
Notice that GCC has nothing to do with Stage3. What makes this strange is that, I can completely delete the code from both files (Stage3.asm and Main.c), and still recieve this error... wtf? Because of this, providing the code will not help, as it does not seem to be the problem (As I still recieve the error without it) It works if I assemble, or just compile--but if I do both, I get this crash. I also recieve this crash when interfacing the NASM with LD.

I should note that this is the GCC and LD provided with DJGPP. It worked fine with my previous systems; it does not seem to work now though...

I also should note that the above is generated by a makefile. I will post it, if anyone thinks that might be the problem.

Any help is appreciated,

Thanks! :D

Posted: Wed Sep 05, 2007 2:03 am
by JamesM
So you've tried running the EXACT commands the makefile spat out manually, and they what? still crash? or don't?

Posted: Wed Sep 05, 2007 2:25 am
by neon
JamesM wrote:So you've tried running the EXACT commands the makefile spat out manually, and they what? still crash? or don't?
I have JUST tried that :wink:

First, I modified the makefile to hardcode the commands (for now, til the problem is resolved):

Code: Select all

all:
	nasm -f elf Stage3.asm -o Stage3.o
	gcc -ffreestanding -nostdlib -nostartfiles -fno-builtin main.c -o main.o
This is not the complete makefile--Just the part that gets executed via commands.

*edit: Okay--Now this *is* the only lines in the makefile, to insure nothing else could be causing the problem.

On command line, I tried these exact commands, and they work just fine:

Code: Select all

C:\MicroOS\Source\SysCore>nasm -f elf Stage3.asm -o Stage3.o

C:\MicroOS\Source\SysCore>gcc -ffreestanding -nostdlib -nostartfiles -fno-builti
n main.c -o main.o
c:/djgpp/bin/ld.exe: warning: cannot find entry symbol start; defaulting to 0000
10d0
When executed from the makefile:

Code: Select all

nasm -f elf Stage3.asm -o Stage3.o
gcc -ffreestanding -nostdlib -nostartfiles -fno-builtin main.c -o main.o
Exiting due to signal SIGSEGV
General Protection Fault at eip=000859cf
eax=fff50000 ebx=fff50000 ecx=000002b8 edx=fff60000 esi=00000c08 edi=00003fc0
ebp=001257f8 esp=001257e4 program=c:\djgpp\bin\as.exe
cs: sel=0257  base=02b80000  limit=7d46ffff
ds: sel=025f  base=02b80000  limit=7d46ffff
es: sel=025f  base=02b80000  limit=7d46ffff
fs: sel=022f  base=00016cf0  limit=0000ffff
gs: sel=026f  base=00000000  limit=0010ffff
ss: sel=025f  base=02b80000  limit=7d46ffff
App stack: [001258d0..000a58d0]  Exceptn stack: [000a5824..000a38e4]

Call frame traceback EIPs:
  0x000859cf
  0x00081485
  0x00082897
  0x0000d5d0
  0x0001d43d
  0x00005de8
  0x000853c2
make.exe: *** [all] Error 1
I see that the error refrences as.exe, which I dont know much about... ...yet.

Any help is appreciated :D

Posted: Wed Sep 05, 2007 2:46 am
by neon
Hmm...

I just tested it with a batch script, and it works just fine as well. Please note that it was a direct copy from my makefile.

I think we can then assume that it only crashes running through MAKE.

Here is the batch script--directly copied from the makefile:

Code: Select all

   nasm -f elf Stage3.asm -o Stage3.o 
   gcc -ffreestanding -nostdlib -nostartfiles -fno-builtin main.c -o main.o 
This is another thread simular to mine. Except in that thread, they purposed the problem was that DJGPP does not support ELF; which is does,

Out of interest though, I tried assembling without using ELF:

Code: Select all

   nasm Stage3.asm -o Stage3.o 
...I still recieved the crash when executing from the makefile :(

Posted: Wed Sep 05, 2007 3:31 am
by neon
I think Im just going to go with Visual studio, instead.

Thanks, anyways.

Suggestions are still welcome, though :wink:

Posted: Wed Sep 05, 2007 8:21 am
by Combuster
Build a GCC Cross-Compiler. that way you get a GNU toolchain like djgpp's, but without the legacy issues and the bugs.

Posted: Wed Sep 05, 2007 11:43 am
by neon
Ah--Too late :(

Actually I wanted to share a very nice resource about loading and executing PE Executables:

CLICKY

Im happy--I got a 32 bit PE Kernel running in 4 lines of assembly, that calls
the C++ entry point directly from my second stage bootloader. ;)

Im currently using MSVC++ 2005 for the kernel.