[PATCH] D59780: Support Intel Control-flow Enforcement Technology

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 1 00:36:47 PDT 2019


MaskRay added a comment.

`writePltHeader` should also be changed.

  diff --git i/ELF/Arch/X86_64.cpp w/ELF/Arch/X86_64.cpp
  index 668b40863..75f780f6b 100644
  --- i/ELF/Arch/X86_64.cpp
  +++ w/ELF/Arch/X86_64.cpp
  @@ -144,7 +144,7 @@ void X86_64::writePltHeader(uint8_t *Buf) const {
     };
     memcpy(Buf, PltData, sizeof(PltData));
     uint64_t GotPlt = In.GotPlt->getVA();
  -  uint64_t Plt = In.Plt->getVA();
  +  uint64_t Plt = In.IBTPlt ? In.IBTPlt->getVA() : In.Plt->getVA();
     write32le(Buf + 2, GotPlt - Plt + 2); // GOTPLT+8
     write32le(Buf + 8, GotPlt - Plt + 4); // GOTPLT+16
   }

With these changes, I manage to run hello-world with `clang {,-m32} -fuse-ld=lld -fcf-protection=branch a.c -Wl,--require-cet -o a; ./a`



================
Comment at: lld/ELF/Arch/X86_64.cpp:575
+    memcpy(Buf, Inst, sizeof(Inst));
+    write32le(Buf + 5, I * sizeof(object::ELF64LE::Rela));
+    write32le(Buf + 10, -PltHeaderSize - sizeof(Inst) * I - 30);
----------------
`write32le(Buf + 5, I);`

For glibc lazy binding, x86_64 uses relocation indices while x86_32 uses offsets.


================
Comment at: lld/ELF/Writer.cpp:429
 
+  if (Config->X86Features & GNU_PROPERTY_X86_FEATURE_1_IBT) {
+    In.IBTPlt = make<IBTPltSection>();
----------------
Since `In.IBTPlt` is named `.plt` while `In.Plt` is named `.plt.sec`.
Creating `In.IBTPlt` before `In.Plt` will give us this ordering: `.plt` `.plt.sec` (instead of `.plt.sec` `.plt`), which may look more natural.

No strong preference here. Up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59780





More information about the llvm-commits mailing list