[llvm] a461e2b - [RISCV] Improvements to .note.gnu.property section. (#151436)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 09:20:29 PDT 2025
Author: Craig Topper
Date: 2025-08-04T09:20:25-07:00
New Revision: a461e2b16056a0ad0e09e7866ed70edb97763b03
URL: https://github.com/llvm/llvm-project/commit/a461e2b16056a0ad0e09e7866ed70edb97763b03
DIFF: https://github.com/llvm/llvm-project/commit/a461e2b16056a0ad0e09e7866ed70edb97763b03.diff
LOG: [RISCV] Improvements to .note.gnu.property section. (#151436)
Put the emitValueToAlignment at the beginning instead of in the middle.
Emit the descsz directly instead of using the difference of 2 labels.
Remove the section alignment. emitValueToAlignment will increase the
section alignment if necessary.
Added:
Modified:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
llvm/test/CodeGen/RISCV/note-gnu-property-zicfiss.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
index 36558613d9172..f70837ea3433b 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -68,36 +68,30 @@ void RISCVTargetStreamer::emitNoteGnuPropertySection(
const Triple &Triple = Ctx.getTargetTriple();
Align NoteAlign;
+ uint64_t DescSize;
if (Triple.isArch64Bit()) {
NoteAlign = Align(8);
+ DescSize = 16;
} else {
assert(Triple.isArch32Bit());
NoteAlign = Align(4);
+ DescSize = 12;
}
assert(Ctx.getObjectFileType() == MCContext::Environment::IsELF);
MCSection *const NoteSection =
Ctx.getELFSection(".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
- NoteSection->setAlignment(NoteAlign);
OutStreamer.pushSection();
OutStreamer.switchSection(NoteSection);
// Emit the note header
- OutStreamer.emitIntValue(4, 4); // n_namsz
-
- MCSymbol *const NDescBeginSym = Ctx.createTempSymbol();
- MCSymbol *const NDescEndSym = Ctx.createTempSymbol();
- const MCExpr *const NDescSzExpr =
- MCBinaryExpr::createSub(MCSymbolRefExpr::create(NDescEndSym, Ctx),
- MCSymbolRefExpr::create(NDescBeginSym, Ctx), Ctx);
-
- OutStreamer.emitValue(NDescSzExpr, 4); // n_descsz
+ OutStreamer.emitValueToAlignment(NoteAlign);
+ OutStreamer.emitIntValue(4, 4); // n_namsz
+ OutStreamer.emitIntValue(DescSize, 4); // n_descsz
OutStreamer.emitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4); // n_type
OutStreamer.emitBytes(StringRef("GNU", 4)); // n_name
// Emit n_desc field
- OutStreamer.emitLabel(NDescBeginSym);
- OutStreamer.emitValueToAlignment(NoteAlign);
// Emit the feature_1_and property
OutStreamer.emitIntValue(ELF::GNU_PROPERTY_RISCV_FEATURE_1_AND, 4); // pr_type
@@ -105,7 +99,6 @@ void RISCVTargetStreamer::emitNoteGnuPropertySection(
OutStreamer.emitIntValue(Feature1And, 4); // pr_data
OutStreamer.emitValueToAlignment(NoteAlign); // pr_padding
- OutStreamer.emitLabel(NDescEndSym);
OutStreamer.popSection();
}
diff --git a/llvm/test/CodeGen/RISCV/note-gnu-property-zicfiss.ll b/llvm/test/CodeGen/RISCV/note-gnu-property-zicfiss.ll
index 24d63cbebc7af..efc4439a5ba17 100644
--- a/llvm/test/CodeGen/RISCV/note-gnu-property-zicfiss.ll
+++ b/llvm/test/CodeGen/RISCV/note-gnu-property-zicfiss.ll
@@ -7,19 +7,18 @@
; ASM: .section ".note.GNU-stack","", at progbits
; ASM-NEXT: .section .note.gnu.property,"a", at note
+; ASM32-NEXT: .p2align 2, 0x0
+; ASM64-NEXT: .p2align 3, 0x0
; ASM-NEXT: .word 4
-; ASM-NEXT: .word .Ltmp1-.Ltmp0
+; ASM32-NEXT: .word 12
+; ASM64-NEXT: .word 16
; ASM-NEXT: .word 5
; ASM-NEXT: .asciz "GNU"
-; ASM-NEXT: .Ltmp0:
-; ASM32-NEXT: .p2align 2, 0x0
-; ASM64-NEXT: .p2align 3, 0x0
; ASM-NEXT: .word 3221225472
; ASM-NEXT: .word 4
; ASM-NEXT: .word 2
; ASM32-NEXT: .p2align 2, 0x0
; ASM64-NEXT: .p2align 3, 0x0
-; ASM-NEXT: .Ltmp1:
define i32 @f() "hw-shadow-stack" {
entry:
More information about the llvm-commits
mailing list