This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to improve ld --print-map output


I can't help think I've missed something here.  But anyway...

While working another problem, and trying to use --print-map to
debug it, I noticed that the current location column was often
misleading.  For example,

    SECTIONS
    {
      . = 0x10001;
      foo = .;
      . += 0x200;
      bar = .;
      . = ALIGN (4);
      frob = .;
    }

gives (x86):

                0x00010001                . = 0x10001
                0x00000000                foo = .
                0x00000200                . = (. + 0x200)
                0x00000000                bar = .
                0x00000000                . =  ALIGN (0x4)
                0x00000000                frob = .

The problem seems to be that print_statement doesn't update
the current location when the destination is ".".  The patch
fixes that.  It also gets rid of the double spaces (. =  ALIGN).

New output is:

                0x00010001                . = 0x10001
                0x00010001                foo = .
                0x00010201                . = (. + 0x200)
                0x00010201                bar = .
                0x00010204                . = ALIGN (0x4)
                0x00010204                frob = .

Tested on i686-pc-linux-gnu & mips64-elf, no regressions.

OK to install?

[ld/]
	* ldlang.c (print_assignment): Update print_dot for assignments to ".".
	* ldexp.c (exp_print_token): Add "infix_p" argument.
	(exp_print_tree): Update accordingly.

[ld/testsuite/]
	* ld-scripts/map-address.exp: New test.
	* ld-scripts/map-address.[td]: New files for it.

Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.80
diff -c -p -d -r1.80 ldlang.c
*** ldlang.c	8 Apr 2002 01:01:43 -0000	1.80
--- ldlang.c	29 Apr 2002 15:51:09 -0000
*************** print_assignment (assignment, output_sec
*** 2211,2217 ****
    result = exp_fold_tree (assignment->exp->assign.src, output_section,
  			  lang_final_phase_enum, print_dot, &print_dot);
    if (result.valid_p)
!     minfo ("0x%V", result.value + result.section->bfd_section->vma);
    else
      {
        minfo ("*undef*   ");
--- 2211,2227 ----
    result = exp_fold_tree (assignment->exp->assign.src, output_section,
  			  lang_final_phase_enum, print_dot, &print_dot);
    if (result.valid_p)
!     {
!       const char *dst;
!       bfd_vma value;
! 
!       value = result.value + result.section->bfd_section->vma;
!       dst = assignment->exp->assign.dst;
! 
!       minfo ("0x%V", value);
!       if (dst[0] == '.' && dst[1] == 0)
! 	print_dot = value;
!     }
    else
      {
        minfo ("*undef*   ");
Index: ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.13
diff -c -p -d -r1.13 ldexp.c
*** ldexp.c	3 Apr 2002 10:25:41 -0000	1.13
--- ldexp.c	29 Apr 2002 15:51:09 -0000
*************** Software Foundation, 59 Temple Place - S
*** 41,47 ****
  #include "libiberty.h"
  #include "safe-ctype.h"
  
! static void exp_print_token PARAMS ((token_code_type code));
  static void make_abs PARAMS ((etree_value_type *ptr));
  static etree_value_type new_abs PARAMS ((bfd_vma value));
  static void check PARAMS ((lang_output_section_statement_type *os,
--- 41,47 ----
  #include "libiberty.h"
  #include "safe-ctype.h"
  
! static void exp_print_token PARAMS ((token_code_type code, int infix_p));
  static void make_abs PARAMS ((etree_value_type *ptr));
  static etree_value_type new_abs PARAMS ((bfd_vma value));
  static void check PARAMS ((lang_output_section_statement_type *os,
*************** static etree_value_type exp_fold_tree_no
*** 67,75 ****
  
  struct exp_data_seg exp_data_seg;
  
  static void
! exp_print_token (code)
       token_code_type code;
  {
    static CONST struct
    {
--- 67,79 ----
  
  struct exp_data_seg exp_data_seg;
  
+ /* Print the string representation of the given token.  Surround it
+    with spaces if INFIX_P is true.  */
+ 
  static void
! exp_print_token (code, infix_p)
       token_code_type code;
+      int infix_p;
  {
    static CONST struct
    {
*************** exp_print_token (code)
*** 122,141 ****
    };
    unsigned int idx;
  
!   for (idx = ARRAY_SIZE (table); idx--;)
!     {
!       if (table[idx].code == code)
! 	{
! 	  fprintf (config.map_file, " %s ", table[idx].name);
! 	  return;
! 	}
!     }
  
!   /* Not in table, just print it alone.  */
!   if (code < 127)
!     fprintf (config.map_file, " %c ", code);
    else
!     fprintf (config.map_file, " <code %d> ", code);
  }
  
  static void
--- 126,147 ----
    };
    unsigned int idx;
  
!   for (idx = 0; idx < ARRAY_SIZE (table); idx++)
!     if (table[idx].code == code)
!       break;
  
!   if (infix_p)
!     fputc (' ', config.map_file);
! 
!   if (idx < ARRAY_SIZE (table))
!     fputs (table[idx].name, config.map_file);
!   else if (code < 127)
!     fputc (code, config.map_file);
    else
!     fprintf (config.map_file, "<code %d>", code);
! 
!   if (infix_p)
!     fputc (' ', config.map_file);
  }
  
  static void
*************** exp_print_tree (tree)
*** 955,961 ****
  	fprintf (config.map_file, "%s (UNDEFINED)", tree->assign.dst->name);
  #endif
        fprintf (config.map_file, "%s", tree->assign.dst);
!       exp_print_token (tree->type.node_code);
        exp_print_tree (tree->assign.src);
        break;
      case etree_provide:
--- 961,967 ----
  	fprintf (config.map_file, "%s (UNDEFINED)", tree->assign.dst->name);
  #endif
        fprintf (config.map_file, "%s", tree->assign.dst);
!       exp_print_token (tree->type.node_code, true);
        exp_print_tree (tree->assign.src);
        break;
      case etree_provide:
*************** exp_print_tree (tree)
*** 967,973 ****
      case etree_binary:
        fprintf (config.map_file, "(");
        exp_print_tree (tree->binary.lhs);
!       exp_print_token (tree->type.node_code);
        exp_print_tree (tree->binary.rhs);
        fprintf (config.map_file, ")");
        break;
--- 973,979 ----
      case etree_binary:
        fprintf (config.map_file, "(");
        exp_print_tree (tree->binary.lhs);
!       exp_print_token (tree->type.node_code, true);
        exp_print_tree (tree->binary.rhs);
        fprintf (config.map_file, ")");
        break;
*************** exp_print_tree (tree)
*** 979,988 ****
        exp_print_tree (tree->trinary.rhs);
        break;
      case etree_unary:
!       exp_print_token (tree->unary.type.node_code);
        if (tree->unary.child)
  	{
! 	  fprintf (config.map_file, "(");
  	  exp_print_tree (tree->unary.child);
  	  fprintf (config.map_file, ")");
  	}
--- 985,994 ----
        exp_print_tree (tree->trinary.rhs);
        break;
      case etree_unary:
!       exp_print_token (tree->unary.type.node_code, false);
        if (tree->unary.child)
  	{
! 	  fprintf (config.map_file, " (");
  	  exp_print_tree (tree->unary.child);
  	  fprintf (config.map_file, ")");
  	}
*************** exp_print_tree (tree)
*** 1004,1012 ****
  	}
        else
  	{
! 	  exp_print_token (tree->type.node_code);
  	  if (tree->name.name)
! 	    fprintf (config.map_file, "(%s)", tree->name.name);
  	}
        break;
      default:
--- 1010,1018 ----
  	}
        else
  	{
! 	  exp_print_token (tree->type.node_code, false);
  	  if (tree->name.name)
! 	    fprintf (config.map_file, " (%s)", tree->name.name);
  	}
        break;
      default:
*** /dev/null	Tue Nov 14 21:44:43 2000
--- testsuite/ld-scripts/map-address.d	Mon Apr 29 16:50:50 2002
***************
*** 0 ****
--- 1,10 ----
+ #...
+ Linker script and memory map
+ 
+  *0x0*010001 *\. = 0x10001
+  *0x0*010001 *foo = \.
+  *0x0*010201 *\. = \(.+0x200\)
+  *0x0*010201 *bar = \.
+  *0x0*010204 *\. = ALIGN \(0x4\)
+  *0x0*010204 *frob = \.
+ #pass
*** /dev/null	Tue Nov 14 21:44:43 2000
--- testsuite/ld-scripts/map-address.exp	Mon Apr 29 16:29:27 2002
***************
*** 0 ****
--- 1,37 ----
+ # Test address printed by --print-map
+ # Copyright 2002 Free Software Foundation, Inc.
+ #
+ # This file is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ # 
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ # GNU General Public License for more details.
+ # 
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ 
+ set testname "map addresses"
+ 
+ # The source file doesn't matter.  Pinch one from the sizeof test.
+ if ![ld_assemble $as $srcdir/$subdir/sizeof.s tmpdir/map-address.o] {
+     unresolved $testname
+     return
+ }
+ 
+ if ![ld_simple_link $ld tmpdir/map-address \
+ 	 "-T $srcdir/$subdir/map-address.t \
+ 	  tmpdir/map-address.o \
+ 	  -Map tmpdir/map-address.map"] {
+     fail $testname
+ } elseif [regexp_diff \
+ 	    "tmpdir/map-address.map" \
+ 	    "$srcdir/$subdir/map-address.d"] {
+     fail $testname
+ } else {
+     pass $testname
+ }
*** /dev/null	Tue Nov 14 21:44:43 2000
--- testsuite/ld-scripts/map-address.t	Mon Apr 29 16:14:16 2002
***************
*** 0 ****
--- 1,9 ----
+ SECTIONS
+ {
+   . = 0x10001;
+   foo = .;
+   . += 0x200;
+   bar = .;
+   . = ALIGN (4);
+   frob = .;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]