<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Should be fixed with r271334.<div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 31, 2016, at 2:04 PM, Chris Bieneman via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">My bad. Committing shortly.<div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 31, 2016, at 1:27 PM, Reid Kleckner <<a href="mailto:rnk@google.com" class="">rnk@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">MSan doesn't like your change:<div class=""><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/13302/steps/check-llvm%20msan/logs/stdio" class="">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/13302/steps/check-llvm%20msan/logs/stdio</a><br class=""></div><div class=""><br class=""></div><div class="">Try adding a default member initializer for these fields:</div><div class=""><span style="font-size:12.8px" class="">+struct ExportEntry {</span><br style="font-size:12.8px" class=""><span style="font-size:12.8px" class="">+ uint64_t TerminalSize;</span><br style="font-size:12.8px" class=""><span style="font-size:12.8px" class="">+ uint64_t NodeOffset;</span><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, May 31, 2016 at 10:26 AM, Chris Bieneman via llvm-commits <span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: cbieneman<br class="">
Date: Tue May 31 12:26:36 2016<br class="">
New Revision: 271300<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=271300&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=271300&view=rev</a><br class="">
Log:<br class="">
[obj2yaml][yaml2obj] Support for reading and dumping the MachO export trie<br class="">
<br class="">
The MachO export trie is a serially encoded trie keyed by symbol name. This code parses the trie and preserves the structure so that it can be dumped again.<br class="">
<br class="">
Added:<br class="">
llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml<br class="">
Modified:<br class="">
llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h<br class="">
llvm/trunk/lib/ObjectYAML/MachOYAML.cpp<br class="">
llvm/trunk/tools/obj2yaml/macho2yaml.cpp<br class="">
llvm/trunk/tools/yaml2obj/yaml2macho.cpp<br class="">
<br class="">
Modified: llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h?rev=271300&r1=271299&r2=271300&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h?rev=271300&r1=271299&r2=271300&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h (original)<br class="">
+++ llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h Tue May 31 12:26:36 2016<br class="">
@@ -71,11 +71,23 @@ struct BindOpcode {<br class="">
StringRef Symbol;<br class="">
};<br class="">
<br class="">
+struct ExportEntry {<br class="">
+ uint64_t TerminalSize;<br class="">
+ uint64_t NodeOffset;<br class="">
+ std::string Name;<br class="">
+ llvm::yaml::Hex64 Flags;<br class="">
+ llvm::yaml::Hex64 Address;<br class="">
+ llvm::yaml::Hex64 Other;<br class="">
+ std::string ImportName;<br class="">
+ std::vector<MachOYAML::ExportEntry> Children;<br class="">
+};<br class="">
+<br class="">
struct LinkEditData {<br class="">
std::vector<MachOYAML::RebaseOpcode> RebaseOpcodes;<br class="">
std::vector<MachOYAML::BindOpcode> BindOpcodes;<br class="">
std::vector<MachOYAML::BindOpcode> WeakBindOpcodes;<br class="">
std::vector<MachOYAML::BindOpcode> LazyBindOpcodes;<br class="">
+ MachOYAML::ExportEntry ExportTrie;<br class="">
};<br class="">
<br class="">
struct Object {<br class="">
@@ -95,6 +107,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml:<br class="">
LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)<br class="">
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)<br class="">
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)<br class="">
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::ExportEntry)<br class="">
<br class="">
namespace llvm {<br class="">
namespace yaml {<br class="">
@@ -123,6 +136,10 @@ template <> struct MappingTraits<MachOYA<br class="">
static void mapping(IO &IO, MachOYAML::BindOpcode &BindOpcode);<br class="">
};<br class="">
<br class="">
+template <> struct MappingTraits<MachOYAML::ExportEntry> {<br class="">
+ static void mapping(IO &IO, MachOYAML::ExportEntry &ExportEntry);<br class="">
+};<br class="">
+<br class="">
template <> struct MappingTraits<MachOYAML::Section> {<br class="">
static void mapping(IO &IO, MachOYAML::Section &Section);<br class="">
};<br class="">
<br class="">
Modified: llvm/trunk/lib/ObjectYAML/MachOYAML.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MachOYAML.cpp?rev=271300&r1=271299&r2=271300&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MachOYAML.cpp?rev=271300&r1=271299&r2=271300&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/ObjectYAML/MachOYAML.cpp (original)<br class="">
+++ llvm/trunk/lib/ObjectYAML/MachOYAML.cpp Tue May 31 12:26:36 2016<br class="">
@@ -103,6 +103,7 @@ void MappingTraits<MachOYAML::LinkEditDa<br class="">
IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);<br class="">
IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);<br class="">
IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);<br class="">
+ IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);<br class="">
}<br class="">
<br class="">
void MappingTraits<MachOYAML::RebaseOpcode>::mapping(<br class="">
@@ -121,6 +122,18 @@ void MappingTraits<MachOYAML::BindOpcode<br class="">
IO.mapOptional("Symbol", BindOpcode.Symbol);<br class="">
}<br class="">
<br class="">
+void MappingTraits<MachOYAML::ExportEntry>::mapping(<br class="">
+ IO &IO, MachOYAML::ExportEntry &ExportEntry) {<br class="">
+ IO.mapRequired("TerminalSize", ExportEntry.TerminalSize);<br class="">
+ IO.mapOptional("NodeOffset", ExportEntry.NodeOffset);<br class="">
+ IO.mapOptional("Name", ExportEntry.Name);<br class="">
+ IO.mapOptional("Flags", ExportEntry.Flags);<br class="">
+ IO.mapOptional("Address", ExportEntry.Address);<br class="">
+ IO.mapOptional("Other", ExportEntry.Other);<br class="">
+ IO.mapOptional("ImportName", ExportEntry.ImportName);<br class="">
+ IO.mapOptional("Children", ExportEntry.Children);<br class="">
+}<br class="">
+<br class="">
template <typename StructType><br class="">
void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}<br class="">
<br class="">
@@ -141,6 +154,12 @@ void mapLoadCommandData<MachO::dylib_com<br class="">
IO &IO, MachOYAML::LoadCommand &LoadCommand) {<br class="">
IO.mapOptional("PayloadString", LoadCommand.PayloadString);<br class="">
}<br class="">
+<br class="">
+template <><br class="">
+void mapLoadCommandData<MachO::rpath_command>(<br class="">
+ IO &IO, MachOYAML::LoadCommand &LoadCommand) {<br class="">
+ IO.mapOptional("PayloadString", LoadCommand.PayloadString);<br class="">
+}<br class="">
<br class="">
template <><br class="">
void mapLoadCommandData<MachO::dylinker_command>(<br class="">
<br class="">
Added: llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml?rev=271300&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml?rev=271300&view=auto</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml (added)<br class="">
+++ llvm/trunk/test/ObjectYAML/MachO/export_trie.yaml Tue May 31 12:26:36 2016<br class="">
@@ -0,0 +1,191 @@<br class="">
+# RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s<br class="">
+<br class="">
+--- !mach-o<br class="">
+FileHeader:<br class="">
+ magic: 0xFEEDFACF<br class="">
+ cputype: 0x01000007<br class="">
+ cpusubtype: 0x80000003<br class="">
+ filetype: 0x00000002<br class="">
+ ncmds: 16<br class="">
+ sizeofcmds: 1408<br class="">
+ flags: 0x00218085<br class="">
+ reserved: 0x00000000<br class="">
+LoadCommands:<br class="">
+ - cmd: LC_SEGMENT_64<br class="">
+ cmdsize: 72<br class="">
+ segname: __PAGEZERO<br class="">
+ vmaddr: 0<br class="">
+ vmsize: 4294967296<br class="">
+ fileoff: 0<br class="">
+ filesize: 0<br class="">
+ maxprot: 0<br class="">
+ initprot: 0<br class="">
+ nsects: 0<br class="">
+ flags: 0<br class="">
+ - cmd: LC_SEGMENT_64<br class="">
+ cmdsize: 552<br class="">
+ segname: __TEXT<br class="">
+ vmaddr: 4294967296<br class="">
+ vmsize: 8192<br class="">
+ fileoff: 0<br class="">
+ filesize: 8192<br class="">
+ maxprot: 7<br class="">
+ initprot: 5<br class="">
+ nsects: 6<br class="">
+ flags: 0<br class="">
+ - cmd: LC_SEGMENT_64<br class="">
+ cmdsize: 312<br class="">
+ segname: __DATA<br class="">
+ vmaddr: 4294975488<br class="">
+ vmsize: 4096<br class="">
+ fileoff: 8192<br class="">
+ filesize: 4096<br class="">
+ maxprot: 7<br class="">
+ initprot: 3<br class="">
+ nsects: 3<br class="">
+ flags: 0<br class="">
+ - cmd: LC_SEGMENT_64<br class="">
+ cmdsize: 72<br class="">
+ segname: __LINKEDIT<br class="">
+ vmaddr: 4294979584<br class="">
+ vmsize: 4096<br class="">
+ fileoff: 12288<br class="">
+ filesize: 2508<br class="">
+ maxprot: 7<br class="">
+ initprot: 1<br class="">
+ nsects: 0<br class="">
+ flags: 0<br class="">
+ - cmd: LC_DYLD_INFO_ONLY<br class="">
+ cmdsize: 48<br class="">
+ rebase_off: 12288<br class="">
+ rebase_size: 8<br class="">
+ bind_off: 12296<br class="">
+ bind_size: 96<br class="">
+ weak_bind_off: 0<br class="">
+ weak_bind_size: 0<br class="">
+ lazy_bind_off: 12392<br class="">
+ lazy_bind_size: 624<br class="">
+ export_off: 13016<br class="">
+ export_size: 48<br class="">
+ - cmd: LC_SYMTAB<br class="">
+ cmdsize: 24<br class="">
+ symoff: 13080<br class="">
+ nsyms: 30<br class="">
+ stroff: 13700<br class="">
+ strsize: 1096<br class="">
+ - cmd: LC_DYSYMTAB<br class="">
+ cmdsize: 80<br class="">
+ ilocalsym: 0<br class="">
+ nlocalsym: 9<br class="">
+ iextdefsym: 9<br class="">
+ nextdefsym: 2<br class="">
+ iundefsym: 11<br class="">
+ nundefsym: 19<br class="">
+ tocoff: 0<br class="">
+ ntoc: 0<br class="">
+ modtaboff: 0<br class="">
+ nmodtab: 0<br class="">
+ extrefsymoff: 0<br class="">
+ nextrefsyms: 0<br class="">
+ indirectsymoff: 13560<br class="">
+ nindirectsyms: 35<br class="">
+ extreloff: 0<br class="">
+ nextrel: 0<br class="">
+ locreloff: 0<br class="">
+ nlocrel: 0<br class="">
+ - cmd: LC_LOAD_DYLINKER<br class="">
+ cmdsize: 32<br class="">
+ name: 12<br class="">
+ PayloadString: /usr/lib/dyld<br class="">
+ ZeroPadBytes: 7<br class="">
+ - cmd: LC_UUID<br class="">
+ cmdsize: 24<br class="">
+ uuid: 461A1B28-822F-3F38-B670-645419E636F5<br class="">
+ - cmd: LC_VERSION_MIN_MACOSX<br class="">
+ cmdsize: 16<br class="">
+ version: 658176<br class="">
+ sdk: 658176<br class="">
+ - cmd: LC_SOURCE_VERSION<br class="">
+ cmdsize: 16<br class="">
+ version: 0<br class="">
+ - cmd: LC_MAIN<br class="">
+ cmdsize: 24<br class="">
+ entryoff: 4448<br class="">
+ stacksize: 0<br class="">
+ - cmd: LC_LOAD_DYLIB<br class="">
+ cmdsize: 48<br class="">
+ dylib:<br class="">
+ name: 24<br class="">
+ timestamp: 2<br class="">
+ current_version: 7864576<br class="">
+ compatibility_version: 65536<br class="">
+ PayloadString: '/usr/lib/libc++.1.dylib'<br class="">
+ ZeroPadBytes: 1<br class="">
+ - cmd: LC_LOAD_DYLIB<br class="">
+ cmdsize: 56<br class="">
+ dylib:<br class="">
+ name: 24<br class="">
+ timestamp: 2<br class="">
+ current_version: 80349697<br class="">
+ compatibility_version: 65536<br class="">
+ PayloadString: /usr/lib/libSystem.B.dylib<br class="">
+ ZeroPadBytes: 6<br class="">
+ - cmd: LC_FUNCTION_STARTS<br class="">
+ cmdsize: 16<br class="">
+ dataoff: 13064<br class="">
+ datasize: 16<br class="">
+ - cmd: LC_DATA_IN_CODE<br class="">
+ cmdsize: 16<br class="">
+ dataoff: 13080<br class="">
+ datasize: 0<br class="">
+LinkEditData:<br class="">
+ ExportTrie:<br class="">
+ TerminalSize: 0<br class="">
+ NodeOffset: 0<br class="">
+ Name: ''<br class="">
+ Flags: 0x0000000000000000<br class="">
+ Address: 0x0000000000000000<br class="">
+ Other: 0x0000000000000000<br class="">
+ ImportName: ''<br class="">
+ Children:<br class="">
+ - TerminalSize: 0<br class="">
+ NodeOffset: 5<br class="">
+ Name: _<br class="">
+ Flags: 0x0000000000000000<br class="">
+ Address: 0x0000000000000000<br class="">
+ Other: 0x0000000000000000<br class="">
+ ImportName: ''<br class="">
+ Children:<br class="">
+ - TerminalSize: 2<br class="">
+ NodeOffset: 33<br class="">
+ Name: _mh_execute_header<br class="">
+ Flags: 0x0000000000000000<br class="">
+ Address: 0x0000000000000000<br class="">
+ Other: 0x0000000000000000<br class="">
+ ImportName: ''<br class="">
+ - TerminalSize: 3<br class="">
+ NodeOffset: 37<br class="">
+ Name: main<br class="">
+ Flags: 0x0000000000000000<br class="">
+ Address: 0x0000000000001160<br class="">
+ Other: 0x0000000000000000<br class="">
+ ImportName: ''<br class="">
+...<br class="">
+<br class="">
+#CHECK: ExportTrie:<br class="">
+#CHECK: TerminalSize: 0<br class="">
+#CHECK: NodeOffset: 0<br class="">
+#CHECK: Name: ''<br class="">
+#CHECK: Children:<br class="">
+#CHECK: - TerminalSize: 0<br class="">
+#CHECK: NodeOffset: 5<br class="">
+#CHECK: Name: _<br class="">
+#CHECK: Children:<br class="">
+#CHECK: - TerminalSize: 2<br class="">
+#CHECK: NodeOffset: 33<br class="">
+#CHECK: Name: _mh_execute_header<br class="">
+#CHECK: Address: 0x0000000000000000<br class="">
+#CHECK: - TerminalSize: 3<br class="">
+#CHECK: NodeOffset: 37<br class="">
+#CHECK: Name: main<br class="">
+#CHECK: Address: 0x0000000000001160<br class="">
<br class="">
Modified: llvm/trunk/tools/obj2yaml/macho2yaml.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/macho2yaml.cpp?rev=271300&r1=271299&r2=271300&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/macho2yaml.cpp?rev=271300&r1=271299&r2=271300&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/tools/obj2yaml/macho2yaml.cpp (original)<br class="">
+++ llvm/trunk/tools/obj2yaml/macho2yaml.cpp Tue May 31 12:26:36 2016<br class="">
@@ -32,6 +32,7 @@ class MachODumper {<br class="">
void dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y);<br class="">
void dumpBindOpcodes(std::vector<MachOYAML::BindOpcode> &BindOpcodes,<br class="">
ArrayRef<uint8_t> OpcodeBuffer, bool Lazy = false);<br class="">
+ void dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y);<br class="">
<br class="">
public:<br class="">
MachODumper(const object::MachOObjectFile &O) : Obj(O) {}<br class="">
@@ -149,6 +150,13 @@ const char *MachODumper::processLoadComm<br class="">
return readString<MachO::dylinker_command>(LC, LoadCmd);<br class="">
}<br class="">
<br class="">
+template <><br class="">
+const char *MachODumper::processLoadCommandData<MachO::rpath_command>(<br class="">
+ MachOYAML::LoadCommand &LC,<br class="">
+ const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {<br class="">
+ return readString<MachO::rpath_command>(LC, LoadCmd);<br class="">
+}<br class="">
+<br class="">
Expected<std::unique_ptr<MachOYAML::Object>> MachODumper::dump() {<br class="">
auto Y = make_unique<MachOYAML::Object>();<br class="">
dumpHeader(Y);<br class="">
@@ -199,8 +207,9 @@ void MachODumper::dumpLinkEdit(std::uniq<br class="">
dumpBindOpcodes(Y->LinkEdit.BindOpcodes, Obj.getDyldInfoBindOpcodes());<br class="">
dumpBindOpcodes(Y->LinkEdit.WeakBindOpcodes,<br class="">
Obj.getDyldInfoWeakBindOpcodes());<br class="">
- dumpBindOpcodes(Y->LinkEdit.LazyBindOpcodes,<br class="">
- Obj.getDyldInfoLazyBindOpcodes(), true);<br class="">
+ dumpBindOpcodes(Y->LinkEdit.LazyBindOpcodes, Obj.getDyldInfoLazyBindOpcodes(),<br class="">
+ true);<br class="">
+ dumpExportTrie(Y);<br class="">
}<br class="">
<br class="">
void MachODumper::dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y) {<br class="">
@@ -244,6 +253,13 @@ void MachODumper::dumpRebaseOpcodes(std:<br class="">
}<br class="">
}<br class="">
<br class="">
+StringRef ReadStringRef(const uint8_t *Start) {<br class="">
+ const uint8_t *Itr = Start;<br class="">
+ for (; *Itr; ++Itr)<br class="">
+ ;<br class="">
+ return StringRef(reinterpret_cast<const char *>(Start), Itr - Start);<br class="">
+}<br class="">
+<br class="">
void MachODumper::dumpBindOpcodes(<br class="">
std::vector<MachOYAML::BindOpcode> &BindOpcodes,<br class="">
ArrayRef<uint8_t> OpcodeBuffer, bool Lazy) {<br class="">
@@ -257,7 +273,6 @@ void MachODumper::dumpBindOpcodes(<br class="">
unsigned Count;<br class="">
uint64_t ULEB = 0;<br class="">
int64_t SLEB = 0;<br class="">
- const uint8_t *SymStart;<br class="">
<br class="">
switch (BindOp.Opcode) {<br class="">
case MachO::BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:<br class="">
@@ -282,12 +297,8 @@ void MachODumper::dumpBindOpcodes(<br class="">
break;<br class="">
<br class="">
case MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM:<br class="">
- SymStart = ++OpCode;<br class="">
- while (*OpCode) {<br class="">
- ++OpCode;<br class="">
- }<br class="">
- BindOp.Symbol = StringRef(reinterpret_cast<const char *>(SymStart),<br class="">
- OpCode - SymStart);<br class="">
+ BindOp.Symbol = ReadStringRef(OpCode + 1);<br class="">
+ OpCode += BindOp.Symbol.size() + 1;<br class="">
break;<br class="">
default:<br class="">
break;<br class="">
@@ -302,6 +313,117 @@ void MachODumper::dumpBindOpcodes(<br class="">
}<br class="">
}<br class="">
<br class="">
+/*!<br class="">
+ * /brief processes a node from the export trie, and its children.<br class="">
+ *<br class="">
+ * To my knowledge there is no documentation of the encoded format of this data<br class="">
+ * other than in the heads of the Apple linker engineers. To that end hopefully<br class="">
+ * this comment and the implementation below can serve to light the way for<br class="">
+ * anyone crazy enough to come down this path in the future.<br class="">
+ *<br class="">
+ * This function reads and preserves the trie structure of the export trie. To<br class="">
+ * my knowledge there is no code anywhere else that reads the data and preserves<br class="">
+ * the Trie. LD64 (sources available at <a href="http://opensource.apple.com/" rel="noreferrer" target="_blank" class="">opensource.apple.com</a>) has a similar<br class="">
+ * implementation that parses the export trie into a vector. That code as well<br class="">
+ * as LLVM's libObject MachO implementation were the basis for this.<br class="">
+ *<br class="">
+ * The export trie is an encoded trie. The node serialization is a bit awkward.<br class="">
+ * The below pseudo-code is the best description I've come up with for it.<br class="">
+ *<br class="">
+ * struct SerializedNode {<br class="">
+ * ULEB128 TerminalSize;<br class="">
+ * struct TerminalData { <-- This is only present if TerminalSize > 0<br class="">
+ * ULEB128 Flags;<br class="">
+ * ULEB128 Address; <-- Present if (! Flags & REEXPORT )<br class="">
+ * ULEB128 Other; <-- Present if ( Flags & REEXPORT ||<br class="">
+ * Flags & STUB_AND_RESOLVER )<br class="">
+ * char[] ImportName; <-- Present if ( Flags & REEXPORT )<br class="">
+ * }<br class="">
+ * uint8_t ChildrenCount;<br class="">
+ * Pair<char[], ULEB128> ChildNameOffsetPair[ChildrenCount];<br class="">
+ * SerializedNode Children[ChildrenCount]<br class="">
+ * }<br class="">
+ *<br class="">
+ * Terminal nodes are nodes that represent actual exports. They can appear<br class="">
+ * anywhere in the tree other than at the root; they do not need to be leaf<br class="">
+ * nodes. When reading the data out of the trie this routine reads it in-order,<br class="">
+ * but it puts the child names and offsets directly into the child nodes. This<br class="">
+ * results in looping over the children twice during serialization and<br class="">
+ * de-serialization, but it makes the YAML representation more human readable.<br class="">
+ *<br class="">
+ * Below is an example of the graph from a "Hello World" executable:<br class="">
+ *<br class="">
+ * -------<br class="">
+ * | '' |<br class="">
+ * -------<br class="">
+ * |<br class="">
+ * -------<br class="">
+ * | '_' |<br class="">
+ * -------<br class="">
+ * |<br class="">
+ * |----------------------------------------|<br class="">
+ * | |<br class="">
+ * ------------------------ ---------------------<br class="">
+ * | '_mh_execute_header' | | 'main' |<br class="">
+ * | Flags: 0x00000000 | | Flags: 0x00000000 |<br class="">
+ * | Addr: 0x00000000 | | Addr: 0x00001160 |<br class="">
+ * ------------------------ ---------------------<br class="">
+ *<br class="">
+ * This graph represents the trie for the exports "__mh_execute_header" and<br class="">
+ * "_main". In the graph only the "_main" and "__mh_execute_header" nodes are<br class="">
+ * terminal.<br class="">
+*/<br class="">
+<br class="">
+const uint8_t *processExportNode(const uint8_t *CurrPtr,<br class="">
+ const uint8_t *const End,<br class="">
+ MachOYAML::ExportEntry &Entry) {<br class="">
+ if (CurrPtr >= End)<br class="">
+ return CurrPtr;<br class="">
+ unsigned Count = 0;<br class="">
+ Entry.TerminalSize = decodeULEB128(CurrPtr, &Count);<br class="">
+ CurrPtr += Count;<br class="">
+ if (Entry.TerminalSize != 0) {<br class="">
+ Entry.Flags = decodeULEB128(CurrPtr, &Count);<br class="">
+ CurrPtr += Count;<br class="">
+ if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT) {<br class="">
+ Entry.Address = 0;<br class="">
+ Entry.Other = decodeULEB128(CurrPtr, &Count);<br class="">
+ CurrPtr += Count;<br class="">
+ Entry.ImportName = std::string(reinterpret_cast<const char *>(CurrPtr));<br class="">
+ } else {<br class="">
+ Entry.Address = decodeULEB128(CurrPtr, &Count);<br class="">
+ CurrPtr += Count;<br class="">
+ if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) {<br class="">
+ Entry.Other = decodeULEB128(CurrPtr, &Count);<br class="">
+ CurrPtr += Count;<br class="">
+ } else<br class="">
+ Entry.Other = 0;<br class="">
+ }<br class="">
+ }<br class="">
+ uint8_t childrenCount = *CurrPtr++;<br class="">
+ if (childrenCount == 0)<br class="">
+ return CurrPtr;<br class="">
+<br class="">
+ Entry.Children.insert(Entry.Children.begin(), (size_t)childrenCount,<br class="">
+ MachOYAML::ExportEntry());<br class="">
+ for (auto &Child : Entry.Children) {<br class="">
+ Child.Name = std::string(reinterpret_cast<const char *>(CurrPtr));<br class="">
+ CurrPtr += Child.Name.length() + 1;<br class="">
+ Child.NodeOffset = decodeULEB128(CurrPtr, &Count);<br class="">
+ CurrPtr += Count;<br class="">
+ }<br class="">
+ for (auto &Child : Entry.Children) {<br class="">
+ CurrPtr = processExportNode(CurrPtr, End, Child);<br class="">
+ }<br class="">
+ return CurrPtr;<br class="">
+}<br class="">
+<br class="">
+void MachODumper::dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y) {<br class="">
+ MachOYAML::LinkEditData &LEData = Y->LinkEdit;<br class="">
+ auto ExportsTrie = Obj.getDyldInfoExportsTrie();<br class="">
+ processExportNode(ExportsTrie.begin(), ExportsTrie.end(), LEData.ExportTrie);<br class="">
+}<br class="">
+<br class="">
Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) {<br class="">
MachODumper Dumper(Obj);<br class="">
Expected<std::unique_ptr<MachOYAML::Object>> YAML = Dumper.dump();<br class="">
<br class="">
Modified: llvm/trunk/tools/yaml2obj/yaml2macho.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2macho.cpp?rev=271300&r1=271299&r2=271300&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2macho.cpp?rev=271300&r1=271299&r2=271300&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/tools/yaml2obj/yaml2macho.cpp (original)<br class="">
+++ llvm/trunk/tools/yaml2obj/yaml2macho.cpp Tue May 31 12:26:36 2016<br class="">
@@ -48,7 +48,9 @@ private:<br class="">
Error writeLinkEditData(raw_ostream &OS);<br class="">
void writeBindOpcodes(raw_ostream &OS, uint64_t offset,<br class="">
std::vector<MachOYAML::BindOpcode> &BindOpcodes);<br class="">
+ Error writeExportTrie(raw_ostream &OS);<br class="">
<br class="">
+ void dumpExportEntry(raw_ostream &OS, MachOYAML::ExportEntry &Entry);<br class="">
void ZeroToOffset(raw_ostream &OS, size_t offset);<br class="">
<br class="">
MachOYAML::Object &Obj;<br class="">
@@ -161,6 +163,12 @@ size_t writeLoadCommandData<MachO::dylin<br class="">
return writePayloadString(LC, OS);<br class="">
}<br class="">
<br class="">
+template <><br class="">
+size_t writeLoadCommandData<MachO::rpath_command>(MachOYAML::LoadCommand &LC,<br class="">
+ raw_ostream &OS) {<br class="">
+ return writePayloadString(LC, OS);<br class="">
+}<br class="">
+<br class="">
void ZeroFillBytes(raw_ostream &OS, size_t Size) {<br class="">
std::vector<uint8_t> FillData;<br class="">
FillData.insert(FillData.begin(), Size, 0);<br class="">
@@ -282,9 +290,39 @@ void MachOWriter::writeBindOpcodes(<br class="">
}<br class="">
if (!Opcode.Symbol.empty()) {<br class="">
OS.write(Opcode.Symbol.data(), Opcode.Symbol.size());<br class="">
- OS.write("\0", 1);<br class="">
+ OS.write('\0');<br class="">
+ }<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+void MachOWriter::dumpExportEntry(raw_ostream &OS, MachOYAML::ExportEntry &Entry) {<br class="">
+ encodeSLEB128(Entry.TerminalSize, OS);<br class="">
+ if (Entry.TerminalSize > 0) {<br class="">
+ encodeSLEB128(Entry.Flags, OS);<br class="">
+ if ( Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT ) {<br class="">
+ encodeSLEB128(Entry.Other, OS);<br class="">
+ OS << Entry.ImportName;<br class="">
+ OS.write('\0');<br class="">
+ }<br class="">
+ else {<br class="">
+ encodeSLEB128(Entry.Address, OS);<br class="">
+ if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER)<br class="">
+ encodeSLEB128(Entry.Other, OS);<br class="">
}<br class="">
}<br class="">
+ OS.write(static_cast<uint8_t>(Entry.Children.size()));<br class="">
+ for (auto EE : Entry.Children){<br class="">
+ OS << EE.Name;<br class="">
+ OS.write('\0');<br class="">
+ encodeSLEB128(EE.NodeOffset, OS);<br class="">
+ }<br class="">
+ for (auto EE : Entry.Children)<br class="">
+ dumpExportEntry(OS, EE);<br class="">
+}<br class="">
+<br class="">
+Error MachOWriter::writeExportTrie(raw_ostream &OS) {<br class="">
+ dumpExportEntry(OS, Obj.LinkEdit.ExportTrie);<br class="">
+ return Error::success();<br class="">
}<br class="">
<br class="">
Error MachOWriter::writeLinkEditData(raw_ostream &OS) {<br class="">
@@ -318,6 +356,10 @@ Error MachOWriter::writeLinkEditData(raw<br class="">
writeBindOpcodes(OS, DyldInfoOnlyCmd->lazy_bind_off,<br class="">
LinkEdit.LazyBindOpcodes);<br class="">
<br class="">
+ ZeroToOffset(OS, DyldInfoOnlyCmd->export_off);<br class="">
+ if(auto Err = writeExportTrie(OS))<br class="">
+ return Err;<br class="">
+<br class="">
// Fill to the end of the string table<br class="">
ZeroToOffset(OS, SymtabCmd->stroff + SymtabCmd->strsize);<br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></body></html>