Skip to content

Commit

Permalink
[Mach-O] Map __DATA,__const to __DATA_CONST,__const
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Jul 6, 2022
1 parent 5634b22 commit be5fe4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions macho/input-files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ bool ObjectFile<E>::is_objc_object(Context<E> &ctx) {
if (!mach_syms[i].is_undef() && mach_syms[i].is_extern &&
this->syms[i]->name.starts_with("_OBJC_CLASS_$_"))
return true;

return false;
}

Expand Down
15 changes: 12 additions & 3 deletions macho/input-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

namespace mold::macho {

template <typename E>
OutputSection<E> &get_output_section(Context<E> &ctx, const MachSection &hdr) {
std::string_view seg = hdr.get_segname();
std::string_view sect = hdr.get_sectname();

if (seg == "__DATA" && sect == "__const")
seg = "__DATA_CONST";

return *OutputSection<E>::get_instance(ctx, seg, sect);
}

template <typename E>
InputSection<E>::InputSection(Context<E> &ctx, ObjectFile<E> &file,
const MachSection &hdr)
: file(file), hdr(hdr),
osec(*OutputSection<E>::get_instance(ctx, hdr.get_segname(),
hdr.get_sectname())) {
: file(file), hdr(hdr), osec(get_output_section(ctx, hdr)) {
if (hdr.type != S_ZEROFILL)
contents = file.mf->get_contents().substr(hdr.offset, hdr.size);
}
Expand Down

0 comments on commit be5fe4c

Please sign in to comment.