Page MenuHomeFreeBSD

Improve libelftc's C++ demangler robustness
AbandonedPublic

Authored by dim on Nov 2 2020, 6:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 29 2023, 9:51 PM
Unknown Object (File)
Sep 25 2023, 2:17 AM
Unknown Object (File)
Jun 14 2023, 11:05 PM
Unknown Object (File)
Apr 23 2023, 4:28 AM
Unknown Object (File)
Nov 28 2022, 10:16 AM
Subscribers

Details

Reviewers
emaste
yuri
Summary

In bug 250702, various mangled identifiers are reported which cause
libelftc's demangler (in libelftc_dem_gnu3.c) to abort, with a few
different assertion failures. I have submitted fixes upstream, but in
the mean time we want to apply these to our copy:

Fix 1: Work around problem introduced in upstream r3531:

Ensure cpp_demangle_read_sname() checks ddata->cur_output, since it
can be called with ddata->cur_output set to many different `struct
vector_str` instances.

Fix 2: Fix the second part of #581, which is about an assertion with
nested template parameters.

demangle:
_ZZN7WebCore19SVGAnimatedProperty20LookupOrCreateHelperINS_32SVGAnimatedStaticPropertyTearOffIbEEbLb1EE21lookupOrCreateWrapperEPNS_10SVGElementEPKNS_15SVGPropertyInfoERbE19__PRETTY_FUNCTION__

to:
WebCore::SVGAnimatedProperty::LookupOrCreateHelper<WebCore::SVGAnimatedStaticPropertyTearOff<bool>, bool, true>::lookupOrCreateWrapper(WebCore::SVGElement*, WebCore::SVGPropertyInfo const*, bool&)::__PRETTY_FUNCTION__

Fix 3: Fix assertions in home-grown vector implementation.

When vector_str_push_vector() pushes a vector of size 1 onto a vector
of size 0, as is usual in the beginning of demangling, the resulting
vector gets a capacity of 1. Later on, this wreaks havoc when its
capacity is multiplied by BUFFER_GROW_FACTOR (1.618), since this
rounds down so the capacity cannot grow beyond 1!

Add a BUFFER_GROW() macro to ensure the calculation is correctly
rounded, and always increases the capacity.

NOTE: This does not yet add lambda and unnamed types support!
Test Plan

Mangled input names:

_ZZ5func1vENK3$_0clEv
_ZZN7WebCore19SVGAnimatedProperty20LookupOrCreateHelperINS_32SVGAnimatedStaticPropertyTearOffIbEEbLb1EE21lookupOrCreateWrapperEPNS_10SVGElementEPKNS_15SVGPropertyInfoERbE19__PRETTY_FUNCTION__
_ZZN10half_float6detail15half2float_implEjfNSt3__117integral_constantIbLb1EEEE14exponent_table
_ZNSt3__116__copy_unalignedINS_6vectorIbNS_9allocatorIbEEEELb0EEENS_14__bit_iteratorIT_Lb0EXLi0EEEENS5_IS6_XT0_EXLi0EEEES8_S7_
_ZZN9libunwind17LocalAddressSpace18findUnwindSectionsEjRNS_18UnwindInfoSectionsEENUlP12dl_phdr_infojPvE_8__invokeES4_jS5_

Result:

func1()::$_0::operator()() const
WebCore::SVGAnimatedProperty::LookupOrCreateHelper<WebCore::SVGAnimatedStaticPropertyTearOff<bool>, bool, true>::lookupOrCreateWrapper(WebCore::SVGElement*, WebCore::SVGPropertyInfo const*, bool&)::__PRETTY_FUNCTION__
half_float::detail::half2float_impl(unsigned int, float, std::__1::integral_constant<bool, true>)::exponent_table
std::__1::__bit_iterator<bool, false, 0> std::__1::__copy_unaligned<std::__1::vector<bool, std::__1::allocator<bool> >, false>(std::__1::__bit_iterator<bool, std::__1::allocator<bool>, 0>, std::__1::__bit_iterator<bool, std::__1::allocator<bool>, 0>, std::__1::__bit_iterator<bool, false, 0>)
_ZZN9libunwind17LocalAddressSpace18findUnwindSectionsEjRNS_18UnwindInfoSectionsEENUlP12dl_phdr_infojPvE_8__invokeES4_jS5_

As expected the last one, which has a lambda, does not work yet. This is
for a later review. It should demangle to:

libunwind::LocalAddressSpace::findUnwindSections(unsigned int, libunwind::UnwindInfoSections&)::{lambda(dl_phdr_info*, unsigned int, void*)#1}::__invoke(dl_phdr_info*, unsigned int, void*)

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 34570
Build 31662: arc lint + arc unit