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

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 01:09:35 PDT 2022


uweigand added a comment.

In D137044#3906898 <https://reviews.llvm.org/D137044#3906898>, @MaskRay wrote:

> 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?

This option is not present in the kernel sources, but it is used by the `kpatch` tool when building patch modules:
https://github.com/dynup/kpatch/blob/master/kpatch-build/kpatch-build

Whether or not this is needed on any platform depends on the particulars of the ISA, e.g. what is the span reachable via PC-relative instructions.


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

https://reviews.llvm.org/D137044



More information about the llvm-commits mailing list