diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-04-25 22:00:15 +0400 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-04-25 22:00:15 +0400 |
commit | a20b668add234cb388e1802e217ef48257fa9e12 (patch) | |
tree | ae662d4d8331e2f0f66cd2064b901f8e5391119a | |
parent | 573d25fe92fac7209c0695c5904dc5b067cf902e (diff) | |
download | nasm-a20b668add234cb388e1802e217ef48257fa9e12.tar.gz nasm-a20b668add234cb388e1802e217ef48257fa9e12.tar.bz2 nasm-a20b668add234cb388e1802e217ef48257fa9e12.zip |
obj: Implement sectalign helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r-- | output/outobj.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/output/outobj.c b/output/outobj.c index 053ca4f..2453c9f 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -1777,6 +1777,49 @@ static int obj_directive(enum directives directive, char *value, int pass) } } +static void obj_sectalign(int32_t seg, unsigned int value) +{ + struct Segment *s; + + list_for_each(s, seghead) { + if (s->index == seg) + break; + } + + /* + * it should not be too big value + * and applied on non-absolute sections + */ + if (!s || !is_power2(value) || + value > 4096 || s->align >= SEG_ABS) + return; + + /* + * FIXME: No code duplication please + * consider making helper for this + * mapping since section handler has + * to do the same + */ + switch (value) { + case 8: + value = 16; + break; + case 32: + case 64: + case 128: + value = 256; + break; + case 512: + case 1024: + case 2048: + value = 4096; + break; + } + + if (s->align < (int)value) + s->align = value; +} + static int32_t obj_segbase(int32_t segment) { struct Segment *seg; @@ -2559,7 +2602,7 @@ struct ofmt of_obj = { obj_out, obj_deflabel, obj_segment, - null_sectalign, + obj_sectalign, obj_segbase, obj_directive, obj_filename, |