[all-commits] [llvm/llvm-project] 21f72c: [hwasan] Add __hwasan_add_frame_record to the hwas...

PiJoules via All-commits all-commits at lists.llvm.org
Wed Jul 13 15:15:36 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 21f72c05c4e4aa4827e23f943c5b419974448fcd
      https://github.com/llvm/llvm-project/commit/21f72c05c4e4aa4827e23f943c5b419974448fcd
  Author: Leonard Chan <leonardchan at google.com>
  Date:   2022-07-13 (Wed, 13 Jul 2022)

  Changed paths:
    M compiler-rt/lib/hwasan/hwasan.cpp
    M compiler-rt/lib/hwasan/hwasan_interface_internal.h
    M compiler-rt/test/hwasan/TestCases/deep-recursion.c
    M compiler-rt/test/hwasan/TestCases/stack-history-length.c
    M compiler-rt/test/hwasan/TestCases/stack-uar.c
    M compiler-rt/test/hwasan/TestCases/stack-uas.c
    M llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
    M llvm/test/Instrumentation/HWAddressSanitizer/prologue.ll

  Log Message:
  -----------
  [hwasan] Add __hwasan_add_frame_record to the hwasan interface

Hwasan includes instructions in the prologue that mix the PC and SP and store
it into the stack ring buffer stored at __hwasan_tls. This is a thread_local
global exposed from the hwasan runtime. However, if TLS-mechanisms or the
hwasan runtime haven't been setup yet, it will be invalid to access __hwasan_tls.
This is the case for Fuchsia where we instrument libc, so some functions that
are instrumented but can run before hwasan initialization will incorrectly
access this global. Additionally, libc cannot have any TLS variables, so we
cannot weakly define __hwasan_tls until the runtime is loaded.

A way we can work around this is by moving the instructions into a hwasan
function that does the store into the ring buffer and creating a weak definition
of that function locally in libc. This way __hwasan_tls will not actually be
referenced. This is not our long-term solution, but this will allow us to roll
out hwasan in the meantime.

This patch includes:

- A new llvm flag for choosing to emit a libcall rather than instructions in the
  prologue (off by default)
- The libcall for storing into the ringbuffer (__hwasan_add_frame_record)

Differential Revision: https://reviews.llvm.org/D128387




More information about the All-commits mailing list