build order of segments

folks,

I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple C
files (say a.c and b.c) I observe that while linking the segements are
joined in the order they were compiled in. That is, a.obj’s section goes
before b.obj’s section. if a.c ws compiled before b.c. Is there a way to
have my own oder of linking defined for such cases?

thanks

AP

You’ve pretty much lost me here, but assuming what you’re saying is
correct, you could compile them in the order you need.

Why do you care about this?

mm

A P wrote:

folks,

I have #pragma code_seg (“MY_SEG”) in my C files. I have them in
multiple C files (say a.c and b.c) I observe that while linking the
segements are joined in the order they were compiled in. That is,
a.obj’s section goes before b.obj’s section. if a.c ws compiled before
b.c. Is there a way to have my own oder of linking defined for such cases?

thanks

AP

Alphabetical order: MY_SEG_A will be before MY_SEG_B, etc. You can find this technique described in a few articles if you look for it hard enough- I picked this one at random:

http://www.codeguru.com/Cpp/misc/misc/threadsprocesses/article.php/c6945__2/

It’s one of the techniques used to build tables you compile in and then process at runtime (and is a part of one solution of initializing C++ globals in the kernel, for that matter).

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Thursday, January 08, 2009 2:05 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] build order of segments

folks,

I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple C files (say a.c and b.c) I observe that while linking the segements are joined in the order they were compiled in. That is, a.obj’s section goes before b.obj’s section. if a.c ws compiled before b.c. Is there a way to have my own oder of linking defined for such cases?

thanks

AP

My recollection is that the linker does not guarantee the order in which
segments are assembled. It is not the order you compile them in, it is the
order they are linked in. This is determined by the linker command line,
but I believe the linker does not actually say that they will be assembled
in the order they appear on the command line, and in fact that can be
thought of largely as an accident of the current implementation.

I know this was true in the days when I was writing overlaid DOS code, and
the sophisticated overlay linker we were using said, in effect, that as with
the Microsoft linker, there is no guaranteed order of combining segments in
multiple compilation units. This was consistent with every other linker I
have ever used in the last four decades.

Since the order shouldn't matter anyway, I'm not sure why this matters.
Strictly speaking, if you write int i; int j; there is no reason to expect
that i and j are allocated adjacent (structs exist if you care about the
order). There have been programs which erroneously depended on such
behavior, and often failed on a new compiler release.
joe


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Thursday, January 08, 2009 5:05 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] build order of segments

folks,

I have #pragma code_seg ("MY_SEG") in my C files. I have them in multiple C
files (say a.c and b.c) I observe that while linking the segements are
joined in the order they were compiled in. That is, a.obj's section goes
before b.obj's section. if a.c ws compiled before b.c. Is there a way to
have my own oder of linking defined for such cases?

thanks

AP
--- NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: OSR Seminars – OSR To unsubscribe, visit the
List Server section of OSR Online at
ListServer/Forum

This message has been scanned for viruses and
dangerous content by http:</http:> MailScanner, and is
believed to be clean.

Every linker I have ever encountered in the last 35 years working on
computers links segments in the order it encounters them in files. Since
the compiler and linker are in this case both fed by the SOURCES directive,
this makes sense.


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” wrote in message news:xxxxx@ntdev…
> folks,
>
> I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple
> C
> files (say a.c and b.c) I observe that while linking the segements are
> joined in the order they were compiled in. That is, a.obj’s section goes
> before b.obj’s section. if a.c ws compiled before b.c. Is there a way to
> have my own oder of linking defined for such cases?
>
> thanks
>
> AP
>

yes, it is the order they are listed in the sources file.

lets say I want my custom order of linkage of these segment, that is the qn,
can that be done?

On Thu, Jan 8, 2009 at 2:18 PM, Don Burn wrote:

> Every linker I have ever encountered in the last 35 years working on
> computers links segments in the order it encounters them in files. Since
> the compiler and linker are in this case both fed by the SOURCES directive,
> this makes sense.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
>
> “A P” wrote in message news:xxxxx@ntdev…
> > folks,
> >
> > I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple
> > C
> > files (say a.c and b.c) I observe that while linking the segements are
> > joined in the order they were compiled in. That is, a.obj’s section goes
> > before b.obj’s section. if a.c ws compiled before b.c. Is there a way to
> > have my own oder of linking defined for such cases?
> >
> > thanks
> >
> > AP
> >
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Well, Bob said it is alphabetical, and I normally think of the sources
ordering, so try changing these and see. What you will not be able to do is
have “MY_SEG” ordered one way and “CODE_SEG” ordered a different way, I have
never seen any thing that would do this.


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” wrote in message news:xxxxx@ntdev…
> yes, it is the order they are listed in the sources file.
>
> lets say I want my custom order of linkage of these segment, that is the
> qn,
> can that be done?
>
>
>
>
>
>
> On Thu, Jan 8, 2009 at 2:18 PM, Don Burn wrote:
>
>> Every linker I have ever encountered in the last 35 years working on
>> computers links segments in the order it encounters them in files.
>> Since
>> the compiler and linker are in this case both fed by the SOURCES
>> directive,
>> this makes sense.
>>
>>
>> –
>> Don Burn (MVP, Windows DDK)
>> Windows Filesystem and Driver Consulting
>> Website: http://www.windrvr.com
>> Blog: http://msmvps.com/blogs/WinDrvr
>> Remove StopSpam to reply
>>
>>
>>
>>
>> “A P” wrote in message news:xxxxx@ntdev…
>> > folks,
>> >
>> > I have #pragma code_seg (“MY_SEG”) in my C files. I have them in
>> > multiple
>> > C
>> > files (say a.c and b.c) I observe that while linking the segements are
>> > joined in the order they were compiled in. That is, a.obj’s section
>> > goes
>> > before b.obj’s section. if a.c ws compiled before b.c. Is there a way
>> > to
>> > have my own oder of linking defined for such cases?
>> >
>> > thanks
>> >
>> > AP
>> >
>>
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>

Why do you care? Do you want certain pieces of data or code close together or guaranteed to be consecutive?

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Thursday, January 08, 2009 2:25 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] build order of segments

yes, it is the order they are listed in the sources file.

lets say I want my custom order of linkage of these segment, that is the qn, can that be done?

On Thu, Jan 8, 2009 at 2:18 PM, Don Burn > wrote:
Every linker I have ever encountered in the last 35 years working on
computers links segments in the order it encounters them in files. Since
the compiler and linker are in this case both fed by the SOURCES directive,
this makes sense.


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.comhttp:</http:>
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” > wrote in message news:xxxxx@ntdev…
> folks,
>
> I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple
> C
> files (say a.c and b.c) I observe that while linking the segements are
> joined in the order they were compiled in. That is, a.obj’s section goes
> before b.obj’s section. if a.c ws compiled before b.c. Is there a way to
> have my own oder of linking defined for such cases?
>
> thanks
>
> AP
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

For a description of the method I alluded to on MSDN itself, see this:

http://msdn.microsoft.com/en-us/library/7977wcck(VS.80).aspx

I’ve used this mechanism (more than once), and I know it works.

I still don’t why you want to do this, but in addition to arranging the
SOURCES file as you would like, perhaps the ‘$’ naming convention could
be used to cause to effect the #pragma part of the problem? That is, I
believe that the compiler merges all segments that have a ‘$’ sign in
their name and match up to that point:

.CRT$ABC
.CRT$EFG

I don’t know the order in which they get merged, but it might be
something to try.

Good luck,

mm

Doron Holan wrote:

Why do you care? Do you want certain pieces of data or code close
together or guaranteed to be consecutive?

*From:* xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] *On Behalf Of *A P
*Sent:* Thursday, January 08, 2009 2:25 PM
*To:* Windows System Software Devs Interest List
*Subject:* Re: [ntdev] build order of segments

yes, it is the order they are listed in the sources file.

lets say I want my custom order of linkage of these segment, that is the
qn, can that be done?

On Thu, Jan 8, 2009 at 2:18 PM, Don Burn > mailto:xxxxx> wrote:
>
> Every linker I have ever encountered in the last 35 years working on
> computers links segments in the order it encounters them in files. Since
> the compiler and linker are in this case both fed by the SOURCES directive,
> this makes sense.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com http:</http:>
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
>
> “A P” > wrote in
> message news:xxxxx@ntdev…
>
> > folks,
> >
> > I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple
> > C
> > files (say a.c and b.c) I observe that while linking the segements are
> > joined in the order they were compiled in. That is, a.obj’s section goes
> > before b.obj’s section. if a.c ws compiled before b.c. Is there a way to
> > have my own oder of linking defined for such cases?
> >
> > thanks
> >
> > AP
> >
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging
> and other seminars visit: http://www.osr.com/seminars To unsubscribe,
> visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
></mailto:xxxxx>

Bob to the rescue - that link describes exactly what I meant but
probably did not communicate very well. According to the comments in
the sample code, everything after the ‘$’ gets sorted:

// The order here is important.
// Section names must be 8 characters or less.
// The sections with the same name before the $
// are merged into one section. The order that
// they are merged is determined by sorting
// the characters after the $.

Good luck,

mm

xxxxx@microsoft.com wrote:

For a description of the method I alluded to on MSDN itself, see this:

http://msdn.microsoft.com/en-us/library/7977wcck(VS.80).aspx

I’ve used this mechanism (more than once), and I know it works.

yes but nameing the segments will end up having all those segments in the
PE. I wanted to avod that, and have one MY_SEG with custom ordering of
objects inside it. Probably impossible.

On Thu, Jan 8, 2009 at 2:29 PM, Don Burn wrote:

> Well, Bob said it is alphabetical, and I normally think of the sources
> ordering, so try changing these and see. What you will not be able to do
> is
> have “MY_SEG” ordered one way and “CODE_SEG” ordered a different way, I
> have
> never seen any thing that would do this.
>
> –
> Don Burn (MVP, Windows DDK)
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
>
>
> “A P” wrote in message news:xxxxx@ntdev…
> > yes, it is the order they are listed in the sources file.
> >
> > lets say I want my custom order of linkage of these segment, that is the
> > qn,
> > can that be done?
> >
> >
> >
> >
> >
> >
> > On Thu, Jan 8, 2009 at 2:18 PM, Don Burn wrote:
> >
> >> Every linker I have ever encountered in the last 35 years working on
> >> computers links segments in the order it encounters them in files.
> >> Since
> >> the compiler and linker are in this case both fed by the SOURCES
> >> directive,
> >> this makes sense.
> >>
> >>
> >> –
> >> Don Burn (MVP, Windows DDK)
> >> Windows Filesystem and Driver Consulting
> >> Website: http://www.windrvr.com
> >> Blog: http://msmvps.com/blogs/WinDrvr
> >> Remove StopSpam to reply
> >>
> >>
> >>
> >>
> >> “A P” wrote in message news:xxxxx@ntdev…
> >> > folks,
> >> >
> >> > I have #pragma code_seg (“MY_SEG”) in my C files. I have them in
> >> > multiple
> >> > C
> >> > files (say a.c and b.c) I observe that while linking the segements are
> >> > joined in the order they were compiled in. That is, a.obj’s section
> >> > goes
> >> > before b.obj’s section. if a.c ws compiled before b.c. Is there a way
> >> > to
> >> > have my own oder of linking defined for such cases?
> >> >
> >> > thanks
> >> >
> >> > AP
> >> >
> >>
> >>
> >>
> >> —
> >> NTDEV is sponsored by OSR
> >>
> >> For our schedule of WDF, WDM, debugging and other seminars visit:
> >> http://www.osr.com/seminars
> >>
> >> To unsubscribe, visit the List Server section of OSR Online at
> >> http://www.osronline.com/page.cfm?name=ListServer
> >>
> >
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

If you take the time to read bob?s links, it is possible. You can order within a segment with $?s the s are documented to be placed in sorted order based off of . This is how the C++ compiler autogenerates global constructor and destructor calls btw.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Thursday, January 08, 2009 2:32 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] build order of segments

yes but nameing the segments will end up having all those segments in the PE. I wanted to avod that, and have one MY_SEG with custom ordering of objects inside it. Probably impossible.

On Thu, Jan 8, 2009 at 2:29 PM, Don Burn > wrote:
Well, Bob said it is alphabetical, and I normally think of the sources
ordering, so try changing these and see. What you will not be able to do is
have “MY_SEG” ordered one way and “CODE_SEG” ordered a different way, I have
never seen any thing that would do this.


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.comhttp:</http:>
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“A P” > wrote in message news:xxxxx@ntdev…
> yes, it is the order they are listed in the sources file.
>
> lets say I want my custom order of linkage of these segment, that is the
> qn,
> can that be done?
>
>
>
>
>
>
> On Thu, Jan 8, 2009 at 2:18 PM, Don Burn > wrote:
>
>> Every linker I have ever encountered in the last 35 years working on
>> computers links segments in the order it encounters them in files.
>> Since
>> the compiler and linker are in this case both fed by the SOURCES
>> directive,
>> this makes sense.
>>
>>
>> –
>> Don Burn (MVP, Windows DDK)
>> Windows Filesystem and Driver Consulting
>> Website: http://www.windrvr.comhttp:</http:>
>> Blog: http://msmvps.com/blogs/WinDrvr
>> Remove StopSpam to reply
>>
>>
>>
>>
>> “A P” > wrote in message news:xxxxx@ntdev…
>> > folks,
>> >
>> > I have #pragma code_seg (“MY_SEG”) in my C files. I have them in
>> > multiple
>> > C
>> > files (say a.c and b.c) I observe that while linking the segements are
>> > joined in the order they were compiled in. That is, a.obj’s section
>> > goes
>> > before b.obj’s section. if a.c ws compiled before b.c. Is there a way
>> > to
>> > have my own oder of linking defined for such cases?
>> >
>> > thanks
>> >
>> > AP
>> >
>>
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Now I’m really confused - why don’t you want the segments in the PE?

Whatever the case, here’s what I had in mind; maybe it’s what you want.
I’m going to use ‘MSEG’ instead of ‘MY_SEG,’ because segments names
are limited to 8 or fewer characters, and I think that this include the
‘$’ and everything after it.

#pragma code_seg(“MSEG$AAA”)
void f1()
{
.
.
.
}
#pragma code_seg(“MSEG$AAB”)
void f2()
{
.
.
.
}
#pragma code_seg(“MSEG$AAC”)
void f3()
{
.
.
.
}

If I understand the situation correctly, these will all get merged in to
one segment named ‘MSEG,’ with ‘f1()’ coming first, followed by ‘f2(),’
and finally ‘f3().’

Good luck,

mm

A P wrote:

yes but nameing the segments will end up having all those segments in
the PE. I wanted to avod that, and have one MY_SEG with custom ordering
of objects inside it. Probably impossible.

On Thu, Jan 8, 2009 at 2:29 PM, Don Burn > mailto:xxxxx> wrote:
>
> Well, Bob said it is alphabetical, and I normally think of the sources
> ordering, so try changing these and see. What you will not be able
> to do is
> have “MY_SEG” ordered one way and “CODE_SEG” ordered a different
> way, I have
> never seen any thing that would do this.
>
> –
> Don Burn (MVP, Windows DDK)
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com http:</http:>
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
>
>
> “A P” > wrote
> in message news:xxxxx@ntdev…
> > yes, it is the order they are listed in the sources file.
> >
> > lets say I want my custom order of linkage of these segment, that
> is the
> > qn,
> > can that be done?
> >
> >
> >
> >
> >
> >
> > On Thu, Jan 8, 2009 at 2:18 PM, Don Burn > mailto:xxxxx> wrote:
> >
> >> Every linker I have ever encountered in the last 35 years working on
> >> computers links segments in the order it encounters them in files.
> >> Since
> >> the compiler and linker are in this case both fed by the SOURCES
> >> directive,
> >> this makes sense.
> >>
> >>
> >> –
> >> Don Burn (MVP, Windows DDK)
> >> Windows Filesystem and Driver Consulting
> >> Website: http://www.windrvr.com http:</http:>
> >> Blog: http://msmvps.com/blogs/WinDrvr
> >> Remove StopSpam to reply
> >>
> >>
> >>
> >>
> >> “A P” >
> wrote in message news:xxxxx@ntdev…
> >> > folks,
> >> >
> >> > I have #pragma code_seg (“MY_SEG”) in my C files. I have them in
> >> > multiple
> >> > C
> >> > files (say a.c and b.c) I observe that while linking the
> segements are
> >> > joined in the order they were compiled in. That is, a.obj’s
> section
> >> > goes
> >> > before b.obj’s section. if a.c ws compiled before b.c. Is
> there a way
> >> > to
> >> > have my own oder of linking defined for such cases?
> >> >
> >> > thanks
> >> >
> >> > AP
> >> >
> >>
> >>
> >>
> >> —
> >> NTDEV is sponsored by OSR
> >>
> >> For our schedule of WDF, WDM, debugging and other seminars visit:
> >> http://www.osr.com/seminars
> >>
> >> To unsubscribe, visit the List Server section of OSR Online at
> >> http://www.osronline.com/page.cfm?name=ListServer
> >>
> >
>
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
></mailto:xxxxx></mailto:xxxxx>

IIRC, you cann ame the segments like “MYSEG$A”, “MYSEG$B”, etc. Characters including and after the $ are chopped off in the final segment in the binary, but they’re concatenated in alpha-sorted order.

? S


From: A P
Sent: Thursday, January 08, 2009 14:05
To: Windows System Software Devs Interest List
Subject: [ntdev] build order of segments

folks,

I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple C files (say a.c and b.c) I observe that while linking the segements are joined in the order they were compiled in. That is, a.obj’s section goes before b.obj’s section. if a.c ws compiled before b.c. Is there a way to have my own oder of linking defined for such cases?

thanks

AP
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Not correct, IIRC; alphabetical order should be used. The CRT relies upon this for things like global ctors/dtors and other implicit “atexit” functionality.

? S


From: Joseph M. Newcomer
Sent: Thursday, January 08, 2009 14:18
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] build order of segments

My recollection is that the linker does not guarantee the order in which segments are assembled. It is not the order you compile them in, it is the order they are linked in. This is determined by the linker command line, but I believe the linker does not actually say that they will be assembled in the order they appear on the command line, and in fact that can be thought of largely as an accident of the current implementation.

I know this was true in the days when I was writing overlaid DOS code, and the sophisticated overlay linker we were using said, in effect, that as with the Microsoft linker, there is no guaranteed order of combining segments in multiple compilation units. This was consistent with every other linker I have ever used in the last four decades.

Since the order shouldn’t matter anyway, I’m not sure why this matters. Strictly speaking, if you write int i; int j; there is no reason to expect that i and j are allocated adjacent (structs exist if you care about the order). There have been programs which erroneously depended on such behavior, and often failed on a new compiler release.
joe

________________________________
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of A P
Sent: Thursday, January 08, 2009 5:05 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] build order of segments

folks,

I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple C files (say a.c and b.c) I observe that while linking the segements are joined in the order they were compiled in. That is, a.obj’s section goes before b.obj’s section. if a.c ws compiled before b.c. Is there a way to have my own oder of linking defined for such cases?

thanks

AP
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

This message has been scanned for viruses and
dangerous content by MailScannerhttp:</http:>, and is
believed to be clean.

NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

folks,

thank you so much for your help, this is what I wanted, and you have given
me the way out. i thank all of you for all the help.

ap

On Thu, Jan 8, 2009 at 4:34 PM, Skywing wrote:

> Not correct, IIRC; alphabetical order should be used. The CRT relies upon
> this for things like global ctors/dtors and other implicit “atexit”
> functionality.
>
> ? S
>
> ------------------------------
> From: Joseph M. Newcomer
> Sent: Thursday, January 08, 2009 14:18
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] build order of segments
>
> My recollection is that the linker does not guarantee the order in which
> segments are assembled. It is not the order you compile them in, it is the
> order they are linked in. This is determined by the linker command line,
> but I believe the linker does not actually say that they will be assembled
> in the order they appear on the command line, and in fact that can be
> thought of largely as an accident of the current implementation.
>
> I know this was true in the days when I was writing overlaid DOS code, and
> the sophisticated overlay linker we were using said, in effect, that as with
> the Microsoft linker, there is no guaranteed order of combining segments in
> multiple compilation units. This was consistent with every other linker I
> have ever used in the last four decades.
>
> Since the order shouldn’t matter anyway, I’m not sure why this matters.
> Strictly speaking, if you write int i; int j; there is no reason to expect
> that i and j are allocated adjacent (structs exist if you care about the
> order). There have been programs which erroneously depended on such
> behavior, and often failed on a new compiler release.
> joe
>
>
> ------------------------------
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *A P
> Sent: Thursday, January 08, 2009 5:05 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] build order of segments
>
> folks,
>
> I have #pragma code_seg (“MY_SEG”) in my C files. I have them in multiple C
> files (say a.c and b.c) I observe that while linking the segements are
> joined in the order they were compiled in. That is, a.obj’s section goes
> before b.obj’s section. if a.c ws compiled before b.c. Is there a way to
> have my own oder of linking defined for such cases?
>
> thanks
>
> AP
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> –
> This message has been scanned for viruses and
> dangerous content by MailScanner http:</http:>, and is
> believed to be clean.
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Don,

Every linker I have ever encountered in the last 35 years working on computers links
segments in the order it encounters them in files.

This is because in the last 35 years working on computers you, apparently, just haven’t used a decent linker, and, instead, stuck to VC/DDK/etc. Otherwise, the above statement applies only as long as a linker does not get a command-line argument that tells it to parse a custom linker script, in which you can specify the layout of your program in any way you wish - you can specify not only the order that sections appear in executable file, but their file offsets and virtual addresses they get loaded to as well…

Anton Bassov

Link.exe supports this; see /ORDER:@script

  • S

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Friday, January 09, 2009 12:57 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] build order of segments

Don,

Every linker I have ever encountered in the last 35 years working on computers links
segments in the order it encounters them in files.

This is because in the last 35 years working on computers you, apparently, just haven’t used a decent linker, and, instead, stuck to VC/DDK/etc. Otherwise, the above statement applies only as long as a linker does not get a command-line argument that tells it to parse a custom linker script, in which you can specify the layout of your program in any way you wish - you can specify not only the order that sections appear in executable file, but their file offsets and virtual addresses they get loaded to as well…

Anton Bassov


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

If I rembember correctly, the linker may ignore alphabetical order
depending on the sections’ characteristics.
For instance, discardable sections have to come last for them to be
removable.

  • Cay