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; } 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.