mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-30 16:41:05 +08:00
BR 1709392: Fix alignment handling in Mach-O format
Fix alignment handling in the Mach-O format. The patch is from the bug report, mangled to apply to the current source base. I have no way to test this, so I'm going to have to assume it's correct.
This commit is contained in:
parent
4b3390eb47
commit
fb0c90cdbe
@ -557,7 +557,7 @@ static int32_t macho_section(char *name, int pass, int *bits)
|
||||
s->data = saa_init(1L);
|
||||
s->index = seg_alloc();
|
||||
s->relocs = NULL;
|
||||
s->align = DEFAULT_SECTION_ALIGNMENT;
|
||||
s->align = -1;
|
||||
|
||||
xstrncpy(s->segname, sm->segname);
|
||||
xstrncpy(s->sectname, sm->sectname);
|
||||
@ -597,7 +597,8 @@ static int32_t macho_section(char *name, int pass, int *bits)
|
||||
}
|
||||
|
||||
if ((-1 != originalIndex)
|
||||
&& (s->align != newAlignment)) {
|
||||
&& (s->align != newAlignment)
|
||||
&& (s->align != -1)) {
|
||||
error(ERR_PANIC,
|
||||
"section \"%s\" has already been specified "
|
||||
"with alignment %d, conflicts with new "
|
||||
@ -910,6 +911,8 @@ static uint32_t macho_write_segment (uint32_t offset)
|
||||
fwriteint32_t(offset, machofp);
|
||||
/* Write out section alignment, as a power of two.
|
||||
e.g. 32-bit word alignment would be 2 (2^^2 = 4). */
|
||||
if (s->align == -1)
|
||||
s->align = DEFAULT_SECTION_ALIGNMENT;
|
||||
fwriteint32_t(s->align, machofp);
|
||||
/* To be compatible with cctools as we emit
|
||||
a zero reloff if we have no relocations. */
|
||||
@ -999,11 +1002,10 @@ static void macho_write_section (void)
|
||||
offset which we already have. The linker takes care
|
||||
of the rest of the address. */
|
||||
if (!r->ext) {
|
||||
/* add sizes of previous sections to current offset */
|
||||
for (s2 = sects, fi = 1;
|
||||
s2 != NULL && fi < r->snum; s2 = s2->next, fi++)
|
||||
if ((s2->flags & SECTION_TYPE) != S_ZEROFILL)
|
||||
l += s2->size;
|
||||
/* add sizes of previous sections to current offset */
|
||||
for (s2 = sects, fi = 1;
|
||||
s2 != NULL && fi < r->snum; s2 = s2->next, fi++)
|
||||
l += s2->size;
|
||||
}
|
||||
|
||||
/* write new offset back */
|
||||
@ -1109,6 +1111,7 @@ static void macho_fixup_relocs (struct reloc *r)
|
||||
sym = undefsyms[i];
|
||||
if (sym->initial_snum == r->snum) {
|
||||
r->snum = sym->snum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1278,14 +1281,14 @@ static void macho_cleanup(int debuginfo)
|
||||
raa_free(extsyms);
|
||||
|
||||
if (syms) {
|
||||
while (syms->next) {
|
||||
sym = syms;
|
||||
syms = syms->next;
|
||||
while (syms->next) {
|
||||
sym = syms;
|
||||
syms = syms->next;
|
||||
|
||||
nasm_free (sym);
|
||||
}
|
||||
nasm_free (sym);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Debugging routines. */
|
||||
static void debug_reloc (struct reloc *r)
|
||||
|
Loading…
Reference in New Issue
Block a user