obj: Implement sectalign helper
authorCyrill Gorcunov <gorcunov@gmail.com>
Sun, 25 Apr 2010 18:00:15 +0000 (22:00 +0400)
committerCyrill Gorcunov <gorcunov@gmail.com>
Sun, 25 Apr 2010 18:00:15 +0000 (22:00 +0400)
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
output/outobj.c

index 053ca4fb745e6077d5c222dfaf0a733344c50449..2453c9fb339e0a6265fc8d63d992f1f67ceb0588 100644 (file)
@@ -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,