summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-05-26 20:50:05 +0000
committerChris Bieneman <beanz@apple.com>2016-05-26 20:50:05 +0000
commit659b35a5d8c0d6afc97a09f47db739bd192c5939 (patch)
tree589ec16026e19f422cef2caad1f67f882040b8bc /llvm/tools
parent84bb355c3a3958b0c85536a328af0cc3e1c2bda7 (diff)
downloadbcm5719-llvm-659b35a5d8c0d6afc97a09f47db739bd192c5939.tar.gz
bcm5719-llvm-659b35a5d8c0d6afc97a09f47db739bd192c5939.zip
[obj2yaml][yaml2obj] Support for MachO weak bindings
This adds support for YAML round tripping dyld info weak bindings. The storage and format of these is the same as regular bind opcodes, they are just interpreted differently by dyld. llvm-svn: 270911
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/obj2yaml/macho2yaml.cpp2
-rw-r--r--llvm/tools/yaml2obj/yaml2macho.cpp42
2 files changed, 28 insertions, 16 deletions
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp
index 7aca3fd82f0..bc3e2c53b95 100644
--- a/llvm/tools/obj2yaml/macho2yaml.cpp
+++ b/llvm/tools/obj2yaml/macho2yaml.cpp
@@ -197,6 +197,8 @@ void MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) {
void MachODumper::dumpLinkEdit(std::unique_ptr<MachOYAML::Object> &Y) {
dumpRebaseOpcodes(Y);
dumpBindOpcodes(Y->LinkEdit.BindOpcodes, Obj.getDyldInfoBindOpcodes());
+ dumpBindOpcodes(Y->LinkEdit.WeakBindOpcodes,
+ Obj.getDyldInfoWeakBindOpcodes());
}
void MachODumper::dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y) {
diff --git a/llvm/tools/yaml2obj/yaml2macho.cpp b/llvm/tools/yaml2obj/yaml2macho.cpp
index a1f5dda9d9d..199515d5c10 100644
--- a/llvm/tools/yaml2obj/yaml2macho.cpp
+++ b/llvm/tools/yaml2obj/yaml2macho.cpp
@@ -46,6 +46,8 @@ private:
Error writeLoadCommands(raw_ostream &OS);
Error writeSectionData(raw_ostream &OS);
Error writeLinkEditData(raw_ostream &OS);
+ void writeBindOpcodes(raw_ostream &OS, uint64_t offset,
+ std::vector<MachOYAML::BindOpcode> &BindOpcodes);
void ZeroToOffset(raw_ostream &OS, size_t offset);
@@ -264,6 +266,27 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
return Error::success();
}
+void MachOWriter::writeBindOpcodes(
+ raw_ostream &OS, uint64_t offset,
+ std::vector<MachOYAML::BindOpcode> &BindOpcodes) {
+ ZeroToOffset(OS, offset);
+
+ for (auto Opcode : BindOpcodes) {
+ uint8_t OpByte = Opcode.Opcode | Opcode.Imm;
+ OS.write(reinterpret_cast<char *>(&OpByte), 1);
+ for (auto Data : Opcode.ULEBExtraData) {
+ encodeULEB128(Data, OS);
+ }
+ for (auto Data : Opcode.SLEBExtraData) {
+ encodeSLEB128(Data, OS);
+ }
+ if (!Opcode.Symbol.empty()) {
+ OS.write(Opcode.Symbol.data(), Opcode.Symbol.size());
+ OS.write("\0", 1);
+ }
+ }
+}
+
Error MachOWriter::writeLinkEditData(raw_ostream &OS) {
MachOYAML::LinkEditData &LinkEdit = Obj.LinkEdit;
MachO::dyld_info_command *DyldInfoOnlyCmd = 0;
@@ -289,22 +312,9 @@ Error MachOWriter::writeLinkEditData(raw_ostream &OS) {
}
}
- ZeroToOffset(OS, DyldInfoOnlyCmd->bind_off);
-
- for (auto Opcode : LinkEdit.BindOpcodes) {
- uint8_t OpByte = Opcode.Opcode | Opcode.Imm;
- OS.write(reinterpret_cast<char *>(&OpByte), 1);
- for (auto Data : Opcode.ULEBExtraData) {
- encodeULEB128(Data, OS);
- }
- for (auto Data : Opcode.SLEBExtraData) {
- encodeSLEB128(Data, OS);
- }
- if(!Opcode.Symbol.empty()) {
- OS.write(Opcode.Symbol.data(), Opcode.Symbol.size());
- OS.write("\0", 1);
- }
- }
+ writeBindOpcodes(OS, DyldInfoOnlyCmd->bind_off, LinkEdit.BindOpcodes);
+ writeBindOpcodes(OS, DyldInfoOnlyCmd->weak_bind_off,
+ LinkEdit.WeakBindOpcodes);
// Fill to the end of the string table
ZeroToOffset(OS, SymtabCmd->stroff + SymtabCmd->strsize);
OpenPOWER on IntegriCloud