Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -862,6 +862,16 @@ return cast_or_null(Parent); } +// Helper is used for hashing short data, like mergeable strings. +static uint64_t hashString(const char *Data, size_t Size) { + // Optimize for 1 byte strings case. For example, scylla has + // about 15k of one byte zeroes. + if (Size == 1) + return *Data; + // Use fixed seed value. + return hashing::detail::hash_short(Data, Size, 0xff51afd7ed558ccdULL); +} + // Split SHF_STRINGS section. Such section is a sequence of // null-terminated strings. void MergeInputSection::splitStrings(ArrayRef Data, size_t EntSize) { @@ -875,7 +885,7 @@ fatal(toString(this) + ": string is not null terminated"); size_t Size = End + EntSize; - Pieces.emplace_back(Off, xxHash64(S.substr(0, Size)), !IsAlloc); + Pieces.emplace_back(Off, hashString(S.data(), Size), !IsAlloc); S = S.substr(Size); Off += Size; } Index: test/ELF/comment-gc.s =================================================================== --- test/ELF/comment-gc.s +++ test/ELF/comment-gc.s @@ -5,7 +5,7 @@ # RUN: llvm-objdump -s %t1 | FileCheck %s # CHECK: Contents of section .comment: -# CHECK-NEXT: foo..LLD 1.0.bar +# CHECK-NEXT: .foo.LLD 1.0.bar .ident "foo" Index: test/ELF/debug-gc.s =================================================================== --- test/ELF/debug-gc.s +++ test/ELF/debug-gc.s @@ -4,11 +4,11 @@ # RUN: llvm-objdump -s %t1 | FileCheck %s # CHECK: Contents of section .debug_str: -# CHECK-NEXT: 0000 41414100 43434300 42424200 AAA.CCC.BBB. +# CHECK-NEXT: 0000 41414100 42424200 43434300 AAA.BBB.CCC. # CHECK: Contents of section .foo: # CHECK-NEXT: 0000 2a000000 # CHECK: Contents of section .debug_info: -# CHECK-NEXT: 0000 00000000 08000000 +# CHECK-NEXT: 0000 00000000 04000000 .globl _start _start: Index: test/ELF/emit-relocs-mergeable-i386.s =================================================================== --- test/ELF/emit-relocs-mergeable-i386.s +++ test/ELF/emit-relocs-mergeable-i386.s @@ -5,7 +5,7 @@ ## Check lf we produce proper relocations when doing merging of SHF_MERGE sections. -## Check addends of relocations are: 0x0, 0x8, 0x8, 0x4 +## Check addends of relocations are: 0x0, 0x4, 0x4, 0x8 # CHECK: Section { # CHECK: Index: # CHECK: Name: .foo @@ -22,11 +22,11 @@ # CHECK-NEXT: AddressAlignment: # CHECK-NEXT: EntrySize: # CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 00000000 08000000 08000000 04000000 +# CHECK-NEXT: 0000: 00000000 04000000 04000000 08000000 # CHECK-NEXT: ) # CHECK-NEXT: } -## Check that offsets for AAA is 0x0, for BBB is 0x8 and CCC has offset 0x4. +## Check that offsets for AAA is 0x0, for BBB is 0x4 and CCC has offset 0x8. # CHECK: Section { # CHECK: Index: # CHECK: Name: .strings @@ -43,7 +43,7 @@ # CHECK-NEXT: AddressAlignment: # CHECK-NEXT: EntrySize: # CHECK-NEXT: SectionData ( -# CHECK-NEXT: |AAA.CCC.BBB.| +# CHECK-NEXT: |AAA.BBB.CCC.| # CHECK-NEXT: ) # CHECK-NEXT: } Index: test/ELF/emit-relocs-mergeable.s =================================================================== --- test/ELF/emit-relocs-mergeable.s +++ test/ELF/emit-relocs-mergeable.s @@ -21,16 +21,16 @@ # CHECK-NEXT: AddressAlignment: # CHECK-NEXT: EntrySize: # CHECK-NEXT: SectionData ( -# CHECK-NEXT: 0000: 41414100 43434300 42424200 |AAA.CCC.BBB.| +# CHECK-NEXT: 0000: 41414100 42424200 43434300 |AAA.BBB.CCC.| # CHECK-NEXT: ) # CHECK-NEXT: } # CHECK: Relocations [ # CHECK-NEXT: Section {{.*}} .rela.foo { # CHECK-NEXT: 0x201000 R_X86_64_64 .strings 0x0 -# CHECK-NEXT: 0x201008 R_X86_64_64 .strings 0x8 -# CHECK-NEXT: 0x201010 R_X86_64_64 .strings 0x8 -# CHECK-NEXT: 0x201018 R_X86_64_64 .strings 0x4 +# CHECK-NEXT: 0x201008 R_X86_64_64 .strings 0x4 +# CHECK-NEXT: 0x201010 R_X86_64_64 .strings 0x4 +# CHECK-NEXT: 0x201018 R_X86_64_64 .strings 0x8 # CHECK-NEXT: } # CHECK-NEXT: ]