[PATCH] D137044: [ClangFE] Add support for option -mno-pic-data-is-text-relative

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 17:43:42 PDT 2022


MaskRay added a comment.

In D137044#3901481 <https://reviews.llvm.org/D137044#3901481>, @uweigand wrote:

> In D137044#3901025 <https://reviews.llvm.org/D137044#3901025>, @MaskRay wrote:
>
>> Can you describe the motivation adding this option? Is it for a FDPIC ABI? Removing the assumption that text and data has a constant offset generally make the code worse for data access. This is almost assuredly a bad idea if the system has a memory management unit.
>
> This is intended to be used for "kpatch" - the Linux kernel live-patching facility.  This allows replacing parts of the kernel code with an updated version at runtime.   However, the *data* segment cannot be moved since it is already in use (and pointers to the data may be around), and so the replacement text segment will have to refer to the original data segment.  Since the replacement text segment will generally end up at different addresses than the original one, this means the compiler cannot make assumptions about the relative distance from code to data.
>
> Of course this in general results in worse code, but that is considered an acceptable cost to enable the live-patching feature.  Note that GCC already supports the same option with the same semantics, used for the same purpose.  The intent of supporting it in clang as well is simply to optionally enabling building the Linux kernel with clang instead of GCC while preserving the full set of kernel features.

I know the existence of livepatch in the Linux kernel though unfamiliar with it. The kernel doesn't use -mno-pic-data-is-text-relative right now for any port. Why does SystemZ need -mno-pic-data-is-text-relative for livepatch?


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

https://reviews.llvm.org/D137044



More information about the llvm-commits mailing list