[all-commits] [llvm/llvm-project] 495662: [hwasan] Add __hwasan_record_frame_record to the h...

PiJoules via All-commits all-commits at lists.llvm.org
Wed Jul 13 14:09:03 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4956620387ee45a48a394853a47ddd65195c4cc6
      https://github.com/llvm/llvm-project/commit/4956620387ee45a48a394853a47ddd65195c4cc6
  Author: leonardchan <leonardchan at google.com>
  Date:   2022-07-14 (Thu, 14 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_record_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_record_frame_record)

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




More information about the All-commits mailing list