summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-02-11 21:23:50 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2010-02-11 21:28:30 +0300
commit9b66d8e4c3030474a75e598f699eccc118a3d651 (patch)
tree9bba8cb1f9bab97632d0c6b3a07e18d7fc20f217
parent89fe355ad00d49aa0a8514a76dfd0745d29cfd09 (diff)
downloadnasm-9b66d8e4c3030474a75e598f699eccc118a3d651.tar.gz
Use ALIGN helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--output/outaout.c2
-rw-r--r--output/outbin.c12
-rw-r--r--output/outelf32.c6
-rw-r--r--output/outelf64.c6
-rw-r--r--output/outmacho32.c7
-rw-r--r--output/outmacho64.c9
-rw-r--r--preproc.c4
7 files changed, 19 insertions, 27 deletions
diff --git a/output/outaout.c b/output/outaout.c
index e2a9075f..31ce5b5e 100644
--- a/output/outaout.c
+++ b/output/outaout.c
@@ -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);
}
/*
diff --git a/output/outbin.c b/output/outbin.c
index 41c28f30..9b1bd6ab 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -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)
diff --git a/output/outelf32.c b/output/outelf32.c
index 0ce21135..0a2bbba6 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -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);
diff --git a/output/outelf64.c b/output/outelf64.c
index fb373b78..bf5f80e8 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -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);
diff --git a/output/outmacho32.c b/output/outmacho32.c
index 1a211a6e..51c22318 100644
--- a/output/outmacho32.c
+++ b/output/outmacho32.c
@@ -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;
}
diff --git a/output/outmacho64.c b/output/outmacho64.c
index dfe523b7..ba785faa 100644
--- a/output/outmacho64.c
+++ b/output/outmacho64.c
@@ -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;
}
diff --git a/preproc.c b/preproc.c
index b5c95af4..575755f0 100644
--- a/preproc.c
+++ b/preproc.c
@@ -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 */