www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/11/20/18:46:44

Message-ID: <3BF5B3EB.2040003@ESTOwanadoo.es>
From: Aitor Santamaria Merino <aitor DOT smQUITA AT ESTOwanadoo DOT es>
User-Agent: Mozilla/5.0 (Windows; U; Win98; es-ES; rv:0.9.4) Gecko/20011019 Netscape6/6.2
X-Accept-Language: es-es
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: DOS Exec() for COFF-Executables
Lines: 71
Date: Sat, 17 Nov 2001 00:39:11 GMT
NNTP-Posting-Host: 10.20.31.4
X-Complaints-To: usenet AT teleline DOT es
X-Trace: telenews.teleline.es 1005957551 10.20.31.4 (Sat, 17 Nov 2001 01:39:11 MET)
NNTP-Posting-Date: Sat, 17 Nov 2001 01:39:11 MET
Organization: Terra Networks
X-Received-Date: Sat, 17 Nov 2001 01:39:11 MET (telenews.teleline.es)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi all,

I have now discovered the whole of the anatomy of a COFF executable
file. Fortunately, it has no relocation, no symbols (as expected).

Now the code has three sections. These sections are
.data
(for data segment, constants, ?variables?)
.text
(for code segment)
.bss
(for stack segment)

There's something else that I'd like to know about how EXEC for this
type of files works.

(1) I suppose that the sections are loaded. Now, for COFF executables,
are EDS and ECS selectors for different segments, meaning that .data and
.text are loaded into different segments?

(2) Is the stack segment of a program empty when it starts up?

(3) (I asked one of these questions in this list a couple of days ago).
I'll use C terminology for a widest audience (I suppose), but I'd like
to know also for (Free)Pascal.

suppose I do
void proc();
void (*a)() = &proc;

void proc() {}
void main () {}

Then what would a have? the reply was: relative to 0. Does this mean,
relative to where you locate .text?

The converse is:

int a;
void proc() { a++}

Now, how does proc know a's address? Would this be relative to 0,
meaning relative to where you place .data?

Marco also added:
  > One just adds
  > the baseaddr to each reference (procedure address or variable)
  >
  > My C knowledge is not that good but:
  > So in the above, "a" is probably loaded and stored, both need
patching. Proc
  > is referenced -> needs patching.
  > Main is called (from startup code) -> needs patching.
  >All init and finalisation code in libraries need patching in the same 
way.

What if I load both of these in the same segment? Does 'patching' mean
that I need to go through the binary code of each function and patch all
the possible references of variables? How on earth can I do this?

Or perhaps there's no reasonable way to load both into the same segment...

(4) Finally, how do I know where the main() code starts?  Will EIP in
the EXE file point to main() relative to .text base location?

Thanks in advance!

Aitor



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019