[PATCH] D120362: [sanitizer][sancov] Refactor GetNextInstructionPc/GetPreviousInstructionPc

Rainer Orth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 23 04:52:20 PST 2022


ro added a comment.

In D120362#3339616 <https://reviews.llvm.org/D120362#3339616>, @XiaodongLoong wrote:

> 



> @MaskRay
> IMO, The SPARC and MIPS branching operations have a branch delay slot, 4 more bytes occupied.

Indeed, but with an additional caveat: to be fully correct, the test program needs to become

  void foo() {
    void *caller_pc = __builtin_extract_return_addr(__builtin_return_address(0));
  }
  
  int main() {
    foo();
  }

On most CPUs, `__builtin_extract_return_addr` is a no-op, but not on SPARC, and since D91607 <https://reviews.llvm.org/D91607> `clang` implements it correctly like `gcc` already did.  I needed that in D91608 <https://reviews.llvm.org/D91608> to fix a couple of `sanitizer_common` failures when enabling that testing on SPARC.  With those changes in place, I get

  (gdb) p caller_pc
  $3 = (void *) 0x100000e18 <main+12>
  (gdb) x/4 $3-8
     0x100000e10 <main+4>:	call  0x100000df4 <foo> <- caller-pc - 8
     0x100000e14 <main+8>:	nop 
     0x100000e18 <main+12>:	ret                                   <- caller_pc
     0x100000e1c <main+16>:	restore  %g0, 0, %o0

There are more CPUs affected in `clang`, compared to `gcc`: `ARM`, `MIPS`, and `S390`, but the failure goes unnoticed because `sanitizer_common` testing is enabled for none of them.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120362/new/

https://reviews.llvm.org/D120362



More information about the llvm-commits mailing list