[PATCH 1/6] gprof: remove ASCII formfeed/0x0C bytes from source code
Alan Modra
amodra@gmail.com
Mon Feb 24 10:02:06 GMT 2025
The patch series looks OK to me, except for a few things:
- Lines with a formfeed should be replaced with a blank line
- There are more occurrences of min_vma and max_vma that could be
removed.
- insn_boundary is a better name than gcd_insn_size.
- Formatting errors.
- You remove some unnecessary xrealloc casts, I've extended that to
more places.
See below for the diff. I've made the changes to each of your patches
already, so no need to repost if you're happy with this.
--
Alan Modra
diff -urp -x autom4te.cache gprof/basic_blocks.c ../binutils-gdb/gprof/basic_blocks.c
--- gprof/basic_blocks.c 2025-02-24 19:38:17.107527925 +1030
+++ ../binutils-gdb/gprof/basic_blocks.c 2025-02-24 19:37:53.963778828 +1030
@@ -20,6 +20,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "filenames.h"
diff -urp -x autom4te.cache gprof/basic_blocks.h ../binutils-gdb/gprof/basic_blocks.h
--- gprof/basic_blocks.h 2025-02-24 19:38:17.107527925 +1030
+++ ../binutils-gdb/gprof/basic_blocks.h 2025-02-24 19:37:53.963778828 +1030
@@ -17,6 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef basic_blocks_h
#define basic_blocks_h
diff -urp -x autom4te.cache gprof/bb_exit_func.c ../binutils-gdb/gprof/bb_exit_func.c
--- gprof/bb_exit_func.c 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/bb_exit_func.c 2025-02-24 19:37:53.963778828 +1030
@@ -23,6 +23,7 @@
This code was contributed by:
David Mosberger-Tang <David.Mosberger@acm.org> */
+
#include <stdio.h>
#include <strings.h>
#include "bfd.h"
diff -urp -x autom4te.cache gprof/call_graph.c ../binutils-gdb/gprof/call_graph.c
--- gprof/call_graph.c 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/call_graph.c 2025-02-24 19:37:53.963778828 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "search_list.h"
#include "source.h"
diff -urp -x autom4te.cache gprof/call_graph.h ../binutils-gdb/gprof/call_graph.h
--- gprof/call_graph.h 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/call_graph.h 2025-02-24 19:37:53.963778828 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef call_graph_h
#define call_graph_h
diff -urp -x autom4te.cache gprof/cg_arcs.h ../binutils-gdb/gprof/cg_arcs.h
--- gprof/cg_arcs.h 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/cg_arcs.h 2025-02-24 19:37:53.964778861 +1030
@@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef cg_arcs_h
#define cg_arcs_h
diff -urp -x autom4te.cache gprof/cg_dfn.h ../binutils-gdb/gprof/cg_dfn.h
--- gprof/cg_dfn.h 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/cg_dfn.h 2025-02-24 19:37:53.964778861 +1030
@@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef cg_dfn_h
#define cg_dfn_h
diff -urp -x autom4te.cache gprof/cg_print.c ../binutils-gdb/gprof/cg_print.c
--- gprof/cg_print.c 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/cg_print.c 2025-02-24 19:37:53.964778861 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "filenames.h"
diff -urp -x autom4te.cache gprof/cg_print.h ../binutils-gdb/gprof/cg_print.h
--- gprof/cg_print.h 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/cg_print.h 2025-02-24 19:37:53.964778861 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef cg_print_h
#define cg_print_h
diff -urp -x autom4te.cache gprof/corefile.c ../binutils-gdb/gprof/corefile.c
--- gprof/corefile.c 2025-02-24 19:38:17.218531516 +1030
+++ ../binutils-gdb/gprof/corefile.c 2025-02-24 19:43:15.682512637 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "filenames.h"
@@ -35,8 +36,8 @@ static asymbol **core_syms;
asection *core_text_sect;
void * core_text_space;
-/* Greatest Common Divisor of instruction sizes and alignments. */
-static int gcd_insn_size;
+/* Greatest common divisor of instruction sizes and alignments. */
+static int insn_boundary;
int offset_to_code;
/* For mapping symbols to specific .o files during file ordering. */
@@ -245,7 +246,7 @@ core_init (const char * aout_name)
*symp = 0;
}
- gcd_insn_size = 1;
+ insn_boundary = 1;
offset_to_code = 0;
switch (bfd_get_arch (core_bfd))
@@ -258,11 +259,11 @@ core_init (const char * aout_name)
case bfd_arch_powerpc:/* and VLE */
case bfd_arch_riscv:/* and RVC */
case bfd_arch_sh:
- gcd_insn_size = 2;
+ insn_boundary = 2;
break;
case bfd_arch_alpha:
- gcd_insn_size = 4;
+ insn_boundary = 4;
break;
default:
@@ -521,8 +522,6 @@ void
core_create_syms_from (const char * sym_table_file)
{
char type;
- bfd_vma min_vma = ~(bfd_vma) 0;
- bfd_vma max_vma = 0;
FILE * f;
f = fopen (sym_table_file, "r");
@@ -577,8 +576,6 @@ core_create_syms_from (const char * sym_
symtab.limit->is_func = true;
symtab.limit->is_bb_head = true;
symtab.limit->is_static = (type == 't');
- min_vma = MIN (symtab.limit->addr, min_vma);
- max_vma = MAX (symtab.limit->addr, max_vma);
++symtab.limit;
}
@@ -600,8 +597,6 @@ search_mapped_symbol (const void * l, co
void
core_create_function_syms (void)
{
- bfd_vma min_vma = ~ (bfd_vma) 0;
- bfd_vma max_vma = 0;
int cxxclass;
long i;
struct function_map * found = NULL;
@@ -739,17 +734,6 @@ core_create_function_syms (void)
if (cxxclass == 't')
symtab.limit->is_static = true;
- /* Keep track of the minimum and maximum vma addresses used by all
- symbols. When computing the max_vma, use the ending address of the
- section containing the symbol, if available. */
- min_vma = MIN (symtab.limit->addr, min_vma);
- if (sym_sec)
- max_vma = MAX (bfd_section_vma (sym_sec)
- + bfd_section_size (sym_sec) - 1,
- max_vma);
- else
- max_vma = MAX (symtab.limit->addr, max_vma);
-
DBG (AOUTDEBUG, printf ("[core_create_function_syms] %ld %s 0x%lx\n",
(long) (symtab.limit - symtab.base),
symtab.limit->name,
@@ -782,7 +766,7 @@ core_create_line_syms (void)
ltab_reserved = 1024;
ltab.len = 0;
- ltab.base = (Sym *) xmalloc (ltab_reserved * sizeof (Sym));
+ ltab.base = xmalloc (ltab_reserved * sizeof (Sym));
ltab.limit = ltab.base;
/* We now set is_static as we go along, rather than by running
@@ -801,23 +785,23 @@ core_create_line_syms (void)
Perhaps symtab_finalize should be modified to make this
distinction as well, but the current fix works and the code is a
lot cleaner now. */
- memset (&prev, 0, sizeof(prev));
+ memset (&prev, 0, sizeof (prev));
for (size_t i = 0; i < num_histograms; ++i)
{
bfd_vma hist_vma_high = histograms[i].highpc;
- bfd_vma vma_low = MAX(histograms[i].lowpc, bfd_vma_low);
- bfd_vma vma_high = MIN(bfd_vma_high,hist_vma_high);
- for (vma = vma_low; vma < vma_high; vma += gcd_insn_size)
- {
+ bfd_vma vma_low = MAX (histograms[i].lowpc, bfd_vma_low);
+ bfd_vma vma_high = MIN (bfd_vma_high, hist_vma_high);
+ for (vma = vma_low; vma < vma_high; vma += insn_boundary)
+ {
if (ltab.len >= ltab_reserved)
{
- /* Reserve more space for line symbols */
+ /* Reserve more space for line symbols. */
ltab_reserved *= 2;
ltab.base = xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
ltab.limit = ltab.base + ltab.len;
}
- sym_init (ltab.limit);
+ sym_init (ltab.limit);
if (!get_src_info (vma, &filename, <ab.limit->name, <ab.limit->line_num)
|| (prev.name && prev.line_num == ltab.limit->line_num
@@ -832,10 +816,10 @@ core_create_line_syms (void)
ltab.limit->addr = vma;
/* Set is_static based on the enclosing function, using either:
- 1) the previous symbol, if it's from the same function, or
- 2) a symtab lookup. */
- if (prev.name && ltab.limit->file == prev.file &&
- strcmp (ltab.limit->name, prev.name) == 0)
+ 1) the previous symbol, if it's from the same function, or
+ 2) a symtab lookup. */
+ if (prev.name && ltab.limit->file == prev.file
+ && strcmp (ltab.limit->name, prev.name) == 0)
{
ltab.limit->is_static = prev.is_static;
}
@@ -849,17 +833,17 @@ core_create_line_syms (void)
prev = *ltab.limit;
DBG (AOUTDEBUG, printf ("[core_create_line_syms] %lu %s 0x%lx\n",
- (unsigned long) (ltab.limit - ltab.base),
- ltab.limit->name,
- (unsigned long) ltab.limit->addr));
+ (unsigned long) (ltab.limit - ltab.base),
+ ltab.limit->name,
+ (unsigned long) ltab.limit->addr));
++ltab.limit;
++ltab.len;
- }
- }
+ }
+ }
- /* Reserve space for function symbols and/or trim excess space */
+ /* Reserve space for function symbols and/or trim excess space. */
ltab_reserved = ltab.len + symtab.len;
- ltab.base = (Sym *) xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
+ ltab.base = xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
ltab.limit = ltab.base + ltab.len;
/* Copy in function symbols. */
diff -urp -x autom4te.cache gprof/corefile.h ../binutils-gdb/gprof/corefile.h
--- gprof/corefile.h 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/corefile.h 2025-02-24 19:37:53.964778861 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef corefile_h
#define corefile_h
diff -urp -x autom4te.cache gprof/gmon_io.c ../binutils-gdb/gprof/gmon_io.c
--- gprof/gmon_io.c 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/gmon_io.c 2025-02-24 19:37:53.964778861 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "binary-io.h"
#include "search_list.h"
diff -urp -x autom4te.cache gprof/gmon_io.h ../binutils-gdb/gprof/gmon_io.h
--- gprof/gmon_io.h 2025-02-24 19:38:17.108527957 +1030
+++ ../binutils-gdb/gprof/gmon_io.h 2025-02-24 19:37:53.964778861 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef gmon_io_h
#define gmon_io_h
diff -urp -x autom4te.cache gprof/hertz.h ../binutils-gdb/gprof/hertz.h
--- gprof/hertz.h 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/hertz.h 2025-02-24 19:37:53.964778861 +1030
@@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef hertz_h
#define hertz_h
diff -urp -x autom4te.cache gprof/hist.c ../binutils-gdb/gprof/hist.c
--- gprof/hist.c 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/hist.c 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "search_list.h"
diff -urp -x autom4te.cache gprof/hist.h ../binutils-gdb/gprof/hist.h
--- gprof/hist.h 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/hist.h 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef hist_h
#define hist_h
diff -urp -x autom4te.cache gprof/search_list.c ../binutils-gdb/gprof/search_list.c
--- gprof/search_list.c 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/search_list.c 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "search_list.h"
diff -urp -x autom4te.cache gprof/search_list.h ../binutils-gdb/gprof/search_list.h
--- gprof/search_list.h 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/search_list.h 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef search_list_h
#define search_list_h
diff -urp -x autom4te.cache gprof/source.c ../binutils-gdb/gprof/source.c
--- gprof/source.c 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/source.c 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "filenames.h"
diff -urp -x autom4te.cache gprof/source.h ../binutils-gdb/gprof/source.h
--- gprof/source.h 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/source.h 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef source_h
#define source_h
diff -urp -x autom4te.cache gprof/sym_ids.c ../binutils-gdb/gprof/sym_ids.c
--- gprof/sym_ids.c 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/sym_ids.c 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "libiberty.h"
#include "safe-ctype.h"
diff -urp -x autom4te.cache gprof/sym_ids.h ../binutils-gdb/gprof/sym_ids.h
--- gprof/sym_ids.h 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/sym_ids.h 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef sym_ids_h
#define sym_ids_h
diff -urp -x autom4te.cache gprof/symtab.c ../binutils-gdb/gprof/symtab.c
--- gprof/symtab.c 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/symtab.c 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
#include "gprof.h"
#include "search_list.h"
#include "source.h"
diff -urp -x autom4te.cache gprof/symtab.h ../binutils-gdb/gprof/symtab.h
--- gprof/symtab.h 2025-02-24 19:38:17.109527990 +1030
+++ ../binutils-gdb/gprof/symtab.h 2025-02-24 19:37:53.965778893 +1030
@@ -18,6 +18,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef symtab_h
#define symtab_h
diff -urp -x autom4te.cache gprof/utils.h ../binutils-gdb/gprof/utils.h
--- gprof/utils.h 2025-02-24 19:38:17.110528022 +1030
+++ ../binutils-gdb/gprof/utils.h 2025-02-24 19:37:53.965778893 +1030
@@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
+
#ifndef utils_h
#define utils_h
More information about the Binutils
mailing list