Exetools  

Go Back   Exetools > General > General Discussion

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-27-2010, 02:09
ArC ArC is offline
VIP
 
Join Date: Jan 2003
Location: NTOSKRNL.EXE
Posts: 172
Rept. Given: 0
Rept. Rcvd 1 Time in 1 Post
Thanks Given: 5
Thanks Rcvd at 17 Times in 12 Posts
ArC Reputation: 1
Omitting unused global variables

Recently I came across somewhat strange (?) behaviour of Microsoft's link.exe (10.00.30319.01).

Code:
#include <stdio.h>

#define SECTION_NAME		".4711"

#pragma code_seg( push, r1, SECTION_NAME )
#pragma comment( linker, "/SECTION:"SECTION_NAME",RWE" )

__declspec(allocate(SECTION_NAME)) const char pString[] = "Blaaaaahhhhhhhh";

void TestFunc2()
{
	printf( __FUNCTION__"\n" );
}

void TestFunc()
{
#if 1
	printf( __FUNCTION__"\n" );
#endif

#if 1
	printf( __FUNCTION__": %s\n", pString );
#endif

	TestFunc2();
}

#pragma code_seg( pop, r1 )

void main()
{
#if 0
	TestFunc();
#endif
}
Based off my understanding of the linking process, the linker should not put TestFunc, TestFunc2 and pString into the executable image since there's no path from the entrypoint which leads to code that references them.

The linker does indeed omit TestFunc and TestFunc2, but it puts pString into the image unless I disable the reference in TestFunc.

So my question is if that's intended, correct behaviour or if this is some kind of bug in link.exe and if someone possibly knows a workaround.

Thanks in advance.

BTW The code was compiled/linked with /O2 /Ob0 /Oy and /OPT:REF.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Armadillo Environment Variables Finder 1.2 rukov Community Tools 3 12-16-2015 01:59
2004 Global Piracy Study Shub-Nigurrath General Discussion 2 07-13-2004 20:51
Tool to zero unused space??? yaa General Discussion 1 10-09-2003 20:31


All times are GMT +8. The time now is 23:30.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )