* sequence of steps that goes from compilation to execution
@ 2004-08-17 19:34 Sudheer Vutukuru
2004-08-18 12:10 ` Jan-Benedict Glaw
0 siblings, 1 reply; 3+ messages in thread
From: Sudheer Vutukuru @ 2004-08-17 19:34 UTC (permalink / raw)
To: linux-c-programming
Hi all,
Why a program which is compiled on linux does not execute on windows..
(though the machine architecture is same)..
Also Can u please suggest me references or help me in knowing the
details of what goes on, from compilation to execution (i.e how
loading,linking libraries is done.. how addresses
are known dynamically etc.. ).
for string literals whether memory is allocated in heap or in code
segment only..
i.e char* ptr = "Hello World";
the ptr points into code segement or heap..
Thanks,
***************************************************************************
V V N Sudheer,
Master of Technology,
Dept. of Computer Science,
IIT Kanpur.
***************************************************************************
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: sequence of steps that goes from compilation to execution
2004-08-17 19:34 sequence of steps that goes from compilation to execution Sudheer Vutukuru
@ 2004-08-18 12:10 ` Jan-Benedict Glaw
0 siblings, 0 replies; 3+ messages in thread
From: Jan-Benedict Glaw @ 2004-08-18 12:10 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 2981 bytes --]
On Wed, 2004-08-18 01:04:51 +0530, Sudheer Vutukuru <sudheer.vutukuru@gmail.com>
wrote in message <55ee29e004081712346075d5b4@mail.gmail.com>:
> Hi all,
>
> Why a program which is compiled on linux does not execute on windows..
> (though the machine architecture is same)..
It's not enough that both operating system / game loader use the same
(or at least widely compatible) CPUs. Also, the whole ABI (Application
Binary Interface) and the backing file format need to be supported.
Linux uses the ELF format, while Windows uses something that's IIRC
called PEXEC (paged executable) format. That is, Windows doesn't simply
know where to load the binary to, how to initialize BSS and the like.
However, one can try to play some dirty tricks like Wine (running
Windows binaries on Linux) does. You do all the loading manually and
just start it. Upon access violations (and other things that would go
wrong), control is given back to Wine to emulate the missing parts.
> Also Can u please suggest me references or help me in knowing the
> details of what goes on, from compilation to execution (i.e how
> loading,linking libraries is done.. how addresses
> are known dynamically etc.. ).
C code gets translated to assembler, which is then compiled to object
code. (This format is already different on Windows vs. Linux.) The
object code then gets linked to the resulting final binary.
(The Linuxish view) upon startup of a dynamically linked ELF binary,
binfmt_elf.c starts the binary's "interpreter", which has to finally
(dynamically) link the binary. This is basically done by mmap()ing the
needed libraries and correcting all symbol references (so by now, the
program really knows about "printf").
After linking, control is transferred to the libc's startup function,
which will initialize the buffered IO subsystem (fprintf and friends),
call any constructor functions and (finally) jump to main(), your
program's user-visible start function.
After main() returns, control is given back to libc's shutdown functions
which may do some cleanups (like calling destructors, flushing buffers,
calling atexit functions and so on).
I guess it's quite similar on Windows, but a different file format is
used for binaries and libraries.
> for string literals whether memory is allocated in heap or in code
> segment only..
> i.e char* ptr = "Hello World";
> the ptr points into code segement or heap..
It points to a read-only data segment:)
Basically, it depends on where you define a variable and how/if you
initialize it at all where backing storage is taken from.
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: sequence of steps that goes from compilation to execution
@ 2004-08-23 15:50 Huber, George K RDECOM CERDEC STCD SRI
0 siblings, 0 replies; 3+ messages in thread
From: Huber, George K RDECOM CERDEC STCD SRI @ 2004-08-23 15:50 UTC (permalink / raw)
To: 'Sudheer Vutukuru', linux-c-programming
> Why a program which is compiled on linux does not execute on windows..
>(though the machine architecture is same)..
Different file formats. Windows uses PE (portable executable) as its file
format with the first two bytes being `MZ' (or possibly `ZM') that
designates it as a windows executable. Linux uses ELF (executible linkable
format) as its file format with the second, third and fourth bytes of the
file being `ELF'.
> Also Can u please suggest me references or help me in knowing the
>details of what goes on, from compilation to execution (i.e how
>loading,linking libraries is done.. how addresses
>are known dynamically etc.. ).
One of the best (only?) books on the subject "Linkers and Loaders" by John
Levine. It covers various file formats (from simple (i.e. DOS) up through
complex (PE and ELF)) and uses these formats to address all of the questions
that you ask. In addition, the book is availble from the authors website:
http://www.iecc.com/linker/
as well as in printed format.
> for string literals whether memory is allocated in heap or in code
>segment only..
>i.e char* ptr = "Hello World";
> the ptr points into code segement or heap..
In this case, I beleive that the C standard specifies that the string
literal
will be a constant, and as such space will be reserved in a read-only
section
of memory. This is why a statement such as:
ptr[5]='i';
will fail. Note however, that some compiles do not enforce this while
others
have flags that make string literals mutable.
George
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-08-23 15:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-17 19:34 sequence of steps that goes from compilation to execution Sudheer Vutukuru
2004-08-18 12:10 ` Jan-Benedict Glaw
-- strict thread matches above, loose matches on Subject: below --
2004-08-23 15:50 Huber, George K RDECOM CERDEC STCD SRI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).