Skip to content

Commit f8ca5fa

Browse files
Joao MoreiraMaskRay
authored andcommitted
[ELF][X86] Don't create IBT .plt if there is no PLT entry
ClangBuiltLinux/linux#1606 When GNU_PROPERTY_X86_FEATURE_1_IBT is enabled, ld.lld will create .plt output section even if there is no PLT entry. Fix this by implementing IBTPltSection::isNeeded instead of using the default code path (which always returns true). Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D120600 (cherry picked from commit 9d7001e)
1 parent 8400036 commit f8ca5fa

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,8 @@ size_t IBTPltSection::getSize() const {
26992699
return 16 + in.plt->getNumEntries() * target->pltEntrySize;
27002700
}
27012701

2702+
bool IBTPltSection::isNeeded() const { return in.plt->getNumEntries() > 0; }
2703+
27022704
// The string hash function for .gdb_index.
27032705
static uint32_t computeGdbHash(StringRef s) {
27042706
uint32_t h = 0;

lld/ELF/SyntheticSections.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ class IBTPltSection : public SyntheticSection {
762762
public:
763763
IBTPltSection();
764764
void writeTo(uint8_t *Buf) override;
765+
bool isNeeded() const override;
765766
size_t getSize() const override;
766767
};
767768

lld/test/ELF/format-binary.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
# EXE: Machine: Advanced Micro Devices X86-64
3333
# EXE: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
34-
# EXE: [ 3] .data PROGBITS {{.*}} 00000c 00 WA 0 0 8
34+
# EXE: [ 2] .data PROGBITS {{.*}} 00000c 00 WA 0 0 8
3535
# EXE: Size Type Bind Vis Ndx Name
36-
# EXE: 0 OBJECT GLOBAL DEFAULT 3 _binary_d_t_txt_start
37-
# EXE-NEXT: 0 OBJECT GLOBAL DEFAULT 3 _binary_d_t_txt_end
36+
# EXE: 0 OBJECT GLOBAL DEFAULT 2 _binary_d_t_txt_start
37+
# EXE-NEXT: 0 OBJECT GLOBAL DEFAULT 2 _binary_d_t_txt_end
3838
# EXE-NEXT: 0 OBJECT GLOBAL DEFAULT ABS _binary_d_t_txt_size
3939

4040
# RUN: not ld.lld -b foo 2>&1 | FileCheck --check-prefix=ERR %s

lld/test/ELF/x86-64-feature-cet.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@
9191
# DISASM-NEXT: jmpq *0x2126(%rip)
9292
# DISASM-NEXT: nopw (%rax,%rax)
9393

94+
## If there is no PLT entry, don't create .plt section.
95+
# RUN: ld.lld -e 0 %t1.o -o %t.noplt
96+
# RUN: llvm-readelf -S %t.noplt | FileCheck %s --check-prefix=NOPLT
97+
# RUN: ld.lld -r %t1.o -o %t.noplt
98+
# RUN: llvm-readelf -S %t.noplt | FileCheck %s --check-prefix=NOPLT
99+
100+
# NOPLT: [Nr] Name
101+
# NOPLT-NOT: .plt
102+
# NOPLT: .note.gnu.property
103+
# NOPLT-NOT: .plt
104+
94105
.section ".note.gnu.property", "a"
95106
.long 4
96107
.long 0x10

0 commit comments

Comments
 (0)