473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 19484
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:

.corflags0x00000001 // ILONLY

versus:

.corflags0x00000003 // 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/
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:
.corflags0x00000001 // 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
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,...
2
by: jw56578 | last post by:
Hi, Is there a way to discover all the classes within a given namespace? thanks
2
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...
2
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
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...
16
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...
1
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...
85
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...
4
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.