[PATCH] D120600: [X86][LLD] Fix PLT emission by LLD when -fcf-protection=branch is used

Joao Moreira via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 25 16:23:55 PST 2022


joaomoreira created this revision.
joaomoreira added reviewers: xiangzhangllvm, hjl.tools, gftg85, pengfei, aaron.ballman, erichkeane, kees, nathanchance.
joaomoreira added a project: lld.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: MaskRay.
joaomoreira requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As discussed here https://github.com/ClangBuiltLinux/linux/issues/1606 -- LLD is generates bogus PLTs on binaries that don't have a PLT when -fcf-protection=branch is used to create objects. This happens because IBTPltSection inside LLD does not have a isNeeded method implemented, and inherits the default method which always returns true. Because of that, IBTPltSection is emitted and, even though it does not have any entry, its header is visible.

This was tested only on minor toy applications. I'm posting here early to provide the fix/discussion to those in need for this patch. I'll update it with proper testing before it is merged.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120600

Files:
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h


Index: lld/ELF/SyntheticSections.h
===================================================================
--- lld/ELF/SyntheticSections.h
+++ lld/ELF/SyntheticSections.h
@@ -761,6 +761,7 @@
 public:
   IBTPltSection();
   void writeTo(uint8_t *Buf) override;
+  bool isNeeded() const override;
   size_t getSize() const override;
 };
 
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -2696,6 +2696,8 @@
   return 16 + in.plt->getNumEntries() * target->pltEntrySize;
 }
 
+bool IBTPltSection::isNeeded() const { return in.plt->getNumEntries() > 0; }
+
 // The string hash function for .gdb_index.
 static uint32_t computeGdbHash(StringRef s) {
   uint32_t h = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120600.411552.patch
Type: text/x-patch
Size: 787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220226/105ce60e/attachment.bin>


More information about the llvm-commits mailing list