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

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 17:08:20 PST 2019


phosek created this revision.
phosek added reviewers: ruiu, jakehehrlich.
Herald added subscribers: llvm-commits, MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

This change implements the solution to PR41000 proposed in the bug
by sorting notes by alignment in decreasing order to close the gap
that might occur when notes use different alignments and to ensure
that PT_NOTE is packed correctly.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D59120

Files:
  lld/ELF/Writer.cpp
  lld/test/ELF/build-id.s


Index: lld/test/ELF/build-id.s
===================================================================
--- lld/test/ELF/build-id.s
+++ lld/test/ELF/build-id.s
@@ -61,19 +61,30 @@
 # ALIGN-NEXT: Link:
 # ALIGN-NEXT: Info:
 # ALIGN-NEXT: AddressAlignment: 4
+# ALIGN:      Name: .note.test
+# ALIGN-NEXT: Type: SHT_NOTE
+# ALIGN-NEXT: Flags [
+# ALIGN-NEXT:   SHF_ALLOC
+# ALIGN-NEXT: ]
+# ALIGN-NEXT: Address:
+# ALIGN-NEXT: Offset:
+# ALIGN-NEXT: Size:
+# ALIGN-NEXT: Link:
+# ALIGN-NEXT: Info:
+# ALIGN-NEXT: AddressAlignment: 1
 
-# DEFAULT:      Contents of section .note.test:
 # DEFAULT:      Contents of section .note.gnu.build-id:
 # DEFAULT-NEXT: 04000000 08000000 03000000 474e5500  ............GNU.
-# DEFAULT-NEXT: 894c04e8 fbf5556b
+# DEFAULT-NEXT: a8559a18 b5591183
+# DEFAULT:      Contents of section .note.test:
 
 # MD5:      Contents of section .note.gnu.build-id:
 # MD5-NEXT: 04000000 10000000 03000000 474e5500  ............GNU.
-# MD5-NEXT: 6a51bbd7 9e8ee3f9 2e02d213 711cfec9
+# MD5-NEXT: aba082ff 066f94ce 66e40824 df7a3f60
 
 # SHA1:      Contents of section .note.gnu.build-id:
 # SHA1-NEXT: 04000000 14000000 03000000 474e5500  ............GNU.
-# SHA1-NEXT: 9a8618b1 d6fd0e5c eda73dd8 76de5596
+# SHA1-NEXT: c47692ed 095f88fc f9a08777 aa1bc6de
 
 # UUID:      Contents of section .note.gnu.build-id:
 # UUID-NEXT: 04000000 10000000 03000000 474e5500  ............GNU.
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -885,6 +885,10 @@
   if (!(A->SortRank & RF_NOT_ADDR_SET))
     return Config->SectionStartMap.lookup(A->Name) <
            Config->SectionStartMap.lookup(B->Name);
+
+  if (A->Type == SHT_NOTE && B->Type == SHT_NOTE)
+    return A->Alignment > B->Alignment;
+
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59120.189802.patch
Type: text/x-patch
Size: 1819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190308/60c71a2e/attachment.bin>


More information about the llvm-commits mailing list