Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an application in which some code integrity check procedure is used. I calculate CRC of the code fragment after applicaztion is built and then check in in runtime.
All works well om 32bit platform, but there are lot of troubles on 64-bit platform.

What I have tried:

Integrity check looks like the following:

C++
codemark1_start:

   <Some code>

    codemark1_end:
    AsmCrcCodeMrk((MyTinyBuff), codemark1_start, codemark1_end, 1,Procedure);


AsmCrcCodeMrk macro looks like

C++

AsmCrcCodeMrk(DescriptorAddr, StartAddr, EndAddr, Id, BPA) \
AsmCrcCodeSig \
__asm mov EAX, offset DescriptorAddr \
__asm mov EAX, StartAddr \
__asm mov EAX, EndAddr \
__asm mov EAX, Id\
__asm mov EAX, BPA\

After compilation, the program has been processed by an additional application that "pulls out" the fragments between labels and calculates theirs CRC. Under Win32, everything compiles and works.

However, for X64 there are difficulties:

1) X64 in Visual Studio 2015 does not support inline assembler. But I can make macro as function in separate file and I can make the function __forceinline.

2) It is necessary to get addresses of labels at the compilation time. And this is a problem.

Can anyone tell me how to get addresses of labels at the compilation time for X64 platform?
Posted
Updated 21-May-18 21:18pm

1 solution

There is no method in the C/C++ standard to get the address of a label. That is probably the reason why inline assembly has been used.

So I don't see a solution besides writing the whole code in 64-bit assembly or using the GNU compiler to compile the specific code portion because that has a Using the GNU Compiler Collection (GCC): Labels as Values[^] C extension. However, this requires to make the created object file linkable with VS. See also the SO thread Address of labels (MSVC).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900