Custom ASAN runtime for a non-posix OS

26 views
Skip to first unread message

Renat Idrisov

unread,
Feb 6, 2023, 6:38:22 PM2/6/23
to address-sanitizer
Hi All,
It is about mips64r6 and gcc-12.2.0.

I am trying to come up with custom ASAN runtime by implementing methods like:
__asan_report_load1, asan report, etc.

I left all methods empty, printing single log line and methods returning stack allocations are returning NULL, for example:
uptr __asan_stack_malloc_0(size_t s) { printf("%s\n", __func__); return NULL; }

Instrumented binary crashes so early that it is hard to reason about what exactly is happening.

I do not see any globals that I should have initialized, is there something obvious that I am missing or binary instrumentation itself is tightly coupled with Linux so reimplementing callbacks is not enough?

Thank you!

Vitaly Buka

unread,
Feb 6, 2023, 8:30:19 PM2/6/23
to address-...@googlegroups.com
Hi,

it's hard to tell what is going on with your OS, but with linux and glibc, very likely the first callback will be triggered before glibc is initialized, so printf will crash. E.g on linux we use .preinit_array to call asan.
Maybe this is the case for you. Also asan inserts module constructors, maybe they are too early for printf.

Thanks,
Vitaly

--
You received this message because you are subscribed to the Google Groups "address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to address-saniti...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/address-sanitizer/b18d564c-84b6-468c-8d3e-12fd93de25c8n%40googlegroups.com.

Renat Idrisov

unread,
Feb 6, 2023, 9:37:53 PM2/6/23
to address-sanitizer
Hi, I was thinking that it could be too early for printf and I tried completely empty runtime as well, but it crashes similarly.

Could you tell more about module constructors? Where do they come from?
To mention, we are using custom libc and there is no C++ in the code. I was thinking that gcc instruments no advanced code, just function calls.

Thank you!

Vitaly Buka

unread,
Feb 6, 2023, 10:07:42 PM2/6/23
to address-...@googlegroups.com
try to compile some tiny example with -S --emit-llvm some

fakharu

unread,
Feb 9, 2024, 2:36:38 PMFeb 9
to address-sanitizer
Hi,

I am myself trying to over write libasan library. Please let me know if you can share the steps.

Thanks,
Fakharu 

Reply all
Reply to author
Forward
0 new messages