Issue 237865
Summary [clang][Driver][X86] -fsanitize=shadow-call-stack is silently accepted on x86_64 but generates no instrumentation
Labels clang
Assignees
Reporter zjy-dev
    The x86_64 ShadowCallStack implementation was removed in LLVM 9 (clang/docs/ShadowCallStack.md:9-21,
"currently only implemented for aarch64, RISC-V and Hexagon"). The driver still accepts the flag for x86_64.
Clang tags every function `shadowcallstack`, the X86 backend ignores the attribute, and the user gets an
unprotected binary with no diagnostic. i386 is rejected correctly.

```c
extern int g(int);
int foo(int x) { return g(x) + x; }   /* non-leaf */
```

Compile flag: `clang --target=x86_64-unknown-linux-gnu -O2 -fsanitize=shadow-call-stack -S`

```
$ clang --target=x86_64-unknown-linux-gnu -O2 -fsanitize=shadow-call-stack -S trigger.c   # exit=0, no warning
; Function Attrs: nounwind shadowcallstack uwtable # IR attribute set
foo:
  pushq %rbx
  movl  %edi, %ebx
  callq g@PLT
 addl  %ebx, %eax
  popq  %rbx
  retq                     # no shadow-stack push/pop; asm identical to the build without the flag
$ clang --target=i386-unknown-linux-gnu -fsanitize=shadow-call-stack ...
clang: error: unsupported option '-fsanitize=shadow-call-stack' for target 'i386-unknown-linux-gnu'
```

**Root cause.** `ToolChain::getSupportedSanitizers` (clang/lib/Driver/ToolChain.cpp:1878-1880) still adds
`SanitizerKind::ShadowCallStack` for `llvm::Triple::x86_64`, a leftover from the removed implementation, so the
unsupported-target check in SanitizerArgs is skipped. Nothing under llvm/lib/Target/X86 reads
`Attribute::ShadowCallStack`. Only `clang/test/Driver/fsanitize.c:462` (x86_64--netbsd) and a couple of
`-###` driver tests rely on the acceptance.

**Suggested fix.** Drop `x86_64` from the ShadowCallStack condition in `getSupportedSanitizers` (and update the
`-###` driver tests) so x86_64 gets the same "unsupported option" error as i386.

Environment: clang 23.1.2 (85ac560262434c9ccfc0c183ec22d4138ed647fb); Compiler Explorer clang trunk also accepts the flag
and emits identical uninstrumented code.

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

Reply via email to