This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Re: C++ demangling patch for win32 dll names


On 14 Aug 1998, Jason Merrill wrote:

> I think it would make more sense to treat _imp__ like _GLOBAL, so you would
> get "import stub for foo(bar)".
> 

How about this?

Regards,
Mumit

===================================================================

Patch priority: uncritical.

With this change, c++filt shows the real demangled name for PE DLL 
imported symbols.

  % echo __imp____7Fooii | c++filt
  import stub for Foo::Foo(int, int)

Fri Aug 14 21:22:15 1998  Mumit Khan  <khan@xraylith.wisc.edu>

	Add support for demangling names imported from a PE DLL.

	* cplus-dem.c (work_stuff): Add dllimported.
	(demangled_prefix): Mark symbols imported from PE DLL.
	(internal_cplus_demangled): Handle.

Index: cplus-dem.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cplus-dem.c,v
retrieving revision 1.25.2.1
diff -u -3 -p -r1.25.2.1 cplus-dem.c
--- cplus-dem.c	1998/07/16 22:41:14	1.25.2.1
+++ cplus-dem.c	1998/08/15 02:22:18
@@ -121,6 +121,7 @@ struct work_stuff
   int static_type;	/* A static member function */
   int const_type;	/* A const member function */
   int volatile_type;    /* A volatile member function */
+  int dllimported;	/* Symbol imported from a PE DLL */
   char **tmpl_argvec;   /* Template function arguments. */
   int ntmpl_args;       /* The number of template function arguments. */
   int forgetting_types; /* Nonzero if we are not remembering the types
@@ -653,6 +654,7 @@ internal_cplus_demangle (work, mangled)
   work->constructor = work->destructor = 0;
   work->static_type = work->const_type = 0;
   work->volatile_type = 0;
+  work->dllimported = 0;
 
   if ((mangled != NULL) && (*mangled != '\0'))
     {
@@ -687,6 +689,11 @@ internal_cplus_demangle (work, mangled)
           string_prepend (&decl, "global destructors keyed to ");
           work->destructor = 0;
         }
+      else if (work->dllimported == 1)
+        {
+          string_prepend (&decl, "import stub for ");
+          work->dllimported = 0;
+        }
       demangled = mop_up (work, &decl, success);
     }
   work->constructor = s1;
@@ -1805,7 +1812,17 @@ demangle_prefix (work, mangled, declp)
   const char *scan;
   int i;
 
-  if (strlen(*mangled) >= 11 && strncmp(*mangled, "_GLOBAL_", 8) == 0)
+  if (strlen(*mangled) > 6
+      && (strncmp(*mangled, "_imp__", 6) == 0 
+          || strncmp(*mangled, "__imp_", 6) == 0))
+    {
+      /* it's a symbol imported from a PE dynamic library. Check for both
+         new style prefix _imp__ and legacy __imp_ used by older versions
+	 of dlltool. */
+      (*mangled) += 6;
+      work->dllimported = 1;
+    }
+  else if (strlen(*mangled) >= 11 && strncmp(*mangled, "_GLOBAL_", 8) == 0)
     {
       char *marker = strchr (cplus_markers, (*mangled)[8]);
       if (marker != NULL && *marker == (*mangled)[10])



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