[PATCH] D61613: [LLD][ELF] Add the -z ifunc-noplt option

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 20:09:18 PDT 2019


MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks for your explanation. I wanted to make sure the caveats of `-z ifunc-noplt` have been considered, the alternatives are compared before you decide to push forward these efforts :)

> Over time, as vendors introduce new CPU features, our code accrues more and more of these tests. ifuncs are an attractive mitigation for this problem,

I will be glad if this helps some code organization problems! I did worry `-z ifunc-noplt` was proposed as it was a "fancy" feature. I asked musl guys, their feeling: "it's even worse on linux where they do this kind of hack; then happily make 10 abstraction layers; i don't get where folks get the idea to pour effort into wacky, costly microoptimizations like this when they have HUGE high-level performance problems". But they may not be aware of the FreeBSD situation.

Since you've proved this has been well-considered, I shall not block you from moving forward :)

> I tested the feature on arm64 and it works there as well.
> 
> We already implement a small "static" linker in the kernel (sys/kern/link_elf_obj.c) to handle the fact that loadable kernel modules are relocatable .o files instead of shared libs on some platforms (and the reason for this is again to avoid the PLT).

Happy to know this is not x86 only. This indeeds requires the dynamic loader support of some "static" relocation types.

In the description,

> Test Plan: I added a couple of regression tests and tested the FreeBSD kernel build using the latest lld sources.

If there are useful links, you may change this part of the commit description to include them.



================
Comment at: lld/test/ELF/gnu-ifunc-noplt-i386.s:2
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=i686-pc-linux %S/Inputs/shared2-x86-64.s -o %t1.o
+// RUN: ld.lld %t1.o --shared -o %t.so
----------------
The `-pc-linux` part in `i686-pc-linux` does not matter. You don't have to call it Linux. Something like `-triple=i686-pc-freebsd13.0` should also work. There are a few other tests using the `freebsd` triple, not many currently, but I hope there will be more in the future for other OSes or os-neutral `-triple=x86_64`.

```
% rg -l freebsd | wc -l
49
% rg -l linux | wc -l  
1346
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61613





More information about the llvm-commits mailing list