diff options
| author | Chris Bieneman <beanz@apple.com> | 2016-12-06 06:00:49 +0000 |
|---|---|---|
| committer | Chris Bieneman <beanz@apple.com> | 2016-12-06 06:00:49 +0000 |
| commit | 8b058aec1d9499015e4a3fd2e5a503273a5d384b (patch) | |
| tree | cbfeaee4b164bac6bc4ebe7d8c32261d3b612774 /llvm/tools/yaml2obj/yaml2macho.cpp | |
| parent | 31150cbdc93040d294b563b4a5475775f5599236 (diff) | |
| download | bcm5719-llvm-8b058aec1d9499015e4a3fd2e5a503273a5d384b.tar.gz bcm5719-llvm-8b058aec1d9499015e4a3fd2e5a503273a5d384b.zip | |
[ObjectYAML] First bit of support for encoding DWARF in MachO
This patch adds the starting support for encoding data from the MachO __DWARF segment. The first section supported is the __debug_str section because it is the simplest.
llvm-svn: 288774
Diffstat (limited to 'llvm/tools/yaml2obj/yaml2macho.cpp')
| -rw-r--r-- | llvm/tools/yaml2obj/yaml2macho.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/llvm/tools/yaml2obj/yaml2macho.cpp b/llvm/tools/yaml2obj/yaml2macho.cpp index fb29e206be3..3312cd45fb7 100644 --- a/llvm/tools/yaml2obj/yaml2macho.cpp +++ b/llvm/tools/yaml2obj/yaml2macho.cpp @@ -41,6 +41,8 @@ private: Error writeLoadCommands(raw_ostream &OS); Error writeSectionData(raw_ostream &OS); Error writeLinkEditData(raw_ostream &OS); + Error writeDWARFData(raw_ostream &OS, + std::vector<MachOYAML::Section> &Sections); void writeBindOpcodes(raw_ostream &OS, std::vector<MachOYAML::BindOpcode> &BindOpcodes); // LinkEdit writers @@ -240,6 +242,9 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) { if (0 == strncmp(&segname[0], "__LINKEDIT", 16)) { if (auto Err = writeLinkEditData(OS)) return Err; + } else if (0 == strncmp(&segname[0], "__DWARF", 16)) { + if (auto Err = writeDWARFData(OS, LC.Sections)) + return Err; } else { // Zero Fill any data between the end of the last thing we wrote and the // start of this section. @@ -252,7 +257,8 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) { // the // start of this section. assert( - OS.tell() - fileStart <= Sec.offset && + (OS.tell() - fileStart <= Sec.offset || + Sec.offset == (uint32_t)0) && "Wrote too much data somewhere, section offsets don't line up."); currOffset = OS.tell() - fileStart; if (currOffset < Sec.offset) { @@ -378,6 +384,20 @@ Error MachOWriter::writeLinkEditData(raw_ostream &OS) { return Error::success(); } +Error MachOWriter::writeDWARFData(raw_ostream &OS, + std::vector<MachOYAML::Section> &Sections) { + for(auto Section : Sections) { + ZeroToOffset(OS, Section.offset); + if (0 == strncmp(&Section.sectname[0], "__debug_str", 16)) { + for (auto Str : Obj.DWARF.DebugStrings) { + OS.write(Str.data(), Str.size()); + OS.write('\0'); + } + } + } + return Error::success(); +} + Error MachOWriter::writeRebaseOpcodes(raw_ostream &OS) { MachOYAML::LinkEditData &LinkEdit = Obj.LinkEdit; |

