[PATCH] D59531: [ELF] Produce multiple PT_NOTE segments as needed

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 03:03:48 PDT 2019


peter.smith added a comment.

In D59531#1435577 <https://reviews.llvm.org/D59531#1435577>, @jakehehrlich wrote:

> > We don't know addresses at this point, and indeed we can't because the layout of the rest of the output file depends on how many program headers there are, which is decided by this function.
>
> Yep I think the only correct solution then is to use one PT_NOTE per note section then. That's kind of a shame but I think all other behaviors have a counter example (academic or otherwise). We can't relay on vaddrs and there aren't any assumptions we can make about what the relative properties between the final vaddrs will be either because of linker scripts. One per is the only solution resistant to academic counter examples (that I personally think we should take seriously).


If I've understood the latest patch right then pcc's original test case will still fail if both notes sections in the example below are 4-byte aligned.

  SECTIONS {
    . = SIZEOF_HEADERS;
    .note1 : { *(.note1) }
    . = 0x10000;
    .note2 : { *(.note2) }
  }

If this is still the intention to support this case then it would be good to add a test case.



================
Comment at: lld/ELF/Writer.cpp:2047
 
-  // Create one PT_NOTE per a group of contiguous .note sections.
-  PhdrEntry *Note = nullptr;
-  for (OutputSection *Sec : OutputSections) {
-    if (Sec->Type == SHT_NOTE && (Sec->Flags & SHF_ALLOC)) {
-      if (!Note || Sec->LMAExpr)
-        Note = AddHdr(PT_NOTE, PF_R);
-      Note->add(Sec);
-    } else {
-      Note = nullptr;
+  bool UseSimpleNoteLayout = false;
+  for (OutputSection *Sec : OutputSections)
----------------
Would OneProgramHeaderPerNoteSection , or MultiNoteSegmentLayout be more descriptive? Which one is more simple is a bit subjective, and means having to read the comment or code to work out what it means in practice.


================
Comment at: lld/ELF/Writer.cpp:2049
+  for (OutputSection *Sec : OutputSections)
+    if (Sec->Alignment > 4)
+      UseSimpleNoteLayout = true;
----------------
This is setting UseSimpleNoteLayout if any OutputSection has an alignment > 4. Was that what you intended? I was expecting only SHT_NOTE sections with an alignment > 4.


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

https://reviews.llvm.org/D59531





More information about the llvm-commits mailing list