This is an archive of the discontinued LLVM Phabricator instance.

[ASan] Added __asan_shadow_memory variable which points to the beginning of the shadow region using some assembly trickery.
AbandonedPublic

Authored by kstoimenov on Nov 19 2021, 3:20 PM.

Details

Reviewers
vitalybuka
kcc
Summary

This is needed for the implementation of __asan_(load|store) in assembly as they need to know what is the beginning of the shadow region.

Diff Detail

Event Timeline

kstoimenov created this revision.Nov 19 2021, 3:20 PM
kstoimenov requested review of this revision.Nov 19 2021, 3:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 19 2021, 3:20 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

/__asan_shadow_memory_offset/__asan_shadow_memory/

kstoimenov retitled this revision from [ASan] Added __asan_shadow_memory_offset variable which points to the beginning of the shadow region using some assembly trickery. to [ASan] Added __asan_shadow_memory variable which points to the beginning of the shadow region using some assembly trickery..Nov 19 2021, 3:25 PM
kcc added inline comments.Nov 19 2021, 3:35 PM
compiler-rt/lib/asan/asan_rtl.cpp
40

do you need an #ifdef here?

kstoimenov added inline comments.Nov 19 2021, 3:47 PM
compiler-rt/lib/asan/asan_rtl.cpp
40

In case asan_shadow_memory_dynamic_address is used I am not defining SHADOW_OFFSET_STR. The reason is that I will have to have a different assembly code and I didn't want to support it at this time. Because of the '#if defined' it will result in unresolved external if someone is trying to use shared optimized callbacks with asan_shadow_memory_dynamic_address.

kcc added a comment.Nov 22 2021, 11:14 AM

LGTM, but please wait for Vitaly

vitalybuka added inline comments.Nov 22 2021, 11:15 AM
compiler-rt/lib/asan/asan_rtl.cpp
43

Why do you need globl and not address as a constant in asm?

44

Isn't this the same as SANITIZER_STRINGIFY(SHADOW_OFFSET)

kstoimenov abandoned this revision.Nov 22 2021, 1:11 PM

I found a better way to do this.

delcypher added inline comments.
compiler-rt/lib/asan/asan_mapping.h
187

It would be nice if we could "string-ifying" the existing constants here? E.g.

E.g.

 #define xstr(s) str(s)
 #define str(s) #s

...

#define SHADOW_OFFSET_STR xstr(SHADOW_OFFSET)

If you did something like that you only need to do #define SHADOW_OFFSET_STR once and you could hoist the definition out of the conditional macros.

Unfortunately it looks like that wouldn't work for things like kFreeBSD_ShadowOffset32 because those are global constants rather than macros.

Maybe there's another way to do it so we can avoid the duplication of constants?

Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2022, 10:16 AM