Skip to content

Commit 5a012f4

Browse files
authored
Asan fix - Adjust size to skip for safe load functions (#125)
The safe load functions can change size depending on the Asan instrumentation. This fix essentially bumps the size to a higher value. The ideal solution would be a compile time check/computation of these sizes.
1 parent 7c8c62e commit 5a012f4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ddprof-lib/src/main/cpp/safeAccess.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SafeAccess {
4646
}
4747

4848
static uintptr_t skipLoad(uintptr_t pc) {
49-
if (pc - (uintptr_t)load < 16) {
49+
if (pc - (uintptr_t)load < sizeSafeLoadFunc) {
5050
#if defined(__x86_64__)
5151
return *(u16*)pc == 0x8b48 ? 3 : 0; // mov rax, [reg]
5252
#elif defined(__i386__)
@@ -64,12 +64,23 @@ class SafeAccess {
6464

6565
static uintptr_t skipLoadArg(uintptr_t pc) {
6666
#if defined(__aarch64__)
67-
if ((pc - (uintptr_t)load32) < 16 || (pc - (uintptr_t)loadPtr) < 16) {
67+
if ((pc - (uintptr_t)load32) < sizeSafeLoadFunc
68+
|| (pc - (uintptr_t)loadPtr) < sizeSafeLoadFunc) {
6869
return 4;
6970
}
7071
#endif
7172
return 0;
7273
}
74+
#ifndef __SANITIZE_ADDRESS__
75+
constexpr static inline size_t sizeSafeLoadFunc = 16;
76+
#else
77+
// asan significantly increases the size of the load function
78+
// checking disassembled code can help adjust the value
79+
// gdb --batch -ex 'disas _ZN10SafeAccess4loadEPPv' ./elfparser_ut
80+
// I see that the functions can also have a 156 bytes size for the load32
81+
// and 136 for the loadPtr functions
82+
constexpr static inline size_t sizeSafeLoadFunc = 132;
83+
#endif
7384
};
7485

7586
#endif // _SAFEACCESS_H

0 commit comments

Comments
 (0)