macho: fix section to segment mapping
This commit is contained in:
@@ -119,12 +119,9 @@ pub fn getThunk(self: Atom, macho_file: *MachO) *Thunk {
|
||||
|
||||
pub fn initOutputSection(sect: macho.section_64, macho_file: *MachO) !u8 {
|
||||
const segname, const sectname, const flags = blk: {
|
||||
const segname = sect.segName();
|
||||
const sectname = sect.sectName();
|
||||
|
||||
if (sect.isCode()) break :blk .{
|
||||
"__TEXT",
|
||||
sectname,
|
||||
"__text",
|
||||
macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
|
||||
};
|
||||
|
||||
@@ -135,32 +132,36 @@ pub fn initOutputSection(sect: macho.section_64, macho_file: *MachO) !u8 {
|
||||
=> break :blk .{ "__TEXT", "__const", macho.S_REGULAR },
|
||||
|
||||
macho.S_CSTRING_LITERALS => {
|
||||
if (mem.startsWith(u8, sectname, "__objc")) break :blk .{
|
||||
segname, sectname, macho.S_REGULAR,
|
||||
if (mem.startsWith(u8, sect.sectName(), "__objc")) break :blk .{
|
||||
sect.segName(), sect.sectName(), macho.S_REGULAR,
|
||||
};
|
||||
break :blk .{ "__TEXT", "__cstring", macho.S_CSTRING_LITERALS };
|
||||
},
|
||||
|
||||
macho.S_MOD_INIT_FUNC_POINTERS,
|
||||
macho.S_MOD_TERM_FUNC_POINTERS,
|
||||
macho.S_LITERAL_POINTERS,
|
||||
=> break :blk .{ "__DATA_CONST", sectname, sect.flags },
|
||||
=> break :blk .{ "__DATA_CONST", sect.sectName(), sect.flags },
|
||||
|
||||
macho.S_LITERAL_POINTERS,
|
||||
macho.S_ZEROFILL,
|
||||
macho.S_GB_ZEROFILL,
|
||||
macho.S_THREAD_LOCAL_VARIABLES,
|
||||
macho.S_THREAD_LOCAL_VARIABLE_POINTERS,
|
||||
macho.S_THREAD_LOCAL_REGULAR,
|
||||
macho.S_THREAD_LOCAL_ZEROFILL,
|
||||
=> break :blk .{ "__DATA", sectname, sect.flags },
|
||||
=> break :blk .{ sect.segName(), sect.sectName(), sect.flags },
|
||||
|
||||
// TODO: do we need this check here?
|
||||
macho.S_COALESCED => break :blk .{ segname, sectname, macho.S_REGULAR },
|
||||
macho.S_COALESCED => break :blk .{
|
||||
sect.segName(),
|
||||
sect.sectName(),
|
||||
macho.S_REGULAR,
|
||||
},
|
||||
|
||||
macho.S_REGULAR => {
|
||||
const segname = sect.segName();
|
||||
const sectname = sect.sectName();
|
||||
if (mem.eql(u8, segname, "__DATA")) {
|
||||
if (mem.eql(u8, sectname, "__const") or
|
||||
mem.eql(u8, sectname, "__cfstring") or
|
||||
if (mem.eql(u8, sectname, "__cfstring") or
|
||||
mem.eql(u8, sectname, "__objc_classlist") or
|
||||
mem.eql(u8, sectname, "__objc_imageinfo")) break :blk .{
|
||||
"__DATA_CONST",
|
||||
@@ -171,7 +172,7 @@ pub fn initOutputSection(sect: macho.section_64, macho_file: *MachO) !u8 {
|
||||
break :blk .{ segname, sectname, sect.flags };
|
||||
},
|
||||
|
||||
else => break :blk .{ segname, sectname, sect.flags },
|
||||
else => break :blk .{ sect.segName(), sect.sectName(), sect.flags },
|
||||
}
|
||||
};
|
||||
const osec = macho_file.getSectionByName(segname, sectname) orelse try macho_file.addSection(
|
||||
|
||||
Reference in New Issue
Block a user