Skip to content

wiki: mention workarounds __builtin_frame_address(0) and _AddressOfReturnAddress() #1688

@chrstphrchvz

Description

@chrstphrchvz

https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn#compatibility currently says:

Compatibility

The fake stack may be incompatible with some low-level code that uses certain assumptions about the stack memory layout.

  • Code that takes an address of a local variable and assumes the variable is localed on the real stack.

I think it is worth mentioning here the workarounds which some projects have used to allow such code continue working under ASan’s use-after-return detection:

https://github.com/llvm/llvm-project/blob/llvmorg-10.0.0-rc1/clang/lib/Basic/Stack.cpp#L24 seems like a neat example of this. For added portability, those borrowing it may also want to preface it with:

#ifndef __has_builtin
#define __has_builtin(x) 0 /* for non-clang compilers */
#endif

as suggested by https://clang.llvm.org/docs/LanguageExtensions.html#has-builtin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions