[lld] r209684 - [mach-o] Add support for reading utf16 string literal sections
Nick Kledzik
kledzik at apple.com
Tue May 27 13:25:06 PDT 2014
Author: kledzik
Date: Tue May 27 15:25:06 2014
New Revision: 209684
URL: http://llvm.org/viewvc/llvm-project?rev=209684&view=rev
Log:
[mach-o] Add support for reading utf16 string literal sections
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
lld/trunk/test/mach-o/parse-literals.yaml
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=209684&r1=209683&r2=209684&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Tue May 27 15:25:06 2014
@@ -188,6 +188,9 @@ SectionInfo *Util::makeSection(DefinedAt
case DefinedAtom::typeLiteral16:
return new (_allocator) SectionInfo("__TEXT", "__literal16",
S_16BYTE_LITERALS);
+ case DefinedAtom::typeUTF16String:
+ return new (_allocator) SectionInfo("__TEXT", "__ustring",
+ S_REGULAR);
default:
llvm_unreachable("TO DO: add support for more sections");
break;
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=209684&r1=209683&r2=209684&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Tue May 27 15:25:06 2014
@@ -113,6 +113,23 @@ static error_code processSection(MachOFi
unsigned offset = 0;
switch (section.type) {
case llvm::MachO::S_REGULAR:
+ if (section.segmentName.equals("__TEXT") &&
+ section.sectionName.equals("__ustring")) {
+ if ((section.content.size() % 4) != 0)
+ return make_dynamic_error_code(Twine("Section ") + section.segmentName
+ + "/" + section.sectionName
+ + " has a size that is not even");
+ for (size_t i = 0, e = section.content.size(); i != e; i +=2) {
+ if ((section.content[i] == 0) && (section.content[i+1] == 0)) {
+ unsigned size = i - offset + 2;
+ ArrayRef<uint8_t> utf16Content = section.content.slice(offset, size);
+ file.addDefinedAtom(StringRef(), DefinedAtom::scopeLinkageUnit,
+ DefinedAtom::typeUTF16String, utf16Content,
+ copyRefs);
+ offset = i + 2;
+ }
+ }
+ }
case llvm::MachO::S_COALESCED:
case llvm::MachO::S_ZEROFILL:
// These sections are broken in to atoms based on symbols.
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=209684&r1=209683&r2=209684&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-literals.yaml (original)
+++ lld/trunk/test/mach-o/parse-literals.yaml Tue May 27 15:25:06 2014
@@ -43,6 +43,15 @@ sections:
address: 0x0000000000000130
content: [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00 ]
+ - segment: __TEXT
+ section: __ustring
+ type: S_REGULAR
+ attributes: [ ]
+ alignment: 0
+ 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 ]
...
@@ -57,6 +66,12 @@ sections:
# CHECK: type: c-string
# CHECK: content: [ 77, 6F, 72, 6C, 64, 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: - scope: hidden
# CHECK: type: const-4-byte
# CHECK: content: [ 01, 02, 03, 04 ]
# CHECK: - scope: hidden
More information about the llvm-commits
mailing list