https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127934

            Bug ID: 127934
           Summary: AArch64: -g -fno-var-tracking emits redundant bti c
                    before paciasp
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: compare-debug-failure
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yqtian668 at gmail dot com
  Target Milestone: ---
            Target: aarch64-unknown-linux-gnu

Created attachment 65867
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65867&action=edit
Proposed patch and regression tests

On GCC trunk, enabling debug information together with `-fno-var-tracking`
adds a redundant `bti c` before `paciasp`.

Tested revision:

```text
40b414ce63a5448495df9161aea0bfb495b47c11
```

Reproducer:

```c
int g (int);

int
f (int x)
{
  int y = g (x);
  return g (y) + 1;
}
```

Command:

```sh
aarch64-unknown-linux-gnu-gcc -O2 -mbranch-protection=standard \
  -fno-var-tracking -fcompare-debug -S source.c
```

GCC reports:

```text
cc1: error: source.c: '-fcompare-debug' failure (length)
```

The ordinary difference is:

```diff
 f:
+  hint 34 // bti c
   hint 25 // paciasp
```

`paciasp` already serves as a valid landing pad, so the BTI insertion pass is
supposed to avoid adding `bti c` in this case.  With `-g -fno-var-tracking`, a
non-executing `BEGIN_STMT` debug instruction can appear before `paciasp`.
`rest_of_insert_bti` asks for the first non-note instruction, sees the debug
instruction instead of `paciasp`, and inserts the redundant landing pad.

Skipping a leading debug instruction before checking for PAC makes the output
independent of debug information.  The focused DejaGNU test also requires one
`paciasp` and no `bti c`, so it cannot pass merely because both compilations
start emitting the redundant instruction.  It has one failure and two
unresolved checks before the fix, and three expected passes after it.

The same pass is shared with Arm, but this report establishes the natural
effect and proposed fix on AArch64.  A full gcc/g++ `aarch64.exp` before/after
comparison found no regression and only this test changed from failing to
passing.

Expected result: a debug instruction should not hide `paciasp`/`pacibsp` or
cause GCC to emit a redundant `bti c`.

Reply via email to