Commit 8f45e92c authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Cut config-time detection of cplus_demangle_v3_callback

Summary: [Folly] Cut config-time detection of `cplus_demangle_v3_callback` and the forward declarations and copy-pasting symbols, replacing them with `__has_include(<demangle.h>)`.

Reviewed By: Orvid

Differential Revision: D9287760

fbshipit-source-id: 4464ec22dd6f96cf081cda6051bebe4d41813390
parent 8f6d3b10
......@@ -74,11 +74,6 @@ check_symbol_exists(preadv sys/uio.h FOLLY_HAVE_PREADV)
check_symbol_exists(pwritev sys/uio.h FOLLY_HAVE_PWRITEV)
check_symbol_exists(clock_gettime time.h FOLLY_HAVE_CLOCK_GETTIME)
check_function_exists(
cplus_demangle_v3_callback
FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
)
check_function_exists(malloc_usable_size FOLLY_HAVE_MALLOC_USABLE_SIZE)
set(CMAKE_REQUIRED_FLAGS "${FOLLY_ORIGINAL_CMAKE_REQUIRED_FLAGS}")
......
......@@ -45,7 +45,6 @@
#cmakedefine FOLLY_HAVE_PREADV 1
#cmakedefine FOLLY_HAVE_PWRITEV 1
#cmakedefine FOLLY_HAVE_CLOCK_GETTIME 1
#cmakedefine FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK 1
#cmakedefine FOLLY_HAVE_OPENSSL_ASN1_TIME_DIFF 1
#cmakedefine FOLLY_HAVE_IFUNC 1
......
......@@ -19,43 +19,18 @@
#include <algorithm>
#include <cstring>
#include <folly/detail/Demangle.h>
#include <folly/portability/Config.h>
#if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
#include <cxxabi.h>
#if FOLLY_DETAIL_HAVE_DEMANGLE_H
// From libiberty
//
// __attribute__((__weak__)) doesn't work, because cplus_demangle_v3_callback
// is exported by an object file in libiberty.a, and the ELF spec says
// "The link editor does not extract archive members to resolve undefined weak
// symbols" (but, interestingly enough, will resolve undefined weak symbols
// with definitions from archive members that were extracted in order to
// resolve an undefined global (strong) symbol)
# ifndef DMGL_NO_OPTS
# define FOLLY_DEFINED_DMGL 1
# define DMGL_NO_OPTS 0 /* For readability... */
# define DMGL_PARAMS (1 << 0) /* Include function args */
# define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
# define DMGL_JAVA (1 << 2) /* Demangle as Java rather than C++. */
# define DMGL_VERBOSE (1 << 3) /* Include implementation details. */
# define DMGL_TYPES (1 << 4) /* Also try to demangle type encodings. */
# define DMGL_RET_POSTFIX (1 << 5) /* Print function return types (when
present) after function signature */
# endif
extern "C" int cplus_demangle_v3_callback(
const char* mangled,
int options, // We use DMGL_PARAMS | DMGL_TYPES, aka 0x11
void (*callback)(const char*, size_t, void*),
void* arg);
#include <cxxabi.h>
#endif
namespace folly {
#if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
#if FOLLY_DETAIL_HAVE_DEMANGLE_H
fbstring demangle(const char* name) {
#ifdef FOLLY_DEMANGLE_MAX_SYMBOL_SIZE
......@@ -120,11 +95,8 @@ size_t demangle(const char* name, char* out, size_t outSize) {
dbuf.total = 0;
// Unlike most library functions, this returns 1 on success and 0 on failure
int status = cplus_demangle_v3_callback(
name,
DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES,
demangleCallback,
&dbuf);
int status =
detail::cplus_demangle_v3_callback_wrapper(name, demangleCallback, &dbuf);
if (status == 0) { // failed, return original
return folly::strlcpy(out, name, outSize);
}
......
......@@ -86,6 +86,7 @@ nobase_follyinclude_HEADERS = \
detail/AtFork.h \
detail/AtomicHashUtils.h \
detail/AtomicUnorderedMapUtils.h \
detail/Demangle.h \
detail/DiscriminatedPtrDetail.h \
detail/FileUtilDetail.h \
detail/FingerprintPolynomial.h \
......@@ -533,6 +534,7 @@ libfollybasesse42_la_SOURCES = \
libfollybase_la_SOURCES = \
Conv.cpp \
Demangle.cpp \
detail/Demangle.cpp \
detail/RangeCommon.cpp \
Format.cpp \
FormatArg.cpp \
......
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/detail/Demangle.h>
// Do not include <libiberty.h> (binutils) and <string.h> (glibc) in the same
// translation unit since they contain conflicting declarations for the symbol
// `basename`.
//
// So we extract the inclusion of `<demangle.h>` which includes `<libiberty.h>`
// to here, isolating it.
#if FOLLY_DETAIL_HAVE_DEMANGLE_H
#include <demangle.h>
#endif
namespace folly {
namespace detail {
int cplus_demangle_v3_callback_wrapper(
char const* const mangled,
void (*const cbref)(char const*, std::size_t, void*),
void* const opaque) {
#if FOLLY_DETAIL_HAVE_DEMANGLE_H
auto const options = DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES;
return cplus_demangle_v3_callback(mangled, options, cbref, opaque);
#else
return 0;
#endif
}
} // namespace detail
} // namespace folly
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <cstddef>
#if __has_include(<demangle.h>)
#define FOLLY_DETAIL_HAVE_DEMANGLE_H 1
#else
#define FOLLY_DETAIL_HAVE_DEMANGLE_H 0
#endif
namespace folly {
namespace detail {
extern int cplus_demangle_v3_callback_wrapper(
char const* mangled,
void (*cbref)(char const*, std::size_t, void*),
void* opaque);
} // namespace detail
} // namespace folly
......@@ -16,6 +16,7 @@
#include <folly/Demangle.h>
#include <folly/detail/Demangle.h>
#include <folly/portability/GTest.h>
using folly::demangle;
......@@ -25,7 +26,7 @@ struct ThisIsAVeryLongStructureName {
};
} // namespace folly_test
#if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
#if FOLLY_DETAIL_HAVE_DEMANGLE_H
TEST(Demangle, demangle) {
char expected[] = "folly_test::ThisIsAVeryLongStructureName";
EXPECT_STREQ(
......@@ -81,7 +82,7 @@ TEST(Demangle, LongSymbolFallback) {
}
#endif // defined(FOLLY_DEMANGLE_MAX_SYMBOL_SIZE)
#endif // FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
#endif // FOLLY_DETAIL_HAVE_DEMANGLE_H
TEST(Demangle, strlcpy) {
char buf[6];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment