[lld] r211682 - [mach-o]: atomize zero-terminated literals correctly.
Tim Northover
tnorthover at apple.com
Wed Jun 25 04:21:51 PDT 2014
Author: tnorthover
Date: Wed Jun 25 06:21:51 2014
New Revision: 211682
URL: http://llvm.org/viewvc/llvm-project?rev=211682&view=rev
Log:
[mach-o]: atomize zero-terminated literals correctly.
When looking through sections with zero-terminated string-literals (__cstring
or __ustring) we were constantly rechecking the first few bytes of the string
for '\0' rather than advancing along. This obviously failed unless all strings
within the section had the same length as that first one.
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
lld/trunk/test/mach-o/parse-literals.yaml
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=211682&r1=211681&r2=211682&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Wed Jun 25 06:21:51 2014
@@ -352,9 +352,9 @@ std::error_code processSection(DefinedAt
case atomizeUTF8:
// Break section up into zero terminated c-strings.
size = 0;
- for (unsigned int i=0; offset+i < e; ++i) {
+ for (unsigned int i = offset; i < e; ++i) {
if (section.content[i] == 0) {
- size = i+1;
+ size = i + 1 - offset;
break;
}
}
@@ -362,9 +362,9 @@ std::error_code processSection(DefinedAt
case atomizeUTF16:
// Break section up into zero terminated UTF16 strings.
size = 0;
- for (unsigned int i=0; offset+i < e; i += 2) {
- if ((section.content[i] == 0) && (section.content[i+1] == 0)) {
- size = i+2;
+ for (unsigned int i = offset; i < e; i += 2) {
+ if ((section.content[i] == 0) && (section.content[i + 1] == 0)) {
+ size = i + 2 - offset;
break;
}
}
Modified: lld/trunk/test/mach-o/parse-literals.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-literals.yaml?rev=211682&r1=211681&r2=211682&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-literals.yaml (original)
+++ lld/trunk/test/mach-o/parse-literals.yaml Wed Jun 25 06:21:51 2014
@@ -18,7 +18,7 @@ sections:
address: 0x0000000000000100
content: [ 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x74, 0x68,
0x65, 0x72, 0x65, 0x00, 0x77, 0x6F, 0x72, 0x6C,
- 0x64, 0x00 ]
+ 0x00 ]
- segment: __TEXT
section: __literal4
type: S_4BYTE_LITERALS
@@ -51,7 +51,7 @@ sections:
address: 0x0000000000000100
content: [ 0x68, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00,
0x6F, 0x00, 0x00, 0x00, 0x74, 0x00, 0x68, 0x00,
- 0x65, 0x00, 0x72, 0x00, 0x65, 0x00, 0x00, 0x00 ]
+ 0x65, 0x00, 0x72, 0x00, 0x00, 0x00 ]
...
@@ -64,13 +64,13 @@ sections:
# CHECK: content: [ 74, 68, 65, 72, 65, 00 ]
# CHECK: - scope: hidden
# CHECK: type: c-string
-# CHECK: content: [ 77, 6F, 72, 6C, 64, 00 ]
+# CHECK: content: [ 77, 6F, 72, 6C, 00 ]
# CHECK: - scope: hidden
# CHECK: type: utf16-string
# CHECK: content: [ 68, 00, 65, 00, 6C, 00, 6C, 00, 6F, 00, 00, 00 ]
# CHECK: - scope: hidden
# CHECK: type: utf16-string
-# CHECK: content: [ 74, 00, 68, 00, 65, 00, 72, 00, 65, 00, 00, 00 ]
+# CHECK: content: [ 74, 00, 68, 00, 65, 00, 72, 00, 00, 00 ]
# CHECK: - scope: hidden
# CHECK: type: const-4-byte
# CHECK: content: [ 01, 02, 03, 04 ]
More information about the llvm-commits
mailing list