[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.

llvm-svn: 211682
This commit is contained in:
Tim Northover 2014-06-25 11:21:51 +00:00
parent 36bd9ab2c5
commit f48f0620ed
2 changed files with 9 additions and 9 deletions

View File

@ -352,9 +352,9 @@ std::error_code processSection(DefinedAtom::ContentType atomType,
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(DefinedAtom::ContentType atomType,
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;
}
}

View File

@ -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 ]