summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2008-12-07 02:49:22 +0000
committerPeter Johnson <peter@tortall.net>2008-12-07 02:49:22 +0000
commit6eaa345a2c6246be6f48463823cf6f447b27c0c4 (patch)
tree93f430e8d1263a3db61bdd4685968e8150f491a1
parent1af17712ca011ba64a20653413032d543ced7017 (diff)
downloadyasm-6eaa345a2c6246be6f48463823cf6f447b27c0c4.tar.gz
Fix Mach-O alignment handling by aligning start and end of every section.
Reported and patch by: David DeHaven <dave@sagetv.com> svn path=/trunk/yasm/; revision=2161
-rw-r--r--modules/objfmts/macho/macho-objfmt.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/objfmts/macho/macho-objfmt.c b/modules/objfmts/macho/macho-objfmt.c
index 10d5893a..e825dbef 100644
--- a/modules/objfmts/macho/macho-objfmt.c
+++ b/modules/objfmts/macho/macho-objfmt.c
@@ -978,6 +978,7 @@ macho_objfmt_calc_sectsize(yasm_section *sect, /*@null@ */ void *d)
/*@null@ */ macho_objfmt_output_info *info =
(macho_objfmt_output_info *) d;
/*@dependent@ *//*@null@ */ macho_section_data *msd;
+ unsigned long align;
assert(info != NULL);
msd = yasm_section_get_data(sect, &macho_section_data_cb);
@@ -994,6 +995,16 @@ macho_objfmt_calc_sectsize(yasm_section *sect, /*@null@ */ void *d)
msd->vmoff = info->vmsize;
info->vmsize += msd->size;
+ /* align both start and end of section */
+ align = yasm_section_get_align(sect);
+ if (align != 0) {
+ unsigned long delta = msd->vmoff % align;
+ if (delta > 0) {
+ msd->vmoff += align - delta;
+ info->vmsize += delta;
+ }
+ }
+
return 0;
}