0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-07-24 10:25:42 -04:00

Merge branch 'master' into elfmerge

Resolved Conflicts:
	output/outmacho.c

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
H. Peter Anvin 2016-02-26 20:51:46 -08:00
commit 8aba13b51f
4 changed files with 46 additions and 22 deletions

View File

@ -40,6 +40,8 @@ since 2007.
\b Line numbers in list files now correspond to the lines in the source \b Line numbers in list files now correspond to the lines in the source
files, instead of simply being sequential. files, instead of simply being sequential.
\b There is now an official 64-bit (x64 a.k.a. x86-64) build for Windows.
\S{cl-2.11.09} Version 2.11.09 \S{cl-2.11.09} Version 2.11.09

View File

@ -3,14 +3,14 @@
Summary: The Netwide Assembler, a portable x86 assembler with Intel-like syntax Summary: The Netwide Assembler, a portable x86 assembler with Intel-like syntax
Name: nasm Name: nasm
Version: @@NASM_MANGLED_VER@@ Version: @@NASM_MANGLED_VER@@
Release: 1 Release: 0
License: BSD License: BSD
Group: Development/Languages Group: Development/Languages
Source: http://www.nasm.us/pub/nasm/releasebuilds/%{nasm_version}/nasm-%{nasm_version}.tar.xz Source: http://www.nasm.us/pub/nasm/releasebuilds/%{nasm_version}/nasm-%{nasm_version}.tar.xz
URL: http://www.nasm.us/ URL: http://www.nasm.us/
BuildRoot: /tmp/rpm-build-nasm BuildRoot: /tmp/rpm-build-nasm
Prefix: %{_prefix} Prefix: %{_prefix}
BuildRequires: perl BuildRequires: perl, asciidoc, xmlto, ghostscript, texinfo
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%package doc %package doc

View File

@ -179,6 +179,9 @@ struct section {
#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section uses pure #define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section uses pure
machine instructions */ machine instructions */
/* Fake section for absolute symbols, *not* part of the section linked list */
static struct section absolute_sect;
static const struct sectmap { static const struct sectmap {
const char *nasmsect; const char *nasmsect;
const char *segname; const char *segname;
@ -274,8 +277,6 @@ static struct RAA *extsyms;
static struct SAA *strs; static struct SAA *strs;
static uint32_t strslen; static uint32_t strslen;
extern const struct ofmt of_macho64;
/* Global file information. This should be cleaned up into either /* Global file information. This should be cleaned up into either
a structure or as function arguments. */ a structure or as function arguments. */
static uint32_t head_ncmds = 0; static uint32_t head_ncmds = 0;
@ -338,6 +339,9 @@ static void macho_init(void)
sects = NULL; sects = NULL;
sectstail = &sects; sectstail = &sects;
/* Fake section for absolute symbols */
absolute_sect.index = NO_SEG;
syms = NULL; syms = NULL;
symstail = &syms; symstail = &syms;
nsyms = 0; nsyms = 0;
@ -376,8 +380,9 @@ static struct symbol *macho_find_gsym(struct section *s,
srb = rb_search(s->gsyms, offset); srb = rb_search(s->gsyms, offset);
if (!srb || (exact && srb->key != offset)) { if (!srb || (exact && srb->key != offset)) {
nasm_error(ERR_NONFATAL, "unable to find a suitable global symbol" nasm_error(ERR_NONFATAL, "unable to find a suitable %s symbol"
" for this reference"); " for this reference",
s == &absolute_sect ? "absolute" : "global");
return NULL; return NULL;
} }
@ -436,21 +441,33 @@ static int64_t add_reloc(struct section *sect, int32_t section,
} }
break; break;
case RL_BRANCH:
r->type = X86_64_RELOC_BRANCH;
goto rel_or_branch;
case RL_REL: case RL_REL:
case RL_BRANCH:
r->type = fmt.reloc_rel; r->type = fmt.reloc_rel;
rel_or_branch:
r->pcrel = 1; r->pcrel = 1;
if (section == NO_SEG) { if (section == NO_SEG) {
goto bail; /* No relocation needed */ /* absolute - seems to produce garbage no matter what */
nasm_error(ERR_NONFATAL, "Mach-O does not support relative "
"references to absolute addresses");
goto bail;
#if 0
/* This "seems" to be how it ought to work... */
struct symbol *sym = macho_find_gsym(&absolute_sect,
offset, false);
if (!sym)
goto bail;
sect->extreloc = 1;
r->snum = NO_SECT;
adjust = -sect->size;
#endif
} else if (fi == NO_SECT) { } else if (fi == NO_SECT) {
/* external */ /* external */
sect->extreloc = 1; sect->extreloc = 1;
r->snum = raa_read(extsyms, section); r->snum = raa_read(extsyms, section);
if (reltype == RL_BRANCH)
r->type = X86_64_RELOC_BRANCH;
} else { } else {
/* local */ /* local */
r->ext = 0; r->ext = 0;
@ -647,7 +664,7 @@ static void macho_output(int32_t secto, const void *data,
saa_fread(s->data, 0, opcode+1, 1); saa_fread(s->data, 0, opcode+1, 1);
} }
if (opcode[1] == 0xe8 || opcode[1] == 0xe9 || if ((opcode[0] != 0x0f && (opcode[1] & 0xfe) == 0xe8) ||
(opcode[0] == 0x0f && (opcode[1] & 0xf0) == 0x80)) { (opcode[0] == 0x0f && (opcode[1] & 0xf0) == 0x80)) {
/* Direct call, jmp, or jcc */ /* Direct call, jmp, or jcc */
reltype = RL_BRANCH; reltype = RL_BRANCH;
@ -821,7 +838,8 @@ static int32_t macho_section(char *name, int pass, int *bits)
s->align = newAlignment; s->align = newAlignment;
} else if (!nasm_stricmp("data", currentAttribute)) { } else if (!nasm_stricmp("data", currentAttribute)) {
flags = S_REGULAR; flags = S_REGULAR;
} else if (!nasm_stricmp("code", currentAttribute)) { } else if (!nasm_stricmp("code", currentAttribute) ||
!nasm_stricmp("text", currentAttribute)) {
flags = S_REGULAR | S_ATTR_SOME_INSTRUCTIONS | flags = S_REGULAR | S_ATTR_SOME_INSTRUCTIONS |
S_ATTR_PURE_INSTRUCTIONS; S_ATTR_PURE_INSTRUCTIONS;
} else if (!nasm_stricmp("mixed", currentAttribute)) { } else if (!nasm_stricmp("mixed", currentAttribute)) {
@ -898,6 +916,9 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
/* symbols in no section get absolute */ /* symbols in no section get absolute */
sym->type |= N_ABS; sym->type |= N_ABS;
sym->sect = NO_SECT; sym->sect = NO_SECT;
/* all absolute symbols are available to use as references */
absolute_sect.gsyms = rb_insert(absolute_sect.gsyms, &sym->symv);
} else { } else {
struct section *s = get_section_by_index(section); struct section *s = get_section_by_index(section);
@ -1103,7 +1124,6 @@ static void macho_calculate_sizes (void)
* perhaps aligning to pointer size would be better. * perhaps aligning to pointer size would be better.
*/ */
s->pad = ALIGN(seg_filesize, 4) - seg_filesize; s->pad = ALIGN(seg_filesize, 4) - seg_filesize;
// s->pad = ALIGN(seg_filesize, 1U << s->align) - seg_filesize;
s->offset = seg_filesize + s->pad; s->offset = seg_filesize + s->pad;
seg_filesize += s->size + s->pad; seg_filesize += s->size + s->pad;
} }
@ -1128,7 +1148,7 @@ static void macho_calculate_sizes (void)
/* Create a table of sections by file index to avoid linear search */ /* Create a table of sections by file index to avoid linear search */
sectstab = nasm_malloc((seg_nsects + 1) * sizeof(*sectstab)); sectstab = nasm_malloc((seg_nsects + 1) * sizeof(*sectstab));
sectstab[0] = NULL; sectstab[NO_SECT] = &absolute_sect;
for (s = sects, fi = 1; s != NULL; s = s->next, fi++) for (s = sects, fi = 1; s != NULL; s = s->next, fi++)
sectstab[fi] = s; sectstab[fi] = s;
} }
@ -1302,6 +1322,8 @@ static void macho_write_section (void)
/* generate final address by section address and offset */ /* generate final address by section address and offset */
nasm_assert(r->snum <= seg_nsects); nasm_assert(r->snum <= seg_nsects);
l += sectstab[r->snum]->addr; l += sectstab[r->snum]->addr;
if (r->pcrel)
l -= s->addr;
} }
/* write new offset back */ /* write new offset back */

View File

@ -1 +1 @@
2.12rc6 2.12