[PATCH] D59120: [ELF] Sort notes by alignment in decreasing order

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 23:20:43 PDT 2019


MaskRay added a comment.

> ld.bfd outputs a separate PT_NOTE per p_align.

No, it merges adjacent `SHT_NOTE` in some circumstances. The rule is complicated, though.

We can place adjacent SHT_NOTE|SHF_ALLOC sections with the same section alignment into the same `PT_NOTE` segment, as what the ld.bfd patch does 
https://sourceware.org/git/?p=binutils-gdb.git;a=blobdiff;f=bfd/elf.c;h=8850efe20e9ea5c9f59bac839cf453790594b6af;hp=5320ae2237fcb67e39c7fd9f47a8ce81338d2aa1;hb=23e463ed7c0d289e2291aaefd576bf02efd98df8;hpb=e66cfcef729d758a5e605d57600530ad9b1bb9c3

> I'm not sure if a separate PT_NOTE section per alignment would work for all cases. I don't think the size of a note section with 8-byte alignment is guaranteed to be a multiple of 8 byte.

I believe valid `SHF_NOTE` sections are either 4-byte or 8-byte aligned and the size is guaranteed to be a multiple of its section alignment. The input is broken if it isn't. It doesn't look wrong for me if lld produces a PT_NOTE that cannot be parsed by ld.so or other tools. Such check may still be nice to have, though.

  .section .note.a, "a", @note
  .p2align 2
  .space 1
  
  .section .note.b, "a", @note
  .p2align 2
  .space 2

In this example, `.note.a`'s size is not aligned but ld.bfd places `.note.a` `.note.b` in the same `PT_NOTE` segment.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59120/new/

https://reviews.llvm.org/D59120





More information about the llvm-commits mailing list