Different fixed pointer resolution between LTCG and non-LTCG

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Consider the following code: StrPtr = (CHAR8 *) (UINTN) (BVDT_BASE_ADDRESS + BIOS_VERSION_OFFSET);

BVDT_BASE_ADDRESS evaluates to extern const unsigned int X = 0xffe8b000
BIOS_VERSION_OFFSET evaluates to #define BIOS_VERSION_OFFSET 0x000e
The the LTCG version, this generates code like this:
0000000000011375: 45 33 E4 xor r12d,r12d // r12d = 0 0000000000011378: BA 0E B0 E8 FF mov edx,0FFE8B00Eh // -> null-terminated string
000000000001137D: 48 8B F1 mov rsi,rcx 0000000000011380: 41 8B C4 mov eax,r12d // eax = r12d == 0 rax = ? 0000000000011383: 44 38 22 cmp byte ptr [rdx],r12b 0000000000011386: 74 0C je 0000000000011394 0000000000011388: 48 FF C0 inc rax 000000000001138B: 44 38 A0 0E B0 E8 cmp byte ptr [rax-174FF2h],r12b // CPU exception here! FF 0000000000011392: 75 F4 jne 0000000000011388 0000000000011394: 48 FF C0 inc rax
But the non-LTCG version generates
mov edx, DWORD PTR X
add rdx, 0x000e
mov ecx, edx
call AsciiStrSize
Now, I understand there are some issues with converting integers into pointers and sign-extension (converting through ints) but I would expect the same behavior in LTCG and non-LTCG.

View the full article
 
Back
Top