After adding the /TSAWARE linker flag to one of my projects (Visual Studio 6), I was surprised to find a new section in the PE file (.idata). If I don't set the flag, the imports are merged into .rdata.
To illustrate the "problem" we start out with a simple console program:
#include <stdio.h>
int main()
{
printf("hello world\n");
return 0;
}
and compile with: cl /Og /O1 /GF /WX /c main.c
Then link with
link /MACHINE:IX86 /SUBSYSTEM:CONSOLE /RELEASE /OUT:a.exe main.obj
link /MACHINE:IX86 /SUBSYSTEM:CONSOLE /RELEASE /OUT:b.exe /TSAWARE main.obj
Let's compare the dumpbin output:
Dump of file a.exe
File Type: EXECUTABLE IMAGE
Summary
4000 .data
1000 .rdata
5000 .text
Dump of file b.exe
File Type: EXECUTABLE IMAGE
Summary
4000 .data
1000 .idata
1000 .rdata
5000 .text
So for some reason, the linker decides that the imports cannot be merged.
But if we run editbin /TSAWARE a.exe
only the DLL characteristics field in the PE optional header is changed.
Can anyone explain this to me? Is this a bug in the linker or can the executable changed by editbin end up not working on certain systems?