public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: PR other/16394: Pass --demangle to ld
@ 2004-07-07  0:04 H. J. Lu
  2004-07-07 15:32 ` Mark Mitchell
  0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2004-07-07  0:04 UTC (permalink / raw)
  To: gcc-patches

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

--demangle was added to ld before 2.10. This patch checks if the
linker supports --demangle and uses it if it is available.


H.J.

[-- Attachment #2: gcc-3.4-collect2-1.patch --]
[-- Type: text/plain, Size: 3025 bytes --]

2004-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	* collect2.c (dump_file): Don't call cplus_demangle if
	HAVE_LD_DEMANGLE is defined.
	(main): Pass "--demangle" to ld if no_demangle is not 0 and
	HAVE_LD_DEMANGLE is defined.

	* configure.ac (HAVE_LD_DEMANGLE): Define if ld supports
	--demangle.
	* config.in: Regenerated.
	* configure: Likewise.

--- gcc/collect2.c.demangle	2004-03-09 08:08:49.000000000 -0800
+++ gcc/collect2.c	2004-07-06 16:33:47.267264183 -0700
@@ -492,10 +492,14 @@ dump_file (const char *name)
 	  if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
 	    p += strlen (USER_LABEL_PREFIX);
 
+#ifdef HAVE_LD_DEMANGLE
+	  result = 0;
+#else
 	  if (no_demangle)
 	    result = 0;
 	  else
 	    result = cplus_demangle (p, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
+#endif
 
 	  if (result)
 	    {
@@ -842,8 +846,8 @@ main (int argc, char **argv)
   /* Do not invoke xcalloc before this point, since locale needs to be
      set first, in case a diagnostic is issued.  */
 
-  ld1 = (const char **)(ld1_argv = xcalloc(sizeof (char *), argc+3));
-  ld2 = (const char **)(ld2_argv = xcalloc(sizeof (char *), argc+10));
+  ld1 = (const char **)(ld1_argv = xcalloc(sizeof (char *), argc+4));
+  ld2 = (const char **)(ld2_argv = xcalloc(sizeof (char *), argc+11));
   object = (const char **)(object_lst = xcalloc(sizeof (char *), argc));
 
 #ifdef DEBUG
@@ -1064,6 +1068,10 @@ main (int argc, char **argv)
   /* After the first file, put in the c++ rt0.  */
 
   first_file = 1;
+#ifdef HAVE_LD_DEMANGLE
+  if (!no_demangle)
+    *ld1++ = *ld2++ = "--demangle";
+#endif
   while ((arg = *++argv) != (char *) 0)
     {
       *ld1++ = *ld2++ = arg;
--- gcc/config.in.demangle	2004-07-06 16:35:02.014610529 -0700
+++ gcc/config.in	2004-07-06 16:34:19.449107883 -0700
@@ -312,6 +312,9 @@
 /* Define if your linker supports --as-needed and --no-as-needed options. */
 #undef HAVE_LD_AS_NEEDED
 
+/* Define if your linker supports --demangle option. */
+#undef HAVE_LD_DEMANGLE
+
 /* Define if your linker supports --eh-frame-hdr option. */
 #undef HAVE_LD_EH_FRAME_HDR
 
--- gcc/configure.ac.demangle	2004-06-26 21:36:03.000000000 -0700
+++ gcc/configure.ac	2004-07-06 16:31:01.135720000 -0700
@@ -2656,6 +2656,24 @@ if test x"$gcc_cv_ld_pie" = xyes; then
 fi
 AC_MSG_RESULT($gcc_cv_ld_pie)
 
+AC_MSG_CHECKING(linker --demangle support)
+gcc_cv_ld_demangle=no
+if test $in_tree_ld = yes ; then
+  if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 10 -o "$gcc_cv_gld_major_version" -gt 2; then \
+    gcc_cv_ld_demangle=yes
+  fi
+elif test x$gcc_cv_ld != x; then
+	# Check if linker supports --demangle option
+	if $gcc_cv_ld --help 2>/dev/null | grep no-demangle > /dev/null; then
+		gcc_cv_ld_demangle=yes
+	fi
+fi
+if test x"$gcc_cv_ld_demangle" = xyes; then
+	AC_DEFINE(HAVE_LD_DEMANGLE, 1,
+[Define if your linker supports --demangle option.])
+fi
+AC_MSG_RESULT($gcc_cv_ld_demangle)
+
 case "$target" in
   *-*-linux*)
     AC_CACHE_CHECK(linker --as-needed support,

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH: PR other/16394: Pass --demangle to ld
  2004-07-07  0:04 PATCH: PR other/16394: Pass --demangle to ld H. J. Lu
@ 2004-07-07 15:32 ` Mark Mitchell
  2004-07-07 17:13   ` H. J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Mitchell @ 2004-07-07 15:32 UTC (permalink / raw)
  To: H. J. Lu; +Cc: gcc-patches

H. J. Lu wrote:

> --demangle was added to ld before 2.10. This patch checks if the
> linker supports --demangle and uses it if it is available.

I think you should probably check that "ld" is GNU ld, in addition to 
checking that it supports --demangle.  Some linkers might support 
--demangle, but use a different mangling scheme.

There's also the issue that cplus_demangle will be more likely to match 
the compiler's mangling than "ld --demangle" which might be out of date.

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH: PR other/16394: Pass --demangle to ld
  2004-07-07 15:32 ` Mark Mitchell
@ 2004-07-07 17:13   ` H. J. Lu
  2004-07-07 18:06     ` Jason Merrill
  0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2004-07-07 17:13 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: gcc-patches

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

On Wed, Jul 07, 2004 at 07:55:11AM -0700, Mark Mitchell wrote:
> H. J. Lu wrote:
> 
> >--demangle was added to ld before 2.10. This patch checks if the
> >linker supports --demangle and uses it if it is available.
> 
> I think you should probably check that "ld" is GNU ld, in addition to 
> checking that it supports --demangle.  Some linkers might support 
> --demangle, but use a different mangling scheme.
> 
> There's also the issue that cplus_demangle will be more likely to match 
> the compiler's mangling than "ld --demangle" which might be out of date.
> 

I added the check for GNU ld and the --with-demangler-in-ld option
default to no.


H.J.

[-- Attachment #2: gcc-3.4-collect2-2.patch --]
[-- Type: text/plain, Size: 3892 bytes --]

2004-07-07  H.J. Lu  <hongjiu.lu@intel.com>

	* collect2.c (dump_file): Don't call cplus_demangle if
	HAVE_LD_DEMANGLE is defined.
	(main): Pass "--demangle" to ld if no_demangle is not 0 and
	HAVE_LD_DEMANGLE is defined. Don't set current_demangling_style
	if HAVE_LD_DEMANGLE is defined.

	* configure.ac (--with-demangler-in-ld): Added
	(HAVE_LD_DEMANGLE): Define if ld supports --demangle when
	--with-demangler-in-ld is used.
	* config.in: Regenerated.
	* configure: Likewise.

--- gcc/collect2.c.collect2	2004-03-09 08:08:49.000000000 -0800
+++ gcc/collect2.c	2004-07-07 08:37:52.230586761 -0700
@@ -492,10 +492,14 @@ dump_file (const char *name)
 	  if (!strncmp (p, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)))
 	    p += strlen (USER_LABEL_PREFIX);
 
+#ifdef HAVE_LD_DEMANGLE
+	  result = 0;
+#else
 	  if (no_demangle)
 	    result = 0;
 	  else
 	    result = cplus_demangle (p, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
+#endif
 
 	  if (result)
 	    {
@@ -842,8 +846,8 @@ main (int argc, char **argv)
   /* Do not invoke xcalloc before this point, since locale needs to be
      set first, in case a diagnostic is issued.  */
 
-  ld1 = (const char **)(ld1_argv = xcalloc(sizeof (char *), argc+3));
-  ld2 = (const char **)(ld2_argv = xcalloc(sizeof (char *), argc+10));
+  ld1 = (const char **)(ld1_argv = xcalloc(sizeof (char *), argc+4));
+  ld2 = (const char **)(ld2_argv = xcalloc(sizeof (char *), argc+11));
   object = (const char **)(object_lst = xcalloc(sizeof (char *), argc));
 
 #ifdef DEBUG
@@ -874,7 +878,9 @@ main (int argc, char **argv)
   obstack_begin (&temporary_obstack, 0);
   temporary_firstobj = obstack_alloc (&temporary_obstack, 0);
 
+#ifndef HAVE_LD_DEMANGLE
   current_demangling_style = auto_demangling;
+#endif
   p = getenv ("COLLECT_GCC_OPTIONS");
   while (p && *p)
     {
@@ -1064,6 +1070,10 @@ main (int argc, char **argv)
   /* After the first file, put in the c++ rt0.  */
 
   first_file = 1;
+#ifdef HAVE_LD_DEMANGLE
+  if (!no_demangle)
+    *ld1++ = *ld2++ = "--demangle";
+#endif
   while ((arg = *++argv) != (char *) 0)
     {
       *ld1++ = *ld2++ = arg;
--- gcc/config.in.collect2	2004-07-07 08:37:51.752648683 -0700
+++ gcc/config.in	2004-07-07 08:37:52.232586501 -0700
@@ -312,6 +312,9 @@
 /* Define if your linker supports --as-needed and --no-as-needed options. */
 #undef HAVE_LD_AS_NEEDED
 
+/* Define if your linker supports --demangle option. */
+#undef HAVE_LD_DEMANGLE
+
 /* Define if your linker supports --eh-frame-hdr option. */
 #undef HAVE_LD_EH_FRAME_HDR
 
--- gcc/configure.ac.collect2	2004-07-07 08:37:52.065608136 -0700
+++ gcc/configure.ac	2004-07-07 09:17:06.137609401 -0700
@@ -211,6 +211,12 @@ else
   AC_MSG_RESULT(no)
 fi
 
+# With demangler in GNU ld
+AC_ARG_WITH(demangler-in-ld,
+[  --with-demangler-in-ld  try to use demangler in GNU ld.],
+demangler_in_ld="$with_demangler_in_ld",
+demangler_in_ld=no)
+
 # ----------------------
 # Find default assembler
 # ----------------------
@@ -2656,6 +2662,26 @@ if test x"$gcc_cv_ld_pie" = xyes; then
 fi
 AC_MSG_RESULT($gcc_cv_ld_pie)
 
+if test x"$demangler_in_ld" = xyes; then
+  AC_MSG_CHECKING(linker --demangle support)
+  gcc_cv_ld_demangle=no
+  if test $in_tree_ld = yes; then
+    if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 14 -o "$gcc_cv_gld_major_version" -gt 2; then \
+      gcc_cv_ld_demangle=yes
+    fi
+  elif test x$gcc_cv_ld != x -a x"$gnu_ld" = xyes; then
+    # Check if the GNU linker supports --demangle option
+    if $gcc_cv_ld --help 2>/dev/null | grep no-demangle > /dev/null; then
+      gcc_cv_ld_demangle=yes
+    fi
+  fi
+  if test x"$gcc_cv_ld_demangle" = xyes; then
+    AC_DEFINE(HAVE_LD_DEMANGLE, 1,
+[Define if your linker supports --demangle option.])
+  fi
+  AC_MSG_RESULT($gcc_cv_ld_demangle)
+fi
+
 case "$target" in
   *-*-linux*)
     AC_CACHE_CHECK(linker --as-needed support,

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH: PR other/16394: Pass --demangle to ld
  2004-07-07 17:13   ` H. J. Lu
@ 2004-07-07 18:06     ` Jason Merrill
  2004-07-07 18:56       ` H. J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2004-07-07 18:06 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Mark Mitchell, gcc-patches

On Wed, 7 Jul 2004 09:30:20 -0700, "H. J. Lu" <hjl@lucon.org> wrote:

> On Wed, Jul 07, 2004 at 07:55:11AM -0700, Mark Mitchell wrote:
>> H. J. Lu wrote:
>> 
>> >--demangle was added to ld before 2.10. This patch checks if the
>> >linker supports --demangle and uses it if it is available.
>> 
>> I think you should probably check that "ld" is GNU ld, in addition to 
>> checking that it supports --demangle.  Some linkers might support 
>> --demangle, but use a different mangling scheme.
>> 
>> There's also the issue that cplus_demangle will be more likely to match 
>> the compiler's mangling than "ld --demangle" which might be out of date.
>
> I added the check for GNU ld and the --with-demangler-in-ld option
> default to no.

What about Mark's point that cplus_demangle is more likely to be correct?
What problem are you trying to solve with this patch?

Jason

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH: PR other/16394: Pass --demangle to ld
  2004-07-07 18:06     ` Jason Merrill
@ 2004-07-07 18:56       ` H. J. Lu
  2004-07-07 19:14         ` Jason Merrill
  0 siblings, 1 reply; 7+ messages in thread
From: H. J. Lu @ 2004-07-07 18:56 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Mark Mitchell, gcc-patches

On Wed, Jul 07, 2004 at 01:51:58PM -0400, Jason Merrill wrote:
> On Wed, 7 Jul 2004 09:30:20 -0700, "H. J. Lu" <hjl@lucon.org> wrote:
> 
> > On Wed, Jul 07, 2004 at 07:55:11AM -0700, Mark Mitchell wrote:
> >> H. J. Lu wrote:
> >> 
> >> >--demangle was added to ld before 2.10. This patch checks if the
> >> >linker supports --demangle and uses it if it is available.
> >> 
> >> I think you should probably check that "ld" is GNU ld, in addition to 
> >> checking that it supports --demangle.  Some linkers might support 
> >> --demangle, but use a different mangling scheme.
> >> 
> >> There's also the issue that cplus_demangle will be more likely to match 
> >> the compiler's mangling than "ld --demangle" which might be out of date.
> >
> > I added the check for GNU ld and the --with-demangler-in-ld option
> > default to no.
> 
> What about Mark's point that cplus_demangle is more likely to be correct?

You won't get it unless you pass --with-demangler-in-ld to configure.
Then you can either upgrade your binutils or live with it. In my case, 
binutils has the correct cplus_demangle for gcc on my machine.

> What problem are you trying to solve with this patch?
> 

It is in PR other/16394. Basically, collect2 tries to demangle more
than just symbol names.


H.J.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH: PR other/16394: Pass --demangle to ld
  2004-07-07 18:56       ` H. J. Lu
@ 2004-07-07 19:14         ` Jason Merrill
  2004-07-07 20:31           ` Mark Mitchell
  0 siblings, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2004-07-07 19:14 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Mark Mitchell, gcc-patches

On Wed, 7 Jul 2004 11:22:29 -0700, "H. J. Lu" <hjl@lucon.org> wrote:

> On Wed, Jul 07, 2004 at 01:51:58PM -0400, Jason Merrill wrote:

>> What about Mark's point that cplus_demangle is more likely to be correct?
>
> You won't get it unless you pass --with-demangler-in-ld to configure.
> Then you can either upgrade your binutils or live with it. In my case, 
> binutils has the correct cplus_demangle for gcc on my machine.

I suppose that's fair; that way it's controlled by the packager.

Jason

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: PATCH: PR other/16394: Pass --demangle to ld
  2004-07-07 19:14         ` Jason Merrill
@ 2004-07-07 20:31           ` Mark Mitchell
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Mitchell @ 2004-07-07 20:31 UTC (permalink / raw)
  To: Jason Merrill; +Cc: H. J. Lu, gcc-patches

Jason Merrill wrote:

>On Wed, 7 Jul 2004 11:22:29 -0700, "H. J. Lu" <hjl@lucon.org> wrote:
>
>  
>
>>On Wed, Jul 07, 2004 at 01:51:58PM -0400, Jason Merrill wrote:
>>    
>>
>
>  
>
>>>What about Mark's point that cplus_demangle is more likely to be correct?
>>>      
>>>
>>You won't get it unless you pass --with-demangler-in-ld to configure.
>>Then you can either upgrade your binutils or live with it. In my case, 
>>binutils has the correct cplus_demangle for gcc on my machine.
>>    
>>
>
>I suppose that's fair; that way it's controlled by the packager.
>  
>
Yes, I think the new version is OK.  Since Jason seems content, I'll 
approve it.

-- 
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-07-07 20:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-07  0:04 PATCH: PR other/16394: Pass --demangle to ld H. J. Lu
2004-07-07 15:32 ` Mark Mitchell
2004-07-07 17:13   ` H. J. Lu
2004-07-07 18:06     ` Jason Merrill
2004-07-07 18:56       ` H. J. Lu
2004-07-07 19:14         ` Jason Merrill
2004-07-07 20:31           ` Mark Mitchell

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).