From 712434c69b5abeac6ce963eac2ed90daf7a800b0 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Wed, 27 Nov 2024 13:31:32 +0000 Subject: [PATCH] Move alignment to function --- link.c | 34 +++++++++++++--------------------- pe.h | 6 +++--- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/link.c b/link.c index 9dc34a1..b478f5f 100644 --- 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 39c1d5d..f195e55 100644 --- 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); -- 2.34.1