summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-04-22 15:05:19 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2010-04-22 19:05:50 +0400
commit7c8c258cddb85e3a3d53a5ff373a747796f1d327 (patch)
tree7bb2501400928fd2eba5355a6f6ee570b166c1cf
parent42017a611590d0ca764ab017aad0abdf0e6cf633 (diff)
downloadnasm-7c8c258cddb85e3a3d53a5ff373a747796f1d327.tar.gz
coff: Fix section alignment computation
Section alignment is broken due to not being direct "align -> power of two set" mapping but rather including second addition operation. Fix it by introducing coff_sectalign_flags helper. This also allow us to use this helper for getting rid of open coded computation as well. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--output/outcoff.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/output/outcoff.c b/output/outcoff.c
index 7123db3a..cb646792 100644
--- a/output/outcoff.c
+++ b/output/outcoff.c
@@ -312,6 +312,11 @@ static int coff_make_section(char *name, uint32_t flags)
return nsects - 1;
}
+static inline int32_t coff_sectalign_flags(unsigned int align)
+{
+ return (ilog2_32(align) + 1) << 20;
+}
+
static int32_t coff_section_names(char *name, int pass, int *bits)
{
char *p;
@@ -394,7 +399,7 @@ static int32_t coff_section_names(char *name, int pass, int *bits)
" to better than 64-byte boundaries");
else {
align_and = ~0x00F00000L;
- align_or = ilog2_32(align) << 20;
+ align_or = coff_sectalign_flags(align);
}
}
}
@@ -1034,13 +1039,7 @@ static void coff_sectalign(int32_t seg, unsigned int value)
return;
align = (s->flags & 0x00F00000L);
- value = (value == 1 ? 0x00100000L :
- value == 2 ? 0x00200000L :
- value == 4 ? 0x00300000L :
- value == 8 ? 0x00400000L :
- value == 16 ? 0x00500000L :
- value == 32 ? 0x00600000L : 0x00700000L);
-
+ value = coff_sectalign_flags(value);
if (value > align)
s->flags = (s->flags & ~0x00F00000L) | value;
}