Issue 240259
Summary [X86][CET] Missing post-setjmp ENDBR with -fno-plt
Labels new issue
Assignees
Reporter zjy-dev
    With `-fcf-protection=branch -fno-plt`, Clang omits the post-call `endbr64` for the GOT-indirect call to `_setjmp`.

Reproduced on x86_64 Linux with Clang 23.1.2 (`85ac560262434c9ccfc0c183ec22d4138ed647fb`) and Compiler Explorer's `clang_trunk` on 2026-11-09.

### Reproducer

Save as `trigger.c`:

```c
#include <setjmp.h>

static jmp_buf ibt_env;

__attribute__((noinline)) int ibt_setjmp_probe(void) {
  int v = setjmp(ibt_env);
  if (v == 0)
    return 0;
  return 1;
}

int main(void) { return ibt_setjmp_probe(); }
```

```sh
clang --target=x86_64-unknown-linux-gnu -fcf-protection=branch \
  -fno-plt -O2 -S trigger.c -o trigger.s
```

Relevant output:

```asm
ibt_setjmp_probe:
    endbr64
    pushq %rax
    leaq ibt_env(%rip), %rdi
    callq *_setjmp@GOTPCREL(%rip)
    xorl  %ecx, %ecx # no post-call endbr64
    testl %eax, %eax
    # remaining instructions omitted
```

### Expected behavior and possible cause

`X86IndirectBranchTracking` explicitly inserts an ENDBR after calls to `returns_twice` functions. This handling should also recognize a GOT-indirect call whose global-address operand names the same function.

In `llvm/lib/Target/X86/X86IndirectBranchTracking.cpp`, `IsCallReturnTwice` requires a global operand, but its caller passes only `I->getOperand(0)`. For `CALL64m`, operand 0 is the base register (`%rip`); the global address for `_setjmp` is in the memory displacement operand (`X86::AddrDisp`). Thus the test misses this call.

Please check the relevant global-address operand of memory calls, or otherwise recover the callee's `returns_twice` property, and add coverage for `-fno-plt`.

This report is based on generated assembly and the pass's existing returns-twice handling. Runtime behavior depends on the longjmp implementation and IBT enforcement; no hardware fault or runtime bypass is claimed.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to