[llvm] [RISCV] Improvements to .note.gnu.property section. (PR #151436)
Ming-Yi Lai via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 31 02:01:18 PDT 2025
================
@@ -83,29 +86,21 @@ void RISCVTargetStreamer::emitNoteGnuPropertySection(
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);
----------------
mylai-mtk wrote:
By interpreting together "Padding is present, if necessary, to ensure 8 or 4-byte alignment for the descriptor (depending on whether the file is a 64-bit or 32-bit object)." and "Padding is present, if necessary, to ensure 8 or 4-byte alignment for the next note entry (depending on whether the file is a 64-bit or 32-bit object).", it requires every `desc` (your "note", I guess) to be aligned.
And add to it the sauce of "The section alignment (in ELF, sh_addralign) is the maximum value of all alignment directives in the section.", the section will be aligned by at least 8 or 4-byte. But I feel this is more like an implication, not an explicit requirement. Consider the case where there's no `desc` elements and thus no alignment requirement is present in the section content, do we still need to align the note header? I don't know.
https://github.com/llvm/llvm-project/pull/151436
More information about the llvm-commits
mailing list