mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-03-19 18:00:23 +08:00
Use ALIGN helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
89fe355ad0
commit
9b66d8e4c3
@ -757,7 +757,7 @@ static void aout_pad_sections(void)
|
||||
*/
|
||||
aout_sect_write(&stext, pad, (-(int32_t)stext.len) & 3);
|
||||
aout_sect_write(&sdata, pad, (-(int32_t)sdata.len) & 3);
|
||||
sbss.len = (sbss.len + 3) & ~3;
|
||||
sbss.len = ALIGN(sbss.len, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -396,8 +396,7 @@ static void bin_cleanup(int debuginfo)
|
||||
nasm_error(ERR_FATAL|ERR_NOFILE, "section %s begins"
|
||||
" before program origin", sections->name);
|
||||
} else if (sections->flags & ALIGN_DEFINED) {
|
||||
sections->start = ((origin + sections->align - 1) &
|
||||
~(sections->align - 1));
|
||||
sections->start = ALIGN(origin, sections->align - 1);
|
||||
} else {
|
||||
sections->start = origin;
|
||||
}
|
||||
@ -424,7 +423,7 @@ static void bin_cleanup(int debuginfo)
|
||||
g->flags |= ALIGN_DEFINED;
|
||||
}
|
||||
/* Set the section start address. */
|
||||
g->start = (pend + g->align - 1) & ~(g->align - 1);
|
||||
g->start = ALIGN(pend, g->align);
|
||||
g->flags |= START_DEFINED;
|
||||
}
|
||||
/* Ugly special case for progbits sections' virtual attributes:
|
||||
@ -437,7 +436,7 @@ static void bin_cleanup(int debuginfo)
|
||||
* vstart equal to the start address. */
|
||||
if (!(g->flags & (VSTART_DEFINED | VFOLLOWS_DEFINED))) {
|
||||
if (g->flags & VALIGN_DEFINED)
|
||||
g->vstart = (pend + g->valign - 1) & ~(g->valign - 1);
|
||||
g->vstart = ALIGN(pend, g->valign);
|
||||
else
|
||||
g->vstart = g->start;
|
||||
g->flags |= VSTART_DEFINED;
|
||||
@ -503,9 +502,8 @@ static void bin_cleanup(int debuginfo)
|
||||
g->flags |= VALIGN_DEFINED;
|
||||
}
|
||||
/* Compute the vstart address. */
|
||||
g->vstart = (s->vstart + s->length + g->valign - 1)
|
||||
& ~(g->valign - 1);
|
||||
g->flags |= VSTART_DEFINED;
|
||||
g->vstart = ALIGN(s->vstart + s->length, g->valign);
|
||||
g->flags |= VSTART_DEFINED;
|
||||
h++;
|
||||
/* Start and vstart mean the same thing for nobits sections. */
|
||||
if (g->flags & TYPE_NOBITS)
|
||||
|
@ -1030,7 +1030,7 @@ static void elf_write(void)
|
||||
*/
|
||||
|
||||
elf_foffs = 0x40 + 0x28 * nsections;
|
||||
align = ((elf_foffs + SEG_ALIGN_1) & ~SEG_ALIGN_1) - elf_foffs;
|
||||
align = ALIGN(elf_foffs, SEG_ALIGN) - elf_foffs;
|
||||
elf_foffs += align;
|
||||
elf_nsect = 0;
|
||||
elf_sects = nasm_malloc(sizeof(*elf_sects) * nsections);
|
||||
@ -1330,7 +1330,7 @@ static void elf_section_header(int name, int type, int flags,
|
||||
fwriteint32_t(type == 0 ? 0L : elf_foffs, ofile);
|
||||
fwriteint32_t(datalen, ofile);
|
||||
if (data)
|
||||
elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1;
|
||||
elf_foffs += ALIGN(datalen, SEG_ALIGN);
|
||||
fwriteint32_t((int32_t)link, ofile);
|
||||
fwriteint32_t((int32_t)info, ofile);
|
||||
fwriteint32_t((int32_t)align, ofile);
|
||||
@ -1343,7 +1343,7 @@ static void elf_write_sections(void)
|
||||
for (i = 0; i < elf_nsect; i++)
|
||||
if (elf_sects[i].data) {
|
||||
int32_t len = elf_sects[i].len;
|
||||
int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1;
|
||||
int32_t reallen = ALIGN(len, SEG_ALIGN);
|
||||
int32_t align = reallen - len;
|
||||
if (elf_sects[i].is_saa)
|
||||
saa_fpwrite(elf_sects[i].data, ofile);
|
||||
|
@ -1117,7 +1117,7 @@ static void elf_write(void)
|
||||
*/
|
||||
|
||||
elf_foffs = 0x40 + sizeof(Elf64_Shdr) * nsections;
|
||||
align = ((elf_foffs + SEG_ALIGN_1) & ~SEG_ALIGN_1) - elf_foffs;
|
||||
align = ALIGN(elf_foffs, SEG_ALIGN) - elf_foffs;
|
||||
elf_foffs += align;
|
||||
elf_nsect = 0;
|
||||
elf_sects = nasm_malloc(sizeof(*elf_sects) * nsections);
|
||||
@ -1415,7 +1415,7 @@ static void elf_section_header(int name, int type, uint64_t flags,
|
||||
fwriteint64_t(type == 0 ? 0L : elf_foffs, ofile);
|
||||
fwriteint64_t(datalen, ofile);
|
||||
if (data)
|
||||
elf_foffs += (datalen + SEG_ALIGN_1) & ~SEG_ALIGN_1;
|
||||
elf_foffs += ALIGN(datalen, SEG_ALIGN);
|
||||
fwriteint32_t((int32_t)link, ofile);
|
||||
fwriteint32_t((int32_t)info, ofile);
|
||||
fwriteint64_t((int64_t)align, ofile);
|
||||
@ -1428,7 +1428,7 @@ static void elf_write_sections(void)
|
||||
for (i = 0; i < elf_nsect; i++)
|
||||
if (elf_sects[i].data) {
|
||||
int32_t len = elf_sects[i].len;
|
||||
int32_t reallen = (len + SEG_ALIGN_1) & ~SEG_ALIGN_1;
|
||||
int32_t reallen = ALIGN(len, SEG_ALIGN);
|
||||
int32_t align = reallen - len;
|
||||
if (elf_sects[i].is_saa)
|
||||
saa_fpwrite(elf_sects[i].data, ofile);
|
||||
|
@ -225,11 +225,8 @@ uint32_t rel_padcnt = 0;
|
||||
strncpy(xdst, xsrc, sizeof(xdst)); /* copy over string */ \
|
||||
xdst[sizeof(xdst) - 1] = '\0'; /* proper null-termination */
|
||||
|
||||
#define align(x, y) \
|
||||
(((x) + (y) - 1) & ~((y) - 1)) /* align x to multiple of y */
|
||||
|
||||
#define alignint32_t(x) \
|
||||
align(x, sizeof(int32_t)) /* align x to int32_t boundary */
|
||||
ALIGN(x, sizeof(int32_t)) /* align x to int32_t boundary */
|
||||
|
||||
static void debug_reloc (struct reloc *);
|
||||
static void debug_section_relocs (struct section *) _unused;
|
||||
@ -832,7 +829,7 @@ static void macho_calculate_sizes (void)
|
||||
if (s->align == -1)
|
||||
s->align = DEFAULT_SECTION_ALIGNMENT;
|
||||
if(s->align) {
|
||||
uint32_t newaddr = align(s->addr, 1 << s->align);
|
||||
uint32_t newaddr = ALIGN(s->addr, 1 << s->align);
|
||||
pad = newaddr - s->addr;
|
||||
s->addr = newaddr;
|
||||
}
|
||||
|
@ -226,14 +226,11 @@ uint64_t rel_padcnt64 = 0;
|
||||
strncpy(xdst, xsrc, sizeof(xdst)); /* copy over string */ \
|
||||
xdst[sizeof(xdst) - 1] = '\0'; /* proper null-termination */
|
||||
|
||||
#define align(x, y) \
|
||||
(((x) + (y) - 1) & ~((y) - 1)) /* align x to multiple of y */
|
||||
|
||||
#define alignint32_t(x) \
|
||||
align(x, sizeof(int32_t)) /* align x to int32_t boundary */
|
||||
ALIGN(x, sizeof(int32_t)) /* align x to int32_t boundary */
|
||||
|
||||
#define alignint64_t(x) \
|
||||
align(x, sizeof(int64_t)) /* align x to int64_t boundary */
|
||||
ALIGN(x, sizeof(int64_t)) /* align x to int64_t boundary */
|
||||
|
||||
static void debug_reloc (struct reloc *);
|
||||
static void debug_section_relocs (struct section *) _unused;
|
||||
@ -981,7 +978,7 @@ static void macho_calculate_sizes (void)
|
||||
if (s->align == -1)
|
||||
s->align = DEFAULT_SECTION_ALIGNMENT;
|
||||
if(s->align) {
|
||||
uint64_t newaddr = align(s->addr, 1 << s->align);
|
||||
uint64_t newaddr = ALIGN(s->addr, 1 << s->align);
|
||||
pad = newaddr - s->addr;
|
||||
s->addr = newaddr;
|
||||
}
|
||||
|
@ -2228,7 +2228,7 @@ static int do_directive(Token * tline)
|
||||
free_tlist(tt);
|
||||
|
||||
/* Round up to even stack slots */
|
||||
size = (size+StackSize-1) & ~(StackSize-1);
|
||||
size = ALIGN(size, StackSize);
|
||||
|
||||
/* Now define the macro for the argument */
|
||||
snprintf(directive, sizeof(directive), "%%define %s (%s+%d)",
|
||||
@ -2303,7 +2303,7 @@ static int do_directive(Token * tline)
|
||||
free_tlist(tt);
|
||||
|
||||
/* Round up to even stack slots */
|
||||
size = (size+StackSize-1) & ~(StackSize-1);
|
||||
size = ALIGN(size, StackSize);
|
||||
|
||||
offset += size; /* Negative offset, increment before */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user