I was looking through the link options and came across /align. Ive put together a small (very small) test program a built it without altering /align, i get 2.5k. If i use /align:16 i get 800bytes with the same program. This is obviously due to the libraries beening linked on a smaller boundry, but i get a warning about not specifying /driver or /vxd. Is altering this /align safe? I basically want to remove any redundant space between functions etc. Adrian
Posted on 2001-06-06 09:25:00 by Adrian
This is what the manual has to say on it :-


This option specifies the alignment of each section within
 the linear address space of the program. The number argument is in bytes and must be a power of two. The default is 4K. The linker issues a warning if the alignment produces an invalid image.
If the program runs ok then I would sat it's fine to use. what were the exact warnings? umbongo This message was edited by umbongo, on 6/6/2001 9:47:22 AM
Posted on 2001-06-06 09:37:00 by umbongo
The warning is: LINK : warning LNK4108: /ALIGN specified without /DRIVER or /VXD; image may not run It runs fine :-) I just wondered why the docs say nothing about /driver or /vxd having to be used. THe default seems to be 1k though? Adrian
Posted on 2001-06-06 09:39:00 by Adrian
some C compilers align also proc entry addresses:

  first proc


  next proc
Will the alignment of code "jump-in" addresses give a speed advantage (on Pentium) ? Some months before I aligned all my data to DWORD and got an amazing speed boost.
Posted on 2001-06-06 10:16:00 by beaster
Well, in normal Windows and Microsoft fashion, it's not mentioned in the help file about /ALIGN, but this is what that error means :

Linker Tools Warning LNK4108

/ALIGN specified without /DRIVER or /VXD; image may not run

The /ALIGN option has been specified without also specifying 
either /DRIVER or /VXD.

Bad alignment can prevent the operating system from loading the 
final image. Do not use the /ALIGN option unless building a 
driver or vxd. 

So I guess my adivce is be careful! umbongo
Posted on 2001-06-06 11:04:00 by umbongo
Ok. There has been a lot of talk about ALIGN and FILEALIGN. I hope I can settle it with this post. /ALIGN sets the memory-alignment of your sections. This is default 4k. Why? Because the page size on the IA32 architecture is 4k. You need to be able to specify various protection characteristics for your sections, and the smallest granularity this can be done on is, surprise surprise, 4k. You cannot set ALIGN smaller than 4k. You can, however, set it to any multiple of 4k. Since /ALIGN requires a power-of-two, you'll only get multiples of 4k. /FILEALIGN sets the file alignment of your sections. A value of 512 or above is fine. Smaller values works on *SOME* versions of windows, 98 and NT4 I believe. 95 and win2k will not accept less than 512. 512 is the sector-size of your harddrive, btw. And if you read in CreateFile (I think) about non-cached access, you will see that file access must be done on 512byte boundaries. Probably something to do with the disk driver. I can't really see the logic about /FILEALIGN limits, but it's a fact, so do not use values less than 512. You can also use the /OPT:NoWin98 to the linker, but iirc, it only does /FILEALIGN:512 -- /FILEALIGN:4096 is the default after win98 shipped, prolly because it makes swap file access faster.
Posted on 2001-06-11 15:16:00 by f0dder