I am using djgpp\bin 's gcc under windows xp. What I don't get is how you change the output object format
when I do gcc -c video.c what format is it produceing for the output video.o is it elf , coff ,...
And how do I tell it what format to produce?
On the otherside I am on window so I need to either create a exe or com. But I cann't use a com format because this is a bin format with org 100h and nasm doesn't support external references in bin format.
So that leaves me with creating an .exe but then I would think I would need the obj format.
But I don't think gcc supports obj format. The closes thing is coff but I am not to familar with it.
I Did change the BITS 16 to BITS 32 in callfunc.asm compiled fine but when I try link it no luck.
Is Obj and coff the only object formats that when linked produce a PE windows compatible .exe.
Or can you use elf , a.out.
I just tried nasm -f coff callfunc.asm and ld callfunc.o video.o and it gave me an a.out file WTF is this format
is it a PE like can I do ld -o callfunc.exe callfunc.o video.o . I did it and it produced the .exe and then when I ran it it crashed. I am assuming a.out ,coff, and elf are simliar?
my nasm supports only these formats
Code: Select all
valid output formats for -f are (`*' denotes default):
* bin flat-form binary files (e.g. DOS .COM, .SYS)
aout Linux a.out object files
aoutb NetBSD/FreeBSD a.out object files
coff COFF (i386) object files (e.g. DJGPP for DOS)
elf32 ELF32 (i386) object files (e.g. Linux)
elf ELF (short name for ELF32)
elf64 ELF64 (x86_64) object files (e.g. Linux)
as86 Linux as86 (bin86 version 0.3) object files
obj MS-DOS 16-bit/32-bit OMF object files
win32 Microsoft Win32 (i386) object files
win64 Microsoft Win64 (x86-64) object files
rdf Relocatable Dynamic Object File Format v2.0
ieee IEEE-695 (LADsoft variant) object file format
macho NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files
As you can see I think my only -f choices on windows xp 32 bit machine is coff , obj , win32.
But the ld linker still complains about me not defining a entry point. But when I use
..start nasm complains about unrecognized special symbol ..start <- this is what the obj format supports for defining it's starting entry point. But apparently nasms documents say that some formats don't support ..start.
Questions
Is their a way to list all supported formats that ld can handle?
Is their a way to list all supported formats that gcc can handle ?
In my video.c file does this function only work if I am in kernal mode or can you use a pointer to video memory in user mode ? Thus if kernel mode is the case then that would explain why my program is crashing.
Do I need different segments or code , data , stack OK? Or does it have to be rodata , text , data , stack ...
Never know what names to call the standard segments.
I have try compiling with nasm and gcc then link with microsofts link linker
link /ENTRY:start /SUBSYSTEM:WINDOWS callfunc.o video.o
This worked and created an exe file how every it is crashing when running it.
Maybe I don't need gcc and can use microsoft cl compiler and nasm -f obj and
link /ENTRY:start /SUBSYSTEM:WINDOWS .
But then again I still want to know why it is crashing do I not have all the proper segment names correct?
I would think the compiler/linker would default to a certain default size if it is missing a needed segment like say stack either way I can define it if needed to.
This is the current callfunc.asm file
Code: Select all
BITS 32
segment data
greetings db 'Greetings and welcome ',13d,10d,'$'
segment code
global _start
_start:
mov ax , 25d
lea bx , [greetings]
push ax
push bx
extern _write_string
call _write_string
label2:
jmp label2
am I calling the function without poping or pushing something?
For -f win32 or obj what is the difference is this just PE exe to old exe format
http://www.delorie.com/djgpp/doc/exe/
Either way I am confused. In theory a linker takes the object files and merges each data section , code section , ...etc of the object files together and creates the entry point of the starting of the program alone with resolving all the references with the approprate offsets and address. The compiler/assemblier is just to
take the source code and turn it into machine code it is the linkers job to merge everything an resolve symbols and address...etc
So I would think you can compile the code any way you want obj , elf , coff ...etc provided you compile all the files with the same object format. Then if the linker supports linking these object file's and the option of of specifying your target output format. PE .exe then you should be all set. The problem is I don't know what format the ld linker produces by default and how to change it.
I would think maybe the input object format determines the output executable file format but if you can specify a target output independent of what the input object format was to the linker then please tell me how.
It would be cool to do some thing like nasm -f elf prog1.asm ,nasm -f elf prog2.asm ,
nasm -f elf prog3.asm ... etc then do ld -b "PE FORMAT" -o mype.exe prog1.o , prog2.o ,...etc etc
instead of having to use a specific object format to get ld to produce a specific executable format.
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH WTF WTF WTF sorry I am just frustrated.
Also, GCC on windows (cygwin) creates PE object files. You need to create a cross compiler.
So no matter what object files I use the linker will will create PE exe. But then WTF is the -b target output for in the ld switches. And I thought gcc is a cross compiler ?
So then in theory if what your saying is correct then if I take an elf file and an obj file I can use
ld -o mype myelf.o myobj.obj and it will merge the 2 different object formats into one nice PE. So never have to worry about what object format the file is I can just worry about if their is a unquie entry point.
But then I want to know how I can produce an exe file that linux can run is this what -b is for do I just specify if it is windows or linux , ....etc ect and by default ld outputs for the platform you are running on.