Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: [rfa:ppc64] Get descriptor FN from the same object file as symbol ".FN"
Date: Fri, 14 Nov 2003 00:25:00 -0000	[thread overview]
Message-ID: <3FB420DB.6030809@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 488 bytes --]

Hello,

The attached tweaks the tail end of the ppc64_sysv_abi_push_dummy_call 
code so that it restricts the search for the descriptor FN (that 
corresponds to function ".FN") to the object file that contains ".FN". 
Given shared libraries, several object files can contain the same symbol 
so searching for an unqualified "FN" can end up finding the descriptor 
in the wrong shared library :-(.  This problem occures when trying to go 
backwards from ".malloc" to "malloc".

ok?
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 3015 bytes --]

2003-11-13  Andrew Cagney  <cagney@redhat.com>

	* Makefile.in (ppc-sysv-tdep.o): Update dependencies.
	* ppc-sysv-tdep.c: Include "objfiles.h".
	(ppc64_sysv_abi_push_dummy_call): Provide the
	the FN's objfile when looking for the descriptor.

Index: ppc-sysv-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/ppc-sysv-tdep.c,v
retrieving revision 1.20
diff -u -r1.20 ppc-sysv-tdep.c
--- ppc-sysv-tdep.c	10 Nov 2003 22:47:28 -0000	1.20
+++ ppc-sysv-tdep.c	14 Nov 2003 00:11:37 -0000
@@ -29,6 +29,7 @@
 #include "gdb_assert.h"
 #include "ppc-tdep.h"
 #include "target.h"
+#include "objfiles.h"
 
 /* Pass the arguments in either registers, or in the stack. Using the
    ppc sysv ABI, the first eight words of the argument list (that might
@@ -790,27 +791,38 @@
      ".FN" and "FN" in the minimal symbol table.  "FN" points at the
      FN's descriptor, while ".FN" points at the entry point (which
      matches FUNC_ADDR).  Need to reverse from FUNC_ADDR back to the
-     FN's descriptor address.  */
+     FN's descriptor address (while at the same time being careful to
+     find "FN" in the same object file as ".FN").  */
   {
     /* Find the minimal symbol that corresponds to FUNC_ADDR (should
        have the name ".FN").  */
     struct minimal_symbol *dot_fn = lookup_minimal_symbol_by_pc (func_addr);
     if (dot_fn != NULL && SYMBOL_LINKAGE_NAME (dot_fn)[0] == '.')
       {
-	/* Now find the corresponding "FN" (dropping ".") minimal
-	   symbol's address.  */
-	struct minimal_symbol *fn =
-	  lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
-				 NULL);
-	if (fn != NULL)
+	/* Get the section that contains FUNC_ADR.  Need this for the
+           "objfile" that it contains.  */
+	struct obj_section *dot_fn_section = find_pc_section (func_addr);
+	if (dot_fn_section != NULL && dot_fn_section->objfile != NULL)
 	  {
-	    /* Got the address of that descriptor.  The TOC is the
-	       second double word.  */
-	    CORE_ADDR toc =
-	      read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn) +
-					    tdep->wordsize, tdep->wordsize);
-	    regcache_cooked_write_unsigned (regcache,
-					    tdep->ppc_gp0_regnum + 2, toc);
+	    /* Now find the corresponding "FN" (dropping ".") minimal
+	       symbol's address.  Only look for the minimal symbol in
+	       ".FN"'s object file - avoids problems when two object
+	       files (i.e., shared libraries) contain a minimal symbol
+	       with the same name.  */
+	    struct minimal_symbol *fn =
+	      lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
+				     dot_fn_section->objfile);
+	    if (fn != NULL)
+	      {
+		/* Got the address of that descriptor.  The TOC is the
+		   second double word.  */
+		CORE_ADDR toc =
+		  read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn)
+						+ tdep->wordsize,
+						tdep->wordsize);
+		regcache_cooked_write_unsigned (regcache,
+						tdep->ppc_gp0_regnum + 2, toc);
+	      }
 	  }
       }
   }

             reply	other threads:[~2003-11-14  0:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-14  0:25 Andrew Cagney [this message]
2003-11-14  1:15 ` Kevin Buettner
2003-11-14 14:35   ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FB420DB.6030809@redhat.com \
    --to=ac131313@redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox