On Thu, 25 Aug 2022 14:03:56 PDT (-0700),
baturo...@gmail.com wrote:
> Hi all,
>
> I've been recently working on upstreaming HWASAN LLVM support for RISC-V.
> Brief description how HWASAN works: the idea behind HWASAN is similar to a
> regular ASAN, but in this case tag is stored in top 8 bits of the pointer,
> which is checked upon memory access with instrumented code. I.e.
> 0x2300000012341234 is a valid tagged pointer value with 0x23 as tag.
>
> Current HWASAN implementation for RISC-V mostly works except for tagging
> global variables: the existing code models and relocation sequences doesn't
> allow such address to be constructed. So such cases would fail during
> linking.
>
> I could propose a solution for this problem which is almost identical to
> the one used in AArch64. The following things have to be done:
> - Add non-checking variants of R_RISCV_HI20 and R_RISCV_PCREL_HI20
> relocations
> - Add new relocation which could set top 8 bits of global address the same
> way R_AARCH64_MOVW_PREL_G3 does
> - Switch to new relocation sequence if HWASAN tagging globals option is
> enabled
>
> I'd like to hear your opinions on this suggestion. Or maybe someone could
> suggest better ways of dealing with this issue.
pair to set the high bits, and then another add to mix in the low bits.