|
39 | 39 | #define CACHEFLUSH(addr, size) __builtin___clear_cache(addr, addr + size);VALGRIND_CACHE_FLUSH(addr, size) |
40 | 40 | #endif |
41 | 41 |
|
| 42 | +#if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || !defined(__ORDER_BIG_ENDIAN__) |
| 43 | + #if defined(_WIN32) |
| 44 | + #define __ORDER_LITTLE_ENDIAN__ 1234 |
| 45 | + #define __ORDER_BIG_ENDIAN__ 4321 |
| 46 | + #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ |
| 47 | + #else |
| 48 | + #include <endian.h> |
| 49 | + #endif |
| 50 | +#endif |
| 51 | + |
42 | 52 | #if defined(__aarch64__) || defined(_M_ARM64) |
43 | 53 | #define CODESIZE 16U |
44 | 54 | #define CODESIZE_MIN 16U |
|
76 | 86 | // NOP |
77 | 87 | // LDR.W PC, [PC] |
78 | 88 | #define REPLACE_FAR(t, fn, fn_stub)\ |
79 | | - uint32_t clearBit0 = fn & 0xfffffffe;\ |
| 89 | + uint32_t clearBit0 = (uintptr_t)fn & 0xfffffffe;\ |
80 | 90 | char *f = (char *)clearBit0;\ |
81 | 91 | if (clearBit0 % 4 != 0) {\ |
82 | 92 | *(uint16_t *)&f[0] = 0xbe00;\ |
|
208 | 218 | // For ppc64le (Little Endian, ELFv2 ABI) |
209 | 219 | // https://maskray.me/blog/2023-02-26-linker-notes-on-power-isa |
210 | 220 | // https://llvm.org/devmtg/2014-04/PDFs/Talks/Euro-LLVM-2014-Weigand.pdf |
211 | | - // PowerPC64 LE (ELFv2 ABI) - Direct jump, no TOC descriptor needed |
| 221 | + // PowerPC64 LE (ELFv2 ABI) - LEP |
| 222 | + // readelf -h test_function : Flags: 0x2, abiv2 |
212 | 223 | #define CODESIZE 28U |
213 | 224 | #define CODESIZE_MIN 28U |
214 | 225 | #define CODESIZE_MAX CODESIZE |
215 | 226 | #define REPLACE_FAR(t, fn, fn_stub) \ |
216 | 227 | do { \ |
217 | 228 | uint64_t addr = (uint64_t)(fn_stub); \ |
218 | | - uint32_t* p = (uint32_t*)(fn); \ |
| 229 | + uint32_t* p = (uint32_t*)(fn + 8); \ |
219 | 230 | p[0] = 0x3d800000 | ((addr >> 48) & 0xFFFF); /* lis r12, hi16 */ \ |
220 | 231 | p[1] = 0x618c0000 | ((addr >> 32) & 0xFFFF); /* ori r12, mid16 */ \ |
221 | 232 | p[2] = 0x798c07c6; /* rldicr r12, r12, 32, 31 */ \ |
|
227 | 238 | } while (0) |
228 | 239 | #define REPLACE_NEAR(t, fn, fn_stub) REPLACE_FAR(t, fn, fn_stub) |
229 | 240 | #elif defined(__powerpc64__) |
230 | | - // PowerPC64 BE (ELFv1 ABI) - Use function descriptor to load code + TOC |
| 241 | + // PowerPC64 BE (ELFv1 ABI) - Use function descriptor to load code + TOC(Table of Contents) |
231 | 242 | #define CODESIZE 36U |
232 | 243 | #define CODESIZE_MIN 36U |
233 | 244 | #define CODESIZE_MAX CODESIZE |
|
0 commit comments