[zero-call-used-regs] Mark only non-debug instruction's register as used
authorShivam Gupta <shivam98.tkg@gmail.com>
Mon, 23 Jan 2023 18:16:04 +0000 (23:46 +0530)
committerShivam Gupta <shivam98.tkg@gmail.com>
Wed, 25 Jan 2023 05:34:22 +0000 (11:04 +0530)
commit7454439674a4a78b9fc9dc9ffba7a60717ee310b
tree038940b5d0c3d9d9e3c9aac15c4dbe38069612f1
parentc9401f2ebe63181e1c27e80181dc48a5c593ed56
[zero-call-used-regs] Mark only non-debug instruction's register as used

zero-call-used-regs pass generate an xor instruction to help mitigate
return-oriented programming exploits via zeroing out used registers. But
in this below test case with -g option there is dbg.value instruction
associating the register with the debug-info description of the formal
parameter d, which makes the register appear used, therefore it zero the
register edi in -g case and makes binary different from without -g option.

The pass should be looking only at the non-debug uses.

$ cat test.c
char a[];
int b;
__attribute__((zero_call_used_regs("used"))) char c(int d) {
  *a = ({
    int e = d;
    b;
  });
}

This fixes https://github.com/llvm/llvm-project/issues/57962.

Differential Revision: https://reviews.llvm.org/D138757
llvm/lib/CodeGen/PrologEpilogInserter.cpp
llvm/test/CodeGen/X86/zero-call-used-regs-debug-info.mir [new file with mode: 0644]