diff --git a/macho/dumper.cc b/macho/dumper.cc index cc50ee49..cffd9595 100644 --- a/macho/dumper.cc +++ b/macho/dumper.cc @@ -248,7 +248,7 @@ void dump_file(std::string path) { std::cout << "LC_SEGMENT_64\n"; SegmentCommand &cmd = *(SegmentCommand *)&lc; std::cout << " cmdsize: " << cmd.cmdsize - << "\n segname: " << cmd.segname + << "\n segname: " << cmd.get_segname() << "\n vmaddr: 0x" << std::hex << cmd.vmaddr << "\n vmsize: 0x" << cmd.vmsize << "\n fileoff: 0x" << cmd.fileoff @@ -261,8 +261,8 @@ void dump_file(std::string path) { MachSection *sec = (MachSection *)((u8 *)&lc + sizeof(cmd)); for (i64 j = 0; j < cmd.nsects; j++) { - std::cout << " section:\n sectname: " << sec[j].sectname - << "\n segname: " << sec[j].segname + std::cout << " section:\n sectname: " << sec[j].get_sectname() + << "\n segname: " << sec[j].get_segname() << "\n addr: 0x" << std::hex << sec[j].addr << "\n size: 0x" << sec[j].size << "\n offset: 0x" << sec[j].offset @@ -292,7 +292,8 @@ void dump_file(std::string path) { } } - if (sec[j].segname == "__TEXT"sv && sec[j].sectname == "__unwind_info"sv) + if (sec[j].get_segname() == "__TEXT" && + sec[j].get_sectname() == "__unwind_info"sv) dump_unwind_info(buf, sec[j]); } break; diff --git a/macho/input-sections.cc b/macho/input-sections.cc index d64e8e92..9c103e9f 100644 --- a/macho/input-sections.cc +++ b/macho/input-sections.cc @@ -5,7 +5,8 @@ namespace mold::macho { std::ostream &operator<<(std::ostream &out, const InputSection &sec) { - out << sec.file << "(" << sec.hdr.segname << "," << sec.hdr.sectname << ")"; + out << sec.file << "(" << sec.hdr.get_segname() << "," + << sec.hdr.get_sectname() << ")"; return out; } diff --git a/macho/macho.h b/macho/macho.h index 18e1a11e..cf7c2a9f 100644 --- a/macho/macho.h +++ b/macho/macho.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace mold::macho { @@ -316,6 +317,10 @@ struct LoadCommand { }; struct SegmentCommand { + std::string_view get_segname() const { + return {segname, strnlen(segname, sizeof(segname))}; + } + u32 cmd; u32 cmdsize; char segname[16]; @@ -330,6 +335,14 @@ struct SegmentCommand { }; struct MachSection { + std::string_view get_segname() const { + return {segname, strnlen(segname, sizeof(segname))}; + } + + std::string_view get_sectname() const { + return {sectname, strnlen(sectname, sizeof(sectname))}; + } + char sectname[16]; char segname[16]; u64 addr;