Bug 208661

Summary: [libelf] __cxa_demangle incorrectly demangles wchar_t
Product: Base System Reporter: Daniel McRobb <dwmcrobb>
Component: binAssignee: Ed Maste <emaste>
Status: Closed FIXED    
Severity: Affects Many People CC: dwmcrobb, pfg
Priority: --- Keywords: patch
Version: 10.3-BETA2Flags: emaste: mfc-stable11+
emaste: mfc-stable10+
emaste: mfc-stable9-
Hardware: Any   
OS: Any   
Attachments:
Description Flags
patch to fix demangling of wchar_t none

Description Daniel McRobb 2016-04-09 19:44:23 UTC
We wind up with 'wchar_' due to an incorrect string length in libelftc_dem_gnu3.c.
This is an upstream bug.

Patch:

Index: libelftc_dem_gnu3.c
===================================================================
--- libelftc_dem_gnu3.c	(revision 296556)
+++ libelftc_dem_gnu3.c	(working copy)
@@ -2842,7 +2842,7 @@
 
 	case 'w':
 		/* wchar_t */
-		if (!cpp_demangle_push_str(ddata, "wchar_t", 6))
+		if (!cpp_demangle_push_str(ddata, "wchar_t", 7))
 			goto clean;
 		++ddata->cur;
 		goto rtn;
Comment 1 Daniel McRobb 2016-04-09 19:46:28 UTC
Created attachment 169132 [details]
patch to fix demangling of wchar_t
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2016-07-24 22:35:21 UTC
Something for the elftoolchain guys.
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-07-24 23:41:12 UTC
A commit references this bug:

Author: emaste
Date: Sun Jul 24 23:40:34 UTC 2016
New revision: 303279
URL: https://svnweb.freebsd.org/changeset/base/303279

Log:
  libelftc: fix demangling of wchar_t

  "wchar_t" is 7 characters long, not 6.

  PR:		208661
  Submitted by:	Daniel McRobb
  Obtained from:	ELF Tool Chain r3480
  MFC after:	3 days

Changes:
  head/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-07-27 17:10:45 UTC
A commit references this bug:

Author: emaste
Date: Wed Jul 27 17:10:10 UTC 2016
New revision: 303398
URL: https://svnweb.freebsd.org/changeset/base/303398

Log:
  MFC r303279: libelftc: fix demangling of wchar_t

  "wchar_t" is 7 characters long, not 6.

  PR:		208661
  Submitted by:	Daniel McRobb
  Approved by:	re (kib)
  Obtained from:	ELF Tool Chain r3480

Changes:
_U  stable/11/
  stable/11/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-07-27 17:18:47 UTC
A commit references this bug:

Author: emaste
Date: Wed Jul 27 17:18:08 UTC 2016
New revision: 303400
URL: https://svnweb.freebsd.org/changeset/base/303400

Log:
  libcxxrt: fix demangling of wchar_t

  'wchar_t' is 7 characters long, not 6. r303297 fixed this in libelftc,
  but not the second copy of this file that we have in libcxxrt.

  PR:		208661
  Submitted by:	Daniel McRobb
  Obtained from:	ELF Tool Chain r3480
  MFC after:	3 days

Changes:
  head/contrib/libcxxrt/libelftc_dem_gnu3.c
Comment 6 Ed Maste freebsd_committer freebsd_triage 2016-07-27 17:36:35 UTC
Merged into libcxxrt upstream now too: https://github.com/pathscale/libcxxrt/commit/c9601e983bb2381215d00342dd00ac70a81d45a4
Comment 7 commit-hook freebsd_committer freebsd_triage 2016-08-01 16:17:11 UTC
A commit references this bug:

Author: emaste
Date: Mon Aug  1 16:16:49 UTC 2016
New revision: 303618
URL: https://svnweb.freebsd.org/changeset/base/303618

Log:
  MFC r303400: libcxxrt: fix demangling of wchar_t

  'wchar_t' is 7 characters long, not 6. r303297 fixed this (in head) in
  libelftc, but not the second copy of this file that we have in libcxxrt.

  PR:		208661

Changes:
_U  stable/10/
  stable/10/contrib/libcxxrt/libelftc_dem_gnu3.c
Comment 8 commit-hook freebsd_committer freebsd_triage 2016-08-01 16:18:13 UTC
A commit references this bug:

Author: emaste
Date: Mon Aug  1 16:18:01 UTC 2016
New revision: 303619
URL: https://svnweb.freebsd.org/changeset/base/303619

Log:
  iMFC r303400: libcxxrt: fix demangling of wchar_t

  'wchar_t' is 7 characters long, not 6. r303297 (MFC'd in r303398) fixed
  this in libelftc, but not the second copy of this file that we have in
  libcxxrt.

  PR:		208661
  Approved by:	re (gjb)

Changes:
_U  stable/11/
  stable/11/contrib/libcxxrt/libelftc_dem_gnu3.c
Comment 9 Ed Maste freebsd_committer freebsd_triage 2016-08-01 16:19:30 UTC
Both copies (libelftc and libcxxrt) are now fixed in all branches where they exist from stable/10 on.
Comment 10 commit-hook freebsd_committer freebsd_triage 2017-04-01 12:28:11 UTC
A commit references this bug:

Author: dim
Date: Sat Apr  1 12:27:03 UTC 2017
New revision: 316356
URL: https://svnweb.freebsd.org/changeset/base/316356

Log:
  Synchronize libcxxrt in stable/9 with stable/{10,11} and head.

  MFC r284549 (by emaste):

  Import libcxxrt master e64e93fe5bba67a6d52cbe5a97f8770c054bfa65

  This includes a number of fixes to the C++ demangler (obtained from
  upstream ELF Tool Chain).

  MFC r284551 (by emaste):

  Import libcxxrt master e64e93fe5bba67a6d52cbe5a97f8770c054bfa65.

  This includes a number of demangler fixes obtained from upstream
  ELF Tool Chain.

  PR:		200913
  Sponsored by:	The FreeBSD Foundation

  MFC r284553 (by emaste):

  Update libcxxrt upgrade instructions

  The typeinfo file no longer exists upstream.

  MFC r288830:

  Add std::uncaught_exceptions() to libcxxrt (C++17, see N4152 and N4259).
  This has also been submitted upstream.

  MFC r288830:

  Add std::uncaught_exceptions() to libcxxrt (C++17, see N4152 and N4259).
  This has also been submitted upstream.

  MFC r297299:

  Compile libcxxrt as C++11, since it is only really used in combination
  with libc++, which is also C++11.  Also change one _Static_assert (which
  is really C11) back into static_assert, like upstream.

  This should help when compiling libcxxrt with newer versions of gcc,
  which refuse to recognize any form of static assertions, if not
  compiling for C++11 or higher.

  While here, add -nostdinc++ to CFLAGS, to prevent picking up any C++
  headers outside the source tree.

  MFC r299144:

  Import libcxxrt master 516a65c109eb0a01e5e95fbef455eb3215135cef.

  Interesting fixes:
  3adaa2e Fix _Unwind_Exception cleanup functions
  286776c Check exception cleanup function ptr before calling
  edda626 Correct exception specifications on new and delete operators

  MFC r303157 (by emaste):

  libcxxrt: add padding in __cxa_allocate_* to fix alignment

  The addition of the referenceCount to __cxa_allocate_exception put the
  unwindHeader at offset 0x58 in __cxa_exception, but it requires 16-byte
  alignment. In order to avoid changing the current __cxa_exception ABI
  (and thus breaking its consumers), add explicit padding in the
  allocation routines (and account for it when freeing).

  This is intended as a lower-risk change for FreeBSD 11. A "more correct"
  fix should be prepared for upstream and -CURRENT.

  Reviewed by:	dim
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D7271

  MFC r303400 (by emaste):

  libcxxrt: fix demangling of wchar_t

  'wchar_t' is 7 characters long, not 6. r303297 fixed this in libelftc,
  but not the second copy of this file that we have in libcxxrt.

  PR:		208661
  Submitted by:	Daniel McRobb
  Obtained from:	ELF Tool Chain r3480

  MFC r305396:

  Add _US_ACTION_MASK to libcxxrt's arm-specific unwind header.  This
  value is used in newer versions of compiler-rt.

  MFC r315947 | dim | 2017-03-25 14:17:48 +0100 (Sat, 25 Mar 2017) | 8 lines

  Import libcxxrt master 8a853717e61d5d55cbdf74d9d0a7545da5d5ff92.

  Interesting fixes which were not already merged:
  0c7c611 Merge C++ demangler bug fixes from ELF Tool Chain (#40)
  2b208d9 __cxa_demangle_gnu3: demangle 'z' as '...', not 'ellipsis' (#41)

Changes:
_U  stable/9/
_U  stable/9/contrib/
_U  stable/9/contrib/libcxxrt/
  stable/9/contrib/libcxxrt/FREEBSD-upgrade
  stable/9/contrib/libcxxrt/exception.cc
  stable/9/contrib/libcxxrt/guard.cc
  stable/9/contrib/libcxxrt/libelftc_dem_gnu3.c
  stable/9/contrib/libcxxrt/memory.cc
  stable/9/contrib/libcxxrt/unwind-arm.h
_U  stable/9/lib/
_U  stable/9/lib/libcxxrt/
  stable/9/lib/libcxxrt/Makefile
  stable/9/lib/libcxxrt/Version.map