]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gprofng: Remove public hz and whoami variables
authorClaudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Fri, 21 Nov 2025 10:31:49 +0000 (12:31 +0200)
committerClaudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Fri, 21 Nov 2025 11:42:05 +0000 (13:42 +0200)
Remove public hz and whoami variables. This fixes the errors when
building with --enable-shared.

14 files changed:
gprofng/src/basic_blocks.h
gprofng/src/call_graph.h
gprofng/src/corefile.h
gprofng/src/gmon_basic_blocks.cc
gprofng/src/gmon_call_graph.cc
gprofng/src/gmon_corefile.cc
gprofng/src/gmon_hist.cc
gprofng/src/gmon_io.cc
gprofng/src/gmon_io.h
gprofng/src/gmon_symtab.cc
gprofng/src/gp-gmon.cc
gprofng/src/gp-gmon.h
gprofng/src/hist.h
gprofng/src/symtab.h

index 97c5283faf0e8ea06e4feaa8db0160a46525adc7..25152a9fd1e131963126f3309d17a7193bcc63ed 100644 (file)
@@ -25,6 +25,6 @@
 
 /* Read a basic-block record from file IFP.  FILENAME is the name of
    file IFP and is provided for formatting error-messages only.  */
-extern void bb_read_rec (FILE *, const char *, bool);
+extern void bb_read_rec (FILE *, const char *, bool, const char *);
 
 #endif /* basic_blocks_h */
index 5555bf3079d86960c78ae7258fcc61d29e6b7881..48e2faf072c3c321310c27fd172d994330139f48 100644 (file)
 #ifndef call_graph_h
 #define call_graph_h
 
-extern void cg_tally (bfd_vma, bfd_vma, unsigned long);
+extern void cg_tally (bfd_vma, bfd_vma, unsigned long, const char *);
 
 /* Read a record from file IFP describing an arc in the function
    call-graph and the count of how many times the arc has been
    traversed.  FILENAME is the name of file IFP and is provided for
    formatting error-messages only.  */
-extern void cg_read_rec (FILE *, const char *);
+extern void cg_read_rec (FILE *, const char *, const char *);
 
 #endif /* call_graph_h */
index 3db1a40934d99c3e5649efd4977ba26236c75e2b..89270d1c318e841281ef35def7a0aae5793320f3 100644 (file)
@@ -35,7 +35,7 @@ extern void * core_text_space;    /* Text space of a.out in core.  */
 extern int offset_to_code;        /* Offset (in bytes) of code from entry
                                      address of routine.  */
 
-extern int core_init (const char *);
-extern void symtab_init (void);
+extern int core_init (const char *, const char *);
+extern void symtab_init (const char *);
 
 #endif /* corefile_h */
index cc37b27c98f1c639b4bd43dd5e6929c124d551ba..2b38e71fbaae6beae14f9577c0b925b3774eeb44 100644 (file)
@@ -51,7 +51,8 @@ fskip_string (FILE *fp)
    of file IFP and is provided for formatting error-messages only.  */
 
 void
-bb_read_rec (FILE *ifp, const char *filename, bool line_granularity)
+bb_read_rec (FILE *ifp, const char *filename,
+            bool line_granularity, const char *whoami)
 {
   unsigned int nblocks, b;
   bfd_vma addr, ncalls;
@@ -65,7 +66,7 @@ bb_read_rec (FILE *ifp, const char *filename, bool line_granularity)
       done (1);
     }
 
-  symtab = get_symtab ();
+  symtab = get_symtab (whoami);
 
   nblocks = bfd_get_32 (core_bfd, (bfd_byte *) & nblocks);
   if (gmon_file_version == 0)
@@ -89,8 +90,8 @@ bb_read_rec (FILE *ifp, const char *filename, bool line_granularity)
              done (1);
            }
        }
-      else if (gmon_io_read_vma (ifp, &addr)
-              || gmon_io_read_vma (ifp, &ncalls))
+      else if (gmon_io_read_vma (ifp, &addr, whoami)
+              || gmon_io_read_vma (ifp, &ncalls, whoami))
        {
          perror (filename);
          done (1);
index 433c3a9f1a81538d2fef94a98b900b924c2c7bce..f0684420adf944b535d01af87688ab39075af3a8 100644 (file)
 #include "gmon_out.h"
 
 void
-cg_tally (bfd_vma from_pc, bfd_vma self_pc, unsigned long count)
+cg_tally (bfd_vma from_pc, bfd_vma self_pc,
+         unsigned long count, const char *whoami)
 {
   Sym *parent;
   Sym *child;
-  Sym_Table *symtab = get_symtab ();
+  Sym_Table *symtab = get_symtab (whoami);
 
   parent = sym_lookup (symtab, from_pc);
   child = sym_lookup (symtab, self_pc);
@@ -68,13 +69,13 @@ cg_tally (bfd_vma from_pc, bfd_vma self_pc, unsigned long count)
    formatting error-messages only.  */
 
 void
-cg_read_rec (FILE *ifp, const char *filename)
+cg_read_rec (FILE *ifp, const char *filename, const char *whoami)
 {
   bfd_vma from_pc, self_pc;
   unsigned int count;
 
-  if (gmon_io_read_vma (ifp, &from_pc)
-      || gmon_io_read_vma (ifp, &self_pc)
+  if (gmon_io_read_vma (ifp, &from_pc, whoami)
+      || gmon_io_read_vma (ifp, &self_pc, whoami)
       || gmon_io_read_32 (ifp, &count))
     {
       fprintf (stderr, "%s: %s: unexpected end of file\n",
@@ -87,5 +88,5 @@ cg_read_rec (FILE *ifp, const char *filename)
               (unsigned long) from_pc, (unsigned long) self_pc,
               (unsigned long) count));
   /* Add this arc:  */
-  cg_tally (from_pc, self_pc, count);
+  cg_tally (from_pc, self_pc, count, whoami);
 }
index 93abb91abf25a7666a58182de5358f78217e0080..07bab11618e8a281cae1e50c8eff12c9d0247a99 100644 (file)
@@ -63,7 +63,7 @@ static bool get_src_info
 
 
 int
-core_init (const char * aout_name)
+core_init (const char * aout_name, const char *whoami)
 {
   int core_sym_bytes;
   asymbol *synthsyms;
@@ -331,7 +331,7 @@ source_file_lookup_path (const char *path)
    One symbol per function is entered.  */
 
 static void
-core_create_function_syms (void)
+core_create_function_syms (const char *whoami)
 {
   int cxxclass;
   long i;
@@ -486,7 +486,7 @@ core_create_function_syms (void)
 /* Initialize the symbol table.  */
 
 void
-symtab_init (void)
+symtab_init (const char *whoami)
 {
-  core_create_function_syms ();
+  core_create_function_syms (whoami);
 }
index e3c7fd8a10568c02e18d78a3c683c42e153cc468..38035e3a631b3aec942194f4b8551bb2cccee663 100644 (file)
@@ -38,7 +38,7 @@ extern void print_name (Sym * self);
 typedef unsigned char UNIT[2]; /* unit of profiling */
 #define UNITS_TO_CODE (offset_to_code / sizeof(UNIT))
 
-static void scale_and_align_entries (void);
+static long hz = 0;
 
 /* Given a range of addresses for a symbol, find a histogram record
    that intersects with this range, and clips the range to that
@@ -47,7 +47,8 @@ static void scale_and_align_entries (void);
    If no intersection is found, *P_LOWPC and *P_HIGHPC will be set to
    one unspecified value.  If more that one intersection is found,
    an error is emitted.  */
-static void hist_clip_symbol_address (bfd_vma *p_lowpc, bfd_vma *p_highpc);
+static void hist_clip_symbol_address (bfd_vma *p_lowpc,
+                                     bfd_vma *p_highpc, const char *whoami);
 
 
 /* Declarations of automatically generated functions to output blurbs.  */
@@ -100,15 +101,15 @@ SItab[] =
 static void
 read_histogram_header (histogram *record,
                       FILE *ifp, const char *filename,
-                      int first)
+                      int first, const char *whoami)
 {
   unsigned int profrate;
   char n_hist_dimension[15];
   char n_hist_dimension_abbrev;
   double n_hist_scale;
 
-  if (gmon_io_read_vma (ifp, &record->lowpc)
-      || gmon_io_read_vma (ifp, &record->highpc)
+  if (gmon_io_read_vma (ifp, &record->lowpc, whoami)
+      || gmon_io_read_vma (ifp, &record->highpc, whoami)
       || gmon_io_read_32 (ifp, &record->num_bins)
       || gmon_io_read_32 (ifp, &profrate)
       || gmon_io_read (ifp, n_hist_dimension, 15)
@@ -177,7 +178,7 @@ read_histogram_header (histogram *record,
    is provided for formatting error messages only.  */
 
 void
-hist_read_rec (FILE * ifp, const char *filename)
+hist_read_rec (FILE * ifp, const char *filename, const char *whoami)
 {
   bfd_vma lowpc, highpc;
   histogram n_record;
@@ -186,7 +187,7 @@ hist_read_rec (FILE * ifp, const char *filename)
 
   /* 1. Read the header and see if there's existing record for the
      same address range and that there are no overlapping records.  */
-  read_histogram_header (&n_record, ifp, filename, num_histograms == 0);
+  read_histogram_header (&n_record, ifp, filename, num_histograms == 0, whoami);
 
   existing_record = find_histogram (n_record.lowpc, n_record.highpc);
   if (existing_record)
@@ -199,7 +200,7 @@ hist_read_rec (FILE * ifp, const char *filename)
         record, it's an error.  */
       lowpc = n_record.lowpc;
       highpc = n_record.highpc;
-      hist_clip_symbol_address (&lowpc, &highpc);
+      hist_clip_symbol_address (&lowpc, &highpc, whoami);
       if (lowpc != highpc)
        {
          fprintf (stderr,
@@ -259,12 +260,12 @@ hist_read_rec (FILE * ifp, const char *filename)
    next bin.  */
 
 static void
-scale_and_align_entries (void)
+scale_and_align_entries (const char *whoami)
 {
   Sym *sym;
   bfd_vma bin_of_entry;
   bfd_vma bin_of_code;
-  Sym_Table *symtab = get_symtab ();
+  Sym_Table *symtab = get_symtab (whoami);
 
   for (sym = symtab->base; sym < symtab->limit; sym++)
     {
@@ -329,7 +330,7 @@ scale_and_align_entries (void)
    cases, above).  */
 
 static void
-hist_assign_samples_1 (histogram *r)
+hist_assign_samples_1 (histogram *r, const char *whoami)
 {
   bfd_vma bin_low_pc, bin_high_pc;
   bfd_vma sym_low_pc, sym_high_pc;
@@ -337,7 +338,7 @@ hist_assign_samples_1 (histogram *r)
   unsigned int bin_count;
   unsigned int i, j, k;
   double count_time, credit;
-  Sym_Table *symtab = get_symtab ();
+  Sym_Table *symtab = get_symtab (whoami);
 
   bfd_vma lowpc = r->lowpc / sizeof (UNIT);
 
@@ -403,14 +404,14 @@ hist_assign_samples_1 (histogram *r)
 
 /* Calls 'hist_assign_samples_1' for all histogram records read so far. */
 void
-hist_assign_samples (void)
+hist_assign_samples (const char *whoami)
 {
   unsigned i;
 
-  scale_and_align_entries ();
+  scale_and_align_entries (whoami);
 
   for (i = 0; i < num_histograms; ++i)
-    hist_assign_samples_1 (&histograms[i]);
+    hist_assign_samples_1 (&histograms[i], whoami);
 
 }
 
@@ -421,8 +422,9 @@ hist_assign_samples (void)
 #define max(a,b) (((a)>(b)) ? (a) : (b))
 #endif
 
-void
-hist_clip_symbol_address (bfd_vma *p_lowpc, bfd_vma *p_highpc)
+static void
+hist_clip_symbol_address (bfd_vma *p_lowpc,
+                         bfd_vma *p_highpc, const char *whoami)
 {
   unsigned i;
   int found = 0;
@@ -488,3 +490,10 @@ find_histogram_for_pc (bfd_vma pc)
     }
   return 0;
 }
+
+/* Return the profile rate in hz. */
+long
+hist_get_hz (void)
+{
+  return hz;
+}
index 6860d2e1e6c6b927bd2a88d4659a186004380f59..82e6cee25ddb09c373e48ff37ddd190df8bc67e4 100644 (file)
@@ -54,7 +54,6 @@ enum gmon_ptr_signedness {
   ptr_unsigned
 };
 
-static enum gmon_ptr_size gmon_get_ptr_size (void);
 static enum gmon_ptr_signedness gmon_get_ptr_signedness (void);
 
 static int gmon_io_read_64 (FILE *, uint64_t *);
@@ -63,7 +62,7 @@ int gmon_input = 0;
 int gmon_file_version = 0;     /* 0 == old (non-versioned) file format.  */
 
 static enum gmon_ptr_size
-gmon_get_ptr_size (void)
+gmon_get_ptr_size (const char *whoami)
 {
   int size;
 
@@ -124,12 +123,12 @@ gmon_io_read_64 (FILE *ifp, uint64_t *valp)
 }
 
 int
-gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
+gmon_io_read_vma (FILE *ifp, bfd_vma *valp, const char *whoami)
 {
   unsigned int val32;
   uint64_t val64;
 
-  switch (gmon_get_ptr_size ())
+  switch (gmon_get_ptr_size (whoami))
     {
     case ptr_32bit:
       if (gmon_io_read_32 (ifp, &val32))
@@ -161,7 +160,8 @@ gmon_io_read (FILE *ifp, char *buf, size_t n)
 }
 
 int
-gmon_out_read (const char *filename, File_Format file_format)
+gmon_out_read (const char *filename,
+              File_Format file_format, const char *whoami)
 {
   FILE *ifp;
   struct gmon_hdr ghdr;
@@ -221,19 +221,19 @@ gmon_out_read (const char *filename, File_Format file_format)
            case GMON_TAG_TIME_HIST:
              ++nhist;
              gmon_input |= INPUT_HISTOGRAM;
-             hist_read_rec (ifp, filename);
+             hist_read_rec (ifp, filename, whoami);
              break;
 
            case GMON_TAG_CG_ARC:
              ++narcs;
              gmon_input |= INPUT_CALL_GRAPH;
-             cg_read_rec (ifp, filename);
+             cg_read_rec (ifp, filename, whoami);
              break;
 
            case GMON_TAG_BB_COUNT:
              ++nbbs;
              gmon_input |= INPUT_BB_COUNTS;
-             bb_read_rec (ifp, filename, false);
+             bb_read_rec (ifp, filename, false, whoami);
              break;
 
            default:
index d2fe8549773c34ef2f3006f0dabdc1e61af0c2f8..de5c678145f08eeba28a186ed619c8f24daa3028 100644 (file)
@@ -37,10 +37,10 @@ File_Format;
 extern int gmon_input;          /* What input did we see?  */
 extern int gmon_file_version;   /* File version are we dealing with.  */
 
-extern int gmon_io_read_vma (FILE *ifp, bfd_vma *valp);
+extern int gmon_io_read_vma (FILE *ifp, bfd_vma *valp, const char *whoami);
 extern int gmon_io_read_32 (FILE *ifp, unsigned int *valp);
 extern int gmon_io_read (FILE *ifp, char *buf, size_t n);
 
-extern int gmon_out_read   (const char *, File_Format);
+extern int gmon_out_read (const char *, File_Format, const char *);
 
 #endif /* gmon_io_h */
index edf82de42ad996161838c6f60b8e4301dd5a4af3..68c8a0bd216d740f297f2b27a8337048ea4ebdcb 100644 (file)
@@ -44,12 +44,12 @@ get_symtab_direct (void)
    initialized yet.  */
 
 Sym_Table *
-get_symtab (void)
+get_symtab (const char *whoami)
 {
   static Sym_Table *symtab_p;
   if (!symtab_p)
     {
-      symtab_init ();
+      symtab_init (whoami);
 
       symtab_p = &symtab;
     }
index 07739b74398466c080411597ea94d021649271c5..353839d4628f40e473542d69543578eb47f61c8a 100644 (file)
@@ -105,9 +105,6 @@ typedef struct ClockPacket
   int       nticks;     /* number of ticks in that state */
 } ClockPacket;
 
-const char *whoami;
-long hz = HZ_WRONG;
-
 static unsigned long *pc_array = NULL;
 static char *base_folder;
 static DFN_Stack *dfn_stack = NULL;
@@ -226,10 +223,10 @@ dfn (Sym *parent)
    Mimimc a stack trace using a DF algorithm.  */
 
 static int
-cg_traverse_arcs (void)
+cg_traverse_arcs (const char *whoami)
 {
   Sym *sym;
-  Sym_Table *symtab = get_symtab ();
+  Sym_Table *symtab = get_symtab (whoami);
 
   for (sym = symtab->base; sym < symtab->limit; sym++)
     {
@@ -451,6 +448,7 @@ gen_gmon_log (void)
 
   logx = fopen (new_file_path, "w");
 
+  long hz = hist_get_hz ();
   int gmon_interval = (hz == HZ_WRONG ? 1000 : hz * 100);
 
   fprintf (logx, "<profile name=\"%s\" ptimer=\"%d\" numstates=\"%d\">\n",
@@ -658,20 +656,20 @@ er_gmon::start (int argc, char *argv[])
     }
 
   /* Read the elf syms and the gmon file.  */
-  if (core_init (a_out_name) < 0)
+  if (core_init (a_out_name, whoami) < 0)
     {
       cc->remove_exp_dir ();
       exit (1);
     }
-  if (gmon_out_read (gmon_name, FF_AUTO) < 0)
+  if (gmon_out_read (gmon_name, FF_AUTO, whoami) < 0)
     {
       cc->remove_exp_dir ();
       exit (1);
     }
 
   /* Process the gmon file, and output the gprofng project files.  */
-  hist_assign_samples ();
-  cg_traverse_arcs ();
+  hist_assign_samples (whoami);
+  cg_traverse_arcs (whoami);
   gen_gmon_map (a_out_name);
   gen_gmon_log ();
 }
index bb8697caba4c51725b6438d81c2edcd3727ba7ae..d4231987c7c86036f347e86c8eeb1470a7c42bad 100644 (file)
@@ -18,5 +18,4 @@
 #define MAX(a,b)        ((a) > (b) ? (a) : (b))
 #endif
 
-extern const char *whoami;
 #endif /* gp_gmon_h */
index 8844388d9cf41bf752291dd96d09afae58055762..22fc56c5817907a1aef59e0f493fd96db8e9f80d 100644 (file)
@@ -30,9 +30,8 @@ typedef struct histogram
   int *sample;           /* Histogram samples (shorts in the file!).  */
 } histogram;
 
-extern long hz;
-
-extern void hist_read_rec        (FILE *, const char *);
-extern void hist_assign_samples  (void);
+extern void hist_read_rec        (FILE *, const char *, const char *);
+extern void hist_assign_samples  (const char *);
+extern long hist_get_hz  (void);
 
 #endif /* hist_h */
index f7b612da5db790d354cacfeeea48c23db190906b..9f7a8dd69a3a100dfa9aac70b1f07179e5f25ae7 100644 (file)
@@ -112,7 +112,7 @@ typedef struct
   }
 Sym_Table;
 
-extern Sym_Table *get_symtab (void);
+extern Sym_Table *get_symtab (const char *);
 extern Sym_Table *get_symtab_direct (void);
 
 extern void sym_init        (Sym *);