diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2016-02-16 18:04:39 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2016-02-16 18:04:39 -0800 |
commit | 085a4a9f98861ed904b37dee1e4c7906a1bc0929 (patch) | |
tree | cf3522146864b1d01dc6ed240a3f72f9b571956e | |
parent | 82a3082d643e2bf8da91bb178fa639eb494be4d6 (diff) | |
download | nasm-085a4a9f98861ed904b37dee1e4c7906a1bc0929.tar.gz |
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 <hpa@linux.intel.com>
-rw-r--r-- | output/outmacho.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/output/outmacho.c b/output/outmacho.c index 24b43386..d2952b2c 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 */ |