[PATCH] D120600: [ELF][X86] Don't create IBT .plt if there is no PLT entry
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 25 19:41:04 PST 2022
MaskRay updated this revision to Diff 411566.
MaskRay retitled this revision from "[X86][LLD] Fix PLT emission by LLD when -fcf-protection=branch is used" to "[ELF][X86] Don't create IBT .plt if there is no PLT entry".
MaskRay edited the summary of this revision.
MaskRay added a comment.
Fix description and add tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120600/new/
https://reviews.llvm.org/D120600
Files:
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/test/ELF/x86-64-feature-cet.s
Index: lld/test/ELF/x86-64-feature-cet.s
===================================================================
--- lld/test/ELF/x86-64-feature-cet.s
+++ lld/test/ELF/x86-64-feature-cet.s
@@ -91,6 +91,17 @@
# DISASM-NEXT: jmpq *0x2126(%rip)
# DISASM-NEXT: nopw (%rax,%rax)
+## If there is no PLT entry, don't create .plt section.
+# RUN: ld.lld -e 0 %t1.o -o %t.noplt
+# RUN: llvm-readelf -S %t.noplt | FileCheck %s --check-prefix=NOPLT
+# RUN: ld.lld -r %t1.o -o %t.noplt
+# RUN: llvm-readelf -S %t.noplt | FileCheck %s --check-prefix=NOPLT
+
+# NOPLT: [Nr] Name
+# NOPLT-NOT: .plt
+# NOPLT: .note.gnu.property
+# NOPLT-NOT: .plt
+
.section ".note.gnu.property", "a"
.long 4
.long 0x10
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.411566.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220226/25cbb8c1/attachment.bin>
More information about the llvm-commits
mailing list