Move alignment to function
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 27 Nov 2024 13:31:32 +0000 (13:31 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 27 Nov 2024 13:31:32 +0000 (13:31 +0000)
link.c
pe.h

diff --git a/link.c b/link.c
index 9dc34a1cbf75951bcaada0ba3dac277ccd57fed7..b478f5fc7dc366f8fb65f273271afa373bc81494 100644 (file)
--- a/link.c
+++ b/link.c
@@ -386,6 +386,16 @@ static void calculate_entry_point (void) {
 
 }
 
+static unsigned long align_section_if_needed (unsigned long value) {
+
+    if (state->format == LD_FORMAT_I386_PE) {
+        return pe_align_to_file_alignment (value);
+    }
+    
+    return value;
+
+}
+
 void link (void) {
 
     struct section *section;
@@ -400,13 +410,7 @@ void link (void) {
     if ((symbol = symbol_find ("__edata")) && symbol_is_undefined (symbol)) {
     
         if ((section = section_find (".text"))) {
-        
-            if (state->format == LD_FORMAT_I386_PE) {
-                value += pe_align_to_file_alignment (section->total_size);
-            } else {
-                value += section->total_size;
-            }
-        
+            value += align_section_if_needed (section->total_size);
         }
         
         of = object_file_make (FAKE_LD_FILENAME, 1);
@@ -426,23 +430,11 @@ void link (void) {
     if ((symbol = symbol_find ("__end")) && symbol_is_undefined (symbol)) {
     
         if ((section = section_find (".data"))) {
-        
-            if (state->format == LD_FORMAT_I386_PE) {
-                value += pe_align_to_file_alignment (section->total_size);
-            } else {
-                value += section->total_size;
-            }
-        
+            value += align_section_if_needed (section->total_size);
         }
         
         if ((section = section_find (".bss"))) {
-        
-            if (state->format == LD_FORMAT_I386_PE) {
-                value += pe_align_to_file_alignment (section->total_size);
-            } else {
-                value += section->total_size;
-            }
-        
+            value += align_section_if_needed (section->total_size);
         }
         
         of = object_file_make (FAKE_LD_FILENAME, 1);
diff --git a/pe.h b/pe.h
index 39c1d5d55cb54df3ac3675a8695644696ff7166a..f195e55bb8ce2b584bb5edc1db825a30ba4c83e6 100644 (file)
--- a/pe.h
+++ b/pe.h
@@ -194,13 +194,13 @@ struct pe_import_directory_table {
 
 int pe_check_option (const char *cmd_arg, int argc, char **argv, int *optind, const char **optarg);
 
+unsigned long pe_align_to_file_alignment (unsigned long value);
+unsigned long pe_get_first_section_rva (void);
+
 void pe_after_link (void);
 void pe_before_link (void);
 void pe_print_help (void);
 
-unsigned long pe_align_to_file_alignment (unsigned long value);
-unsigned long pe_get_first_section_rva (void);
-
 void pe_write (const char *filename);
 void pe_use_option (const char *cmd_arg, int idx, const char *optarg);