[PATCH] D148034: [clang][driver] Disable GP relaxation with RISC-V ShadowCallStack

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 12 13:58:15 PDT 2023


MaskRay added a comment.

In D148034#4260376 <https://reviews.llvm.org/D148034#4260376>, @asb wrote:

> Will `--[no-]relax-gp` make its way into a minor gcc point release or do we need to wait for the next major release?
>
> In terms of this breaking GNU users - isn't it the case that without this option, they may get silently broken code when using the shadow call stack? Breaking loudly and early seems preferable, though of course it would be best if it's easily fixable by e.g. updating to a newer released binutils.

Yes, `-fsanitize=shadow-call-stack` using gp users will get silently broken code if linked with GNU ld, unless GNU ld is specified, or `-Wl,--no-relax` or `-Wl,--no-relax-gp` is specified.
This is an instance of the guideline proposed in https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/371/commits/bb0df41a4f2626fa039173c2a975039905dce99c

> For such platforms, care must be taken to ensure all code (compiler generated or otherwise) avoids using gp in a way incompatible with the platform specific purpose, and that global pointer relaxation is disabled in the toolchain.

Personally I think most `-fsanitize=shadow-call-stack`  users do not use GNU ld, so this incompatibility is actually minor.

`-fsanitize=shadow-call-stack` is already a quite specific configuration. For GNU ld users, I think placing the burden more on user education is fine (sorry, just that we don't have better options).

We have experience that even when the linker option `--push-state` has been available in GNU ld for ~5 years, we don't use it in Clang Driver, since using the option in the default configuration will break old GNU ld users.

> One slight tweak might be to avoid adding `--no-relax-gp` if linker relaxation is already disabled, though it's not going to matter once binutils gets support for --no-relax-gp.

Compile actions and link actions can be separate. Unfortunately Clang Driver for the link action does not have sufficient information whether linker relaxation has been disabled for all input relocatable object files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148034



More information about the cfe-commits mailing list