From cf7a3c01d82abdf110ef85ab770e5997d8ac28ac Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 15 Dec 2020 22:09:30 +1030 Subject: Lose some COFF/PE static vars, and peicode.h constify This patch tidies some COFF and PE code that unnecessarily used static variables to communicate between functions. * coffcode.h (pelength, peheader): Delete static variables. (coff_apply_checksum): Instead, define them as auto vars, and pass.. (coff_read_word, coff_compute_checksum): ..to here. Delete unnecessary forward declarations. * pei-x86_64.c (pdata_count): Delete static variable. (struct pex64_paps): New. (pex64_print_all_pdata_sections, pex64_bfd_print_pdata): Pass a pex64_paps for counting. * peicode.h (jtab): Constify. --- bfd/pei-x86_64.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'bfd/pei-x86_64.c') diff --git a/bfd/pei-x86_64.c b/bfd/pei-x86_64.c index 7af0d49..b1259a0 100644 --- a/bfd/pei-x86_64.c +++ b/bfd/pei-x86_64.c @@ -820,20 +820,25 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section) return TRUE; } -/* Static counter of number of found pdata sections. */ -static bfd_boolean pdata_count; +struct pex64_paps +{ + void *obj; + /* Number of found pdata sections. */ + unsigned int pdata_count; +}; /* Functionn prototype. */ bfd_boolean pex64_bfd_print_pdata (bfd *, void *); /* Helper function for bfd_map_over_section. */ static void -pex64_print_all_pdata_sections (bfd *abfd, asection *pdata, void *obj) +pex64_print_all_pdata_sections (bfd *abfd, asection *pdata, void *arg) { + struct pex64_paps *paps = arg; if (CONST_STRNEQ (pdata->name, ".pdata")) { - if (pex64_bfd_print_pdata_section (abfd, obj, pdata)) - pdata_count++; + if (pex64_bfd_print_pdata_section (abfd, paps->obj, pdata)) + paps->pdata_count++; } } @@ -841,13 +846,15 @@ bfd_boolean pex64_bfd_print_pdata (bfd *abfd, void *vfile) { asection *pdata_section = bfd_get_section_by_name (abfd, ".pdata"); + struct pex64_paps paps; if (pdata_section) return pex64_bfd_print_pdata_section (abfd, vfile, pdata_section); - pdata_count = 0; - bfd_map_over_sections (abfd, pex64_print_all_pdata_sections, vfile); - return (pdata_count > 0); + paps.obj = vfile; + paps.pdata_count = 0; + bfd_map_over_sections (abfd, pex64_print_all_pdata_sections, &paps); + return paps.pdata_count != 0; } #define bfd_pe_print_pdata pex64_bfd_print_pdata -- cgit v1.1