473,725 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to determine an assembly's target platform?

We're working with some benchmarks designed to test x86 vs. x64
performance (both on a x64 system). To ensure that our assemblies are
loaded as x86 or x64, we specifically target our builds to the
appropriate platform, avoiding using the "Any CPU" setting. (It's my
understanding that on an x64 system, the runtime will JIT an "Any CPU"
assembly as x64 if it's able.)

All this raised an interesting question: given an arbitrary .NET
assembly, how can I tell how it was compiled? ILDASM shows me the PE
header, and I've found sections labeled "PE Optional Header (64 bit)"
in assemblies specifically targeted to x64. But assemblies targeted
to "Any CPU" -and- assemblies targeted to x86 seem to have "PE
Optional Header (32 bit)", leaving some ambiguity. Is there a sure-
fire way to tell? A flag among all that hex, perhaps?

--
Jeff S.

Mar 15 '07 #1
4 19527
Object01 wrote:
We're working with some benchmarks designed to test x86 vs. x64
performance (both on a x64 system). To ensure that our assemblies are
loaded as x86 or x64, we specifically target our builds to the
appropriate platform, avoiding using the "Any CPU" setting. (It's my
understanding that on an x64 system, the runtime will JIT an "Any CPU"
assembly as x64 if it's able.)

All this raised an interesting question: given an arbitrary .NET
assembly, how can I tell how it was compiled? ILDASM shows me the PE
header, and I've found sections labeled "PE Optional Header (64 bit)"
in assemblies specifically targeted to x64. But assemblies targeted
to "Any CPU" -and- assemblies targeted to x86 seem to have "PE
Optional Header (32 bit)", leaving some ambiguity. Is there a sure-
fire way to tell? A flag among all that hex, perhaps?
If you done the ildasm, you can see that .corflags is the relevant
field:

..corflags 0x00000001 // ILONLY

versus:

..corflags 0x00000003 // ILONLY 32BITREQUIRED

It's part of the CLI header, 'Flags' field. The CLI header is pointed to
by the an entry in the PE header directories, that follow PE optional
header. It's the 15th (RVA,Size) pair (aka directory entry) in that
list. The relevant details are in the ECMA 335 specification.

-- Barry

--
http://barrkel.blogspot.com/
Mar 15 '07 #2
On Mar 15, 12:24 pm, "Object01" <objec...@gmail .comwrote:
We're working with some benchmarks designed to test x86 vs. x64
performance (both on a x64 system). To ensure that our assemblies are
loaded as x86 or x64, we specifically target our builds to the
appropriate platform, avoiding using the "Any CPU" setting. (It's my
understanding that on an x64 system, the runtime will JIT an "Any CPU"
assembly as x64 if it's able.)

All this raised an interesting question: given an arbitrary .NET
assembly, how can I tell how it was compiled? ILDASM shows me the PE
header, and I've found sections labeled "PE Optional Header (64 bit)"
in assemblies specifically targeted to x64. But assemblies targeted
to "Any CPU" -and- assemblies targeted to x86 seem to have "PE
Optional Header (32 bit)", leaving some ambiguity. Is there a sure-
fire way to tell? A flag among all that hex, perhaps?

--
Jeff S.
I think I found a solution at http://blogs.msdn.com/gauravseth/arc...07/545104.aspx.
The PETYPE and 32BIT flags can be used to determine the targeted
platform.

--
Jeff S.

Mar 15 '07 #3
On Mar 15, 12:50 pm, Barry Kelly <barry.j.ke...@ gmail.comwrote:
Object01 wrote:
We're working with some benchmarks designed to test x86 vs. x64
performance (both on a x64 system). To ensure that our assemblies are
loaded as x86 or x64, we specifically target our builds to the
appropriate platform, avoiding using the "Any CPU" setting. (It's my
understanding that on an x64 system, the runtime will JIT an "Any CPU"
assembly as x64 if it's able.)
All this raised an interesting question: given an arbitrary .NET
assembly, how can I tell how it was compiled? ILDASM shows me the PE
header, and I've found sections labeled "PE Optional Header (64 bit)"
in assemblies specifically targeted to x64. But assemblies targeted
to "Any CPU" -and- assemblies targeted to x86 seem to have "PE
Optional Header (32 bit)", leaving some ambiguity. Is there a sure-
fire way to tell? A flag among all that hex, perhaps?

If you done the ildasm, you can see that .corflagsis the relevant
field:

.corflags0x0000 0001 // ILONLY

versus:

.corflags0x0000 0003 // ILONLY 32BITREQUIRED

It's part of the CLI header, 'Flags' field. The CLI header is pointed to
by the an entry in the PE header directories, that follow PE optional
header. It's the 15th (RVA,Size) pair (aka directory entry) in that
list. The relevant details are in the ECMA 335 specification.

-- Barry

--http://barrkel.blogspo t.com/
Am I interpreting ECMA 335 correctly when it says ($24.1) that ILONLY
should be ignored when read? By this reading, why would ILONLY ever
be 0, as it is in so many of the assemblies I've examined?

--
Jeff S.

Mar 15 '07 #4
Object01 wrote:
.corflags0x0000 0001 // ILONLY
Am I interpreting ECMA 335 correctly when it says ($24.1) that ILONLY
should be ignored when read? By this reading, why would ILONLY ever
be 0, as it is in so many of the assemblies I've examined?
AFAIK, in e.g. C++/CLI assembly with mixed native code (/clr), it won't
necessarily be present.

-- Barry

--
http://barrkel.blogspot.com/
Mar 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
1617
by: Johannes Bauer | last post by:
Hi group, inspired by the other inline assembly thread a question popped up in my mind... Victor Bazarov mentioned in his response that the asm() clause was covered by the C++ standard, subclause 7.3.. Well, I couldn't find the C++ standard definition on the net, so I'm asking here: Why is a thing like assembly covered by the standard at all? According to Victor's response, it seems to be totally compiler dependent what's done with...
2
1587
by: jw56578 | last post by:
Hi, Is there a way to discover all the classes within a given namespace? thanks
2
2314
by: aallee83 | last post by:
i'm new in asp.net after develop my solution i copied it on the server where I want it to run but something cares... WHAT?!?! thank you in advance File or assembly name System, or one of its dependencies, was not found. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
2
1633
by: Joe | last post by:
i would like to my c# project to have the Platform target be set to any cpu. i would like to detect at run-time whether the environment is x86, x64 or Itanium, any ideas?
3
7839
by: Shawnk | last post by:
I use two classes to manage the Main() command line (and alot of other stuff) for my prototyping environment. I tryed putting the MainClass in a DLL and just having the other class (which gets modified on a per project basis) as the 'program.cs' file (the only *.cs file). I keep getting 'Main() not defined error' even though it was defined via the DLL reference in the project.
16
3919
by: Andy | last post by:
Hi, I have read that 'C' is platform-independent and portable. I can'tsee much a difference between the two terms. Could anyone differentiate the two? Also is the statement actually true? Thanks Andy
1
1543
by: Christian Maslen | last post by:
Hi all, I have come across an issue that appears to relate to APAR IY76615: IY76615 CONNECTION WITH .NET DATA PROVIDER MAY FAIL WHEN UPGRADING TO DB2 V8 FP10 This is documented as having been fixed in fix pack 11. We upgraded the deployment target from fixpack 9 to fixpack 10 and got connection errors with our ASP.Net app. I'll post a response once I determine if
85
4838
by: fermineutron | last post by:
Some compilers support __asm{ } statement which allows integration of C and raw assembly code. A while back I asked a question about such syntax and was told that __asm is not a part of a C standard. My question now is: Is there a chance that such statement will become a part of C standard in the future? In some cases using asm language is the best way to acomplish some small task, hence integration of C and asm would greatly enhence C,...
4
3249
by: kanepart2 | last post by:
Hi, I am coding in VB using VS 2003 If I have an assembly how can I determine if it should go into the "C:\WINNT\assembly\GAC\" or the "C:\WINNT\assembly\GAC_MSIL\" or the "C:\WINNT\assembly\GAC_32\" folder ... thanks
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.