Skip to content

Commit a58c62f

Browse files
authored
[X86] Do not end 'note.gnu.property' section with -fcf-protection (#79360)
The glibc now adds the required minimum ISA level for libc-nonshared.a (linked on all programs) and this is done with an inline asm along with .note.gnu.property and .pushsection/.popsection. However, the x86 backend always ends the 'note.gnu.property' section when building with -fcf-protection, leading to assert failure: llvm/llvm-project-git/llvm/lib/MC/MCStreamer.cpp:1251: virtual void llvm::MCStreamer::switchSection(llvm::MCSection*, const llvm::MCExpr*): Assertion `!Section->hasEnded() && "Section already ended"' failed. [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86/isa-level.c;h=3f1b269848a52f994275bab6f60dded3ded6b144;hb=HEAD
1 parent bee1557 commit a58c62f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,6 @@ void X86AsmPrinter::emitStartOfAsmFile(Module &M) {
877877
OutStreamer->emitInt32(FeatureFlagsAnd); // data
878878
emitAlignment(WordSize == 4 ? Align(4) : Align(8)); // padding
879879

880-
OutStreamer->endSection(Nt);
881880
OutStreamer->switchSection(Cur);
882881
}
883882
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llc -mtriple x86_64-unknown-linux-gnu %s -o %t.o -filetype=obj
2+
; RUN: llvm-readobj -n %t.o | FileCheck %s
3+
4+
module asm ".pushsection \22.note.gnu.property\22,\22a\22,@note"
5+
module asm " .p2align 3"
6+
module asm " .long 1f - 0f"
7+
module asm " .long 4f - 1f"
8+
module asm " .long 5"
9+
module asm "0: .asciz \22GNU\22"
10+
module asm "1: .p2align 3"
11+
module asm " .long 0xc0008002"
12+
module asm " .long 3f - 2f"
13+
module asm "2: .long ((1U << 0) | 0 | 0 | 0)"
14+
module asm "3: .p2align 3"
15+
module asm "4:"
16+
module asm " .popsection"
17+
18+
!llvm.module.flags = !{!0, !1}
19+
20+
!0 = !{i32 4, !"cf-protection-return", i32 1}
21+
!1 = !{i32 4, !"cf-protection-branch", i32 1}
22+
23+
; CHECK: Type: NT_GNU_PROPERTY_TYPE_0
24+
; CHECK-NEXT: Property [
25+
; CHECK-NEXT: x86 feature: IBT, SHSTK
26+
; CHECK-NEXT: ]
27+
; CHECK: Type: NT_GNU_PROPERTY_TYPE_0
28+
; CHECK-NEXT: Property [
29+
; CHECK-NEXT: x86 ISA needed: x86-64-baseline
30+
; CHECK-NEXT: ]

0 commit comments

Comments
 (0)