public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Re: Error: attempt to get value of unresolved symbol `L0'
@ 2022-10-11 14:29 Nick Clifton
  0 siblings, 0 replies; only message in thread
From: Nick Clifton @ 2022-10-11 14:29 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=12509439a1844a1f1095ac4e9d70b59b539e952c

commit 12509439a1844a1f1095ac4e9d70b59b539e952c
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Oct 11 15:28:10 2022 +0100

    Re: Error: attempt to get value of unresolved symbol `L0'
    
            * symbols.c (S_GET_VALUE): If the unresolved symbol is the fake
            label provide a more helpful error message to the user.
            (S_GET_VALUE_WHERE): Like S_GET_VALUE, but includes a file/line
            number for error reporting purposes.
            * symbols.h (S_GET_VALUE_WHERE): Prototype.
            * write.c (fixup_segment): Use S_GET_VALUE_WHERE.

Diff:
---
 gas/ChangeLog |  4 ++++
 gas/symbols.c | 13 +++++++++++--
 gas/symbols.h |  1 +
 gas/write.c   | 18 ++++++++++--------
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index ce4e78cd92f..0be692c6401 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -2,6 +2,10 @@
 
 	* symbols.c (S_GET_VALUE): If the unresolved symbol is the fake
 	label provide a more helpful error message to the user.
+	(S_GET_VALUE_WHERE): Like S_GET_VALUE, but includes a file/line
+	number for error reporting purposes.
+	* symbols.h (S_GET_VALUE_WHERE): Prototype.
+	* write.c (fixup_segment): Use S_GET_VALUE_WHERE.
 
 2022-09-28  Nick Clifton  <nickc@redhat.com>
 
diff --git a/gas/symbols.c b/gas/symbols.c
index 0aac3a434f2..59358c136c8 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -2217,7 +2217,7 @@ decode_local_label_name (char *s)
 /* Get the value of a symbol.  */
 
 valueT
-S_GET_VALUE (symbolS *s)
+S_GET_VALUE_WHERE (symbolS *s, const char * file, unsigned int line)
 {
   if (s->flags.local_symbol)
     return resolve_symbol_value (s);
@@ -2238,7 +2238,10 @@ S_GET_VALUE (symbolS *s)
 	  || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
 	{
 	  if (strcmp (S_GET_NAME (s), FAKE_LABEL_NAME) == 0)
-	    as_bad (_("expression is too complex to be resolved"));
+	    as_bad_where (file, line, _("expression is too complex to be resolved or converted into relocations"));
+	  else if (file != NULL)
+	    as_bad_where (file, line, _("attempt to get value of unresolved symbol `%s'"),
+			  S_GET_NAME (s));
 	  else
 	    as_bad (_("attempt to get value of unresolved symbol `%s'"),
 		    S_GET_NAME (s));
@@ -2247,6 +2250,12 @@ S_GET_VALUE (symbolS *s)
   return (valueT) s->x->value.X_add_number;
 }
 
+valueT
+S_GET_VALUE (symbolS *s)
+{
+  return S_GET_VALUE_WHERE (s, NULL, 0);
+}
+
 /* Set the value of a symbol.  */
 
 void
diff --git a/gas/symbols.h b/gas/symbols.h
index c33a28ff86b..0282197e41a 100644
--- a/gas/symbols.h
+++ b/gas/symbols.h
@@ -92,6 +92,7 @@ extern void copy_symbol_attributes (symbolS *, symbolS *);
 
 /* Get and set the values of symbols.  These used to be macros.  */
 extern valueT S_GET_VALUE (symbolS *);
+extern valueT S_GET_VALUE_WHERE (symbolS *, const char *, unsigned int);
 extern void S_SET_VALUE (symbolS *, valueT);
 
 extern int S_IS_FUNCTION (symbolS *);
diff --git a/gas/write.c b/gas/write.c
index 30f6c110908..1c1b8104222 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -972,16 +972,18 @@ fixup_segment (fixS *fixP, segT this_segment)
       if (fixP->fx_subsy != NULL)
 	{
 	  segT sub_symbol_segment;
+
 	  resolve_symbol_value (fixP->fx_subsy);
 	  sub_symbol_segment = S_GET_SEGMENT (fixP->fx_subsy);
+
 	  if (fixP->fx_addsy != NULL
 	      && sub_symbol_segment == add_symbol_segment
 	      && !S_FORCE_RELOC (fixP->fx_addsy, 0)
 	      && !S_FORCE_RELOC (fixP->fx_subsy, 0)
 	      && !TC_FORCE_RELOCATION_SUB_SAME (fixP, add_symbol_segment))
 	    {
-	      add_number += S_GET_VALUE (fixP->fx_addsy);
-	      add_number -= S_GET_VALUE (fixP->fx_subsy);
+	      add_number += S_GET_VALUE_WHERE (fixP->fx_addsy, fixP->fx_file, fixP->fx_line);
+	      add_number -= S_GET_VALUE_WHERE (fixP->fx_subsy, fixP->fx_file, fixP->fx_line);
 	      fixP->fx_offset = add_number;
 	      fixP->fx_addsy = NULL;
 	      fixP->fx_subsy = NULL;
@@ -994,7 +996,7 @@ fixup_segment (fixS *fixP, segT this_segment)
 		   && !S_FORCE_RELOC (fixP->fx_subsy, 0)
 		   && !TC_FORCE_RELOCATION_SUB_ABS (fixP, add_symbol_segment))
 	    {
-	      add_number -= S_GET_VALUE (fixP->fx_subsy);
+	      add_number -= S_GET_VALUE_WHERE (fixP->fx_subsy, fixP->fx_file, fixP->fx_line);
 	      fixP->fx_offset = add_number;
 	      fixP->fx_subsy = NULL;
 	    }
@@ -1002,7 +1004,7 @@ fixup_segment (fixS *fixP, segT this_segment)
 		   && !S_FORCE_RELOC (fixP->fx_subsy, 0)
 		   && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP, add_symbol_segment))
 	    {
-	      add_number -= S_GET_VALUE (fixP->fx_subsy);
+	      add_number -= S_GET_VALUE_WHERE (fixP->fx_subsy, fixP->fx_file, fixP->fx_line);
 	      fixP->fx_offset = (add_number + fixP->fx_dot_value
 				 + fixP->fx_dot_frag->fr_address);
 
@@ -1035,7 +1037,7 @@ fixup_segment (fixS *fixP, segT this_segment)
 	  else if (sub_symbol_segment != undefined_section
 		   && ! bfd_is_com_section (sub_symbol_segment)
 		   && MD_APPLY_SYM_VALUE (fixP))
-	    add_number -= S_GET_VALUE (fixP->fx_subsy);
+	    add_number -= S_GET_VALUE_WHERE (fixP->fx_subsy, fixP->fx_file, fixP->fx_line);
 	}
 
       if (fixP->fx_addsy)
@@ -1047,7 +1049,7 @@ fixup_segment (fixS *fixP, segT this_segment)
 	      /* This fixup was made when the symbol's segment was
 		 SEG_UNKNOWN, but it is now in the local segment.
 		 So we know how to do the address without relocation.  */
-	      add_number += S_GET_VALUE (fixP->fx_addsy);
+	      add_number += S_GET_VALUE_WHERE (fixP->fx_addsy, fixP->fx_file, fixP->fx_line);
 	      fixP->fx_offset = add_number;
 	      if (fixP->fx_pcrel)
 		add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment);
@@ -1058,14 +1060,14 @@ fixup_segment (fixS *fixP, segT this_segment)
 		   && !S_FORCE_RELOC (fixP->fx_addsy, 0)
 		   && !TC_FORCE_RELOCATION_ABS (fixP))
 	    {
-	      add_number += S_GET_VALUE (fixP->fx_addsy);
+	      add_number += S_GET_VALUE_WHERE (fixP->fx_addsy, fixP->fx_file, fixP->fx_line);
 	      fixP->fx_offset = add_number;
 	      fixP->fx_addsy = NULL;
 	    }
 	  else if (add_symbol_segment != undefined_section
 		   && ! bfd_is_com_section (add_symbol_segment)
 		   && MD_APPLY_SYM_VALUE (fixP))
-	    add_number += S_GET_VALUE (fixP->fx_addsy);
+	    add_number += S_GET_VALUE_WHERE (fixP->fx_addsy, fixP->fx_file, fixP->fx_line);
 	}
 
       if (fixP->fx_pcrel)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-11 14:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 14:29 [binutils-gdb] Re: Error: attempt to get value of unresolved symbol `L0' Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).