From: nasm-bot f. H. P. A. <hp...@li...> - 2016-02-17 02:06:17
|
Commit-ID: 085a4a9f98861ed904b37dee1e4c7906a1bc0929 Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=085a4a9f98861ed904b37dee1e4c7906a1bc0929 Author: H. Peter Anvin <hp...@li...> AuthorDate: Tue, 16 Feb 2016 18:04:39 -0800 Committer: H. Peter Anvin <hp...@li...> CommitDate: Tue, 16 Feb 2016 18:04:39 -0800 outmacho: fix the .rodata -> __TEXT,__const mapping For the mapping of .rodata to __TEXT,__const in the absence of relocations, it would help if we changed the segment name *before* we emit that part of the load command. Signed-off-by: H. Peter Anvin <hp...@li...> --- output/outmacho.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/output/outmacho.c b/output/outmacho.c index 24b4338..d2952b2 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -1074,6 +1074,24 @@ static uint32_t macho_write_segment (uint64_t offset) /* emit section headers */ for (s = sects; s != NULL; s = s->next) { + if (s->nreloc) { + nasm_assert((s->flags & SECTION_TYPE) != S_ZEROFILL); + s->flags |= S_ATTR_LOC_RELOC; + if (s->extreloc) + s->flags |= S_ATTR_EXT_RELOC; + } else if (!strcmp(s->segname, "__DATA") && + !strcmp(s->sectname, "__const") && + !s->by_name && + !get_section_by_name("__TEXT", "__const")) { + /* + * The MachO equivalent to .rodata can be either + * __DATA,__const or __TEXT,__const; the latter only if + * there are no relocations. However, when mixed it is + * better to specify the segments explicitly. + */ + xstrncpy(s->segname, "__TEXT"); + } + nasm_write(s->sectname, sizeof(s->sectname), ofile); nasm_write(s->segname, sizeof(s->segname), ofile); fwriteptr(s->addr, ofile); @@ -1101,23 +1119,6 @@ static uint32_t macho_write_segment (uint64_t offset) fwriteint32_t(0, ofile); } - if (s->nreloc) { - s->flags |= S_ATTR_LOC_RELOC; - if (s->extreloc) - s->flags |= S_ATTR_EXT_RELOC; - } else if (!strcmp(s->segname, "__DATA") && - !strcmp(s->sectname, "__const") && - !s->by_name && - !get_section_by_name("__TEXT", "__const")) { - /* - * The MachO equivalent to .rodata can be either - * __DATA,__const or __TEXT,__const; the latter only if - * there are no relocations. However, when mixed it is - * better to specify the segments explicitly. - */ - xstrncpy(s->segname, "__TEXT"); - } - fwriteint32_t(s->flags, ofile); /* flags */ fwriteint32_t(0, ofile); /* reserved */ fwriteptr(0, ofile); /* reserved */ |