Vipon / viponTools

Cross platform libs and tools
MIT License
4 stars 0 forks source link

Create MOD_CODE #52

Open Vipon opened 4 months ago

Vipon commented 4 months ago
Vipon commented 4 months ago

clang-cl or MSVC compatible clang compiles MOD_CODE absolutely wrong, so need to create special workaround.

Corner of problem is how inline assembler directive ".section" procced. It breaks function and all code after MOD_CODE point are placed at the start of section ".text".

So need to force compiler to tie it up. Possible solution

volatile static int a = 1;
if (__buildin_expect(a == 0, 0)) {
    MOD_CODE(code);
}

MOD_CODE will be placed in unlikely executable path. Lost part of initial function will be at likely path. There is only only one problem - it produces extra instructions for if clause. Maybe need to save MSVC type for pointer and replace useless code with NOPs.