[lld] c78c00d - [LLD][ELF] Drop the string null terminator from the hash in splitStrings

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 02:54:48 PDT 2022


Author: Andrew Ng
Date: 2022-05-27T10:48:53+01:00
New Revision: c78c00dc16bbbb3b48705190f7e6de09458a1f34

URL: https://github.com/llvm/llvm-project/commit/c78c00dc16bbbb3b48705190f7e6de09458a1f34
DIFF: https://github.com/llvm/llvm-project/commit/c78c00dc16bbbb3b48705190f7e6de09458a1f34.diff

LOG: [LLD][ELF] Drop the string null terminator from the hash in splitStrings

Differential Revision: https://reviews.llvm.org/D126484

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/test/ELF/comment-gc.s
    lld/test/ELF/merge-string.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 02d1080cae2cd..056119924a829 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -1376,15 +1376,15 @@ void MergeInputSection::splitStrings(StringRef s, size_t entSize) {
   if (entSize == 1) {
     // Optimize the common case.
     do {
-      size_t size = strlen(p) + 1;
+      size_t size = strlen(p);
       pieces.emplace_back(p - s.begin(), xxHash64(StringRef(p, size)), live);
-      p += size;
+      p += size + 1;
     } while (p != end);
   } else {
     do {
-      size_t size = findNull(StringRef(p, end - p), entSize) + entSize;
+      size_t size = findNull(StringRef(p, end - p), entSize);
       pieces.emplace_back(p - s.begin(), xxHash64(StringRef(p, size)), live);
-      p += size;
+      p += size + entSize;
     } while (p != end);
   }
 }

diff  --git a/lld/test/ELF/comment-gc.s b/lld/test/ELF/comment-gc.s
index 44c08fe9cef9a..077bdb9021a6d 100644
--- a/lld/test/ELF/comment-gc.s
+++ b/lld/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: .LLD 1.0.foo.bar
 
 .ident "foo"
 

diff  --git a/lld/test/ELF/merge-string.s b/lld/test/ELF/merge-string.s
index 0922cd8f135e7..549195d5cf805 100644
--- a/lld/test/ELF/merge-string.s
+++ b/lld/test/ELF/merge-string.s
@@ -54,7 +54,7 @@ zed:
 // NOTAIL-NEXT: AddressAlignment: 1
 // NOTAIL-NEXT: EntrySize: 1
 // NOTAIL-NEXT: SectionData (
-// NOTAIL-NEXT:   0000: 62630061 626300                     |bc.abc.|
+// NOTAIL-NEXT:   0000: 61626300 626300                     |abc.bc.|
 // NOTAIL-NEXT: )
 
 // NOMERGE:      Name:    .rodata1


        


More information about the llvm-commits mailing list