[libc++abi] Clean up visibility

Use the libc++abi visibility macros instead of pragmas or using
visibility attributes directly. Clean up redundant attributes on
definitions (where the declarations already have visibility attributes
applied, from either libc++ or libc++abi headers).

Introduce _LIBCXXABI_WEAK as a drive-by cleanup, which matches the
semantics of _LIBCPP_WEAK.

No functional change. Tested by building on Linux before and after this
change and verifying that the list of exported symbols is identical.

Differential Revision: https://reviews.llvm.org/D26949

llvm-svn: 296576
This commit is contained in:
Shoaib Meenai 2017-03-01 03:55:57 +00:00
parent 175ffa8c35
commit fe989a9817
16 changed files with 47 additions and 99 deletions

View File

@ -56,4 +56,10 @@
#endif
#endif
#if defined(_WIN32)
#define _LIBCXXABI_WEAK
#else
#define _LIBCXXABI_WEAK __attribute__((__weak__))
#endif
#endif // ____CXXABI_CONFIG_H

View File

@ -22,8 +22,6 @@ extern "C" void android_set_abort_message(const char* msg);
#endif // __ANDROID_API__ >= 21
#endif // __BIONIC__
#pragma GCC visibility push(hidden)
#ifdef __APPLE__
# if defined(__has_include) && __has_include(<CrashReporterClient.h>)
# define HAVE_CRASHREPORTERCLIENT_H
@ -31,7 +29,6 @@ extern "C" void android_set_abort_message(const char* msg);
# endif
#endif
__attribute__((visibility("hidden"), noreturn))
void abort_message(const char* format, ...)
{
// write message to stderr
@ -79,5 +76,3 @@ void abort_message(const char* format, ...)
abort();
}
#pragma GCC visibility pop

View File

@ -10,24 +10,18 @@
#ifndef __ABORT_MESSAGE_H_
#define __ABORT_MESSAGE_H_
#include <stdio.h>
#pragma GCC visibility push(hidden)
#include "cxxabi.h"
#ifdef __cplusplus
extern "C" {
#endif
__attribute__((visibility("hidden"), noreturn))
void abort_message(const char* format, ...)
__attribute__((format(printf, 1, 2)));
_LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN void
abort_message(const char *format, ...) __attribute__((format(printf, 1, 2)));
#ifdef __cplusplus
}
#endif
#pragma GCC visibility pop
#endif

View File

@ -33,8 +33,6 @@
namespace __cxxabiv1 {
#pragma GCC visibility push(default)
// Utility routines
static
inline
@ -139,7 +137,7 @@ extern "C" {
// object. Zero-fill the object. If memory can't be allocated, call
// std::terminate. Return a pointer to the memory to be used for the
// user's exception object.
_LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() {
void *__cxa_allocate_exception(size_t thrown_size) throw() {
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
__cxa_exception *exception_header =
static_cast<__cxa_exception *>(__malloc_with_fallback(actual_size));
@ -151,7 +149,7 @@ _LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() {
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
_LIBCXXABI_FUNC_VIS void __cxa_free_exception(void *thrown_object) throw() {
void __cxa_free_exception(void *thrown_object) throw() {
__free_with_fallback(cxa_exception_from_thrown_object(thrown_object));
}
@ -202,7 +200,7 @@ handler, _Unwind_RaiseException may return. In that case, __cxa_throw
will call terminate, assuming that there was no handler for the
exception.
*/
_LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
void
__cxa_throw(void *thrown_object, std::type_info *tinfo, void (*dest)(void *)) {
__cxa_eh_globals *globals = __cxa_get_globals();
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@ -235,7 +233,6 @@ The adjusted pointer is computed by the personality routine during phase 1
Requires: exception is native
*/
_LIBCXXABI_FUNC_VIS
void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
#if _LIBCXXABI_ARM_EHABI
return reinterpret_cast<void*>(
@ -251,7 +248,6 @@ void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
The routine to be called before the cleanup. This will save __cxa_exception in
__cxa_eh_globals, so that __cxa_end_cleanup() can recover later.
*/
_LIBCXXABI_FUNC_VIS
bool __cxa_begin_cleanup(void *unwind_arg) throw() {
_Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
__cxa_eh_globals* globals = __cxa_get_globals();
@ -423,7 +419,7 @@ For a foreign exception:
* If it has been rethrown, there is nothing to do.
* Otherwise delete the exception and pop the catch stack to empty.
*/
_LIBCXXABI_FUNC_VIS void __cxa_end_catch() {
void __cxa_end_catch() {
static_assert(sizeof(__cxa_exception) == sizeof(__cxa_dependent_exception),
"sizeof(__cxa_exception) must be equal to "
"sizeof(__cxa_dependent_exception)");
@ -500,7 +496,7 @@ _LIBCXXABI_FUNC_VIS void __cxa_end_catch() {
// Note: exception_header may be masquerading as a __cxa_dependent_exception
// and that's ok. exceptionType is there too.
// However watch out for foreign exceptions. Return null for them.
_LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type() {
std::type_info *__cxa_current_exception_type() {
// get the current exception
__cxa_eh_globals *globals = __cxa_get_globals_fast();
if (NULL == globals)
@ -525,7 +521,7 @@ If the exception is native:
Note: exception_header may be masquerading as a __cxa_dependent_exception
and that's ok.
*/
_LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow() {
void __cxa_rethrow() {
__cxa_eh_globals* globals = __cxa_get_globals();
__cxa_exception* exception_header = globals->caughtExceptions;
if (NULL == exception_header)
@ -570,7 +566,7 @@ _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow() {
Requires: If thrown_object is not NULL, it is a native exception.
*/
_LIBCXXABI_FUNC_VIS void
void
__cxa_increment_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
@ -587,7 +583,7 @@ __cxa_increment_exception_refcount(void *thrown_object) throw() {
Requires: If thrown_object is not NULL, it is a native exception.
*/
_LIBCXXABI_FUNC_VIS void
void
__cxa_decrement_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
@ -611,7 +607,7 @@ __cxa_decrement_exception_refcount(void *thrown_object) throw() {
been no exceptions thrown, ever, on this thread, we can return NULL without
the need to allocate the exception-handling globals.
*/
_LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw() {
void *__cxa_current_primary_exception() throw() {
// get the current exception
__cxa_eh_globals* globals = __cxa_get_globals_fast();
if (NULL == globals)
@ -697,6 +693,4 @@ __cxa_uncaught_exceptions() throw()
} // extern "C"
#pragma GCC visibility pop
} // abi

View File

@ -20,13 +20,11 @@
namespace __cxxabiv1 {
#pragma GCC visibility push(hidden)
static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
struct __cxa_exception {
struct _LIBCXXABI_HIDDEN __cxa_exception {
#if defined(__LP64__) || _LIBCXXABI_ARM_EHABI
// This is a new field to support C++ 0x exception_ptr.
// For binary compatibility it is at the start of this
@ -69,7 +67,7 @@ struct __cxa_exception {
// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
// The layout of this structure MUST match the layout of __cxa_exception, with
// primaryException instead of referenceCount.
struct __cxa_dependent_exception {
struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
#if defined(__LP64__) || _LIBCXXABI_ARM_EHABI
void* primaryException;
#endif
@ -101,7 +99,7 @@ struct __cxa_dependent_exception {
_Unwind_Exception unwindHeader;
};
struct __cxa_eh_globals {
struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
__cxa_exception * caughtExceptions;
unsigned int uncaughtExceptions;
#if _LIBCXXABI_ARM_EHABI
@ -109,16 +107,11 @@ struct __cxa_eh_globals {
#endif
};
#pragma GCC visibility pop
#pragma GCC visibility push(default)
extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals ();
extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
extern "C" __cxa_eh_globals * __cxa_get_globals ();
extern "C" __cxa_eh_globals * __cxa_get_globals_fast ();
extern "C" void * __cxa_allocate_dependent_exception ();
extern "C" void __cxa_free_dependent_exception (void * dependent_exception);
#pragma GCC visibility pop
extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
} // namespace __cxxabiv1

View File

@ -32,7 +32,6 @@ get_unexpected() _NOEXCEPT
// return __cxa_unexpected_handler.load(memory_order_acq);
}
__attribute__((visibility("hidden"), noreturn))
void
__unexpected(unexpected_handler func)
{
@ -57,7 +56,6 @@ get_terminate() _NOEXCEPT
// return __cxa_terminate_handler.load(memory_order_acq);
}
__attribute__((visibility("hidden"), noreturn))
void
__terminate(terminate_handler func) _NOEXCEPT
{
@ -105,7 +103,7 @@ terminate() _NOEXCEPT
// In the future this will become:
// std::atomic<std::new_handler> __cxa_new_handler(0);
extern "C" {
_LIBCXXABI_DATA_VIS new_handler __cxa_new_handler = 0;
new_handler __cxa_new_handler = 0;
}
new_handler

View File

@ -20,11 +20,11 @@
namespace std
{
__attribute__((visibility("hidden"), noreturn))
_LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN
void
__unexpected(unexpected_handler func);
__attribute__((visibility("hidden"), noreturn))
_LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN
void
__terminate(terminate_handler func) _NOEXCEPT;

View File

@ -11,6 +11,7 @@
#define _LIBCPP_BUILDING_NEW
#include "__cxxabi_config.h"
#include <new>
#include <cstdlib>
@ -36,7 +37,7 @@
* The loop terminates when an attempt to allocate the requested storage is
successful or when a called new_handler function does not return.
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void *
operator new(std::size_t size) _THROW_BAD_ALLOC
{
@ -70,7 +71,7 @@ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2158.html
Calls operator new(size). If the call returns normally, returns the result of
that call. Otherwise, returns a null pointer.
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void*
operator new(size_t size, const std::nothrow_t&) _NOEXCEPT
{
@ -94,7 +95,7 @@ operator new(size_t size, const std::nothrow_t&) _NOEXCEPT
Returns operator new(size).
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void*
operator new[](size_t size) _THROW_BAD_ALLOC
{
@ -107,7 +108,7 @@ operator new[](size_t size) _THROW_BAD_ALLOC
Calls operator new[](size). If the call returns normally, returns the result
of that call. Otherwise, returns a null pointer.
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void*
operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT
{
@ -132,7 +133,7 @@ operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT
If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the
earlier call to operator new.
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void
operator delete(void* ptr) _NOEXCEPT
{
@ -145,7 +146,7 @@ operator delete(void* ptr) _NOEXCEPT
calls operator delete(ptr)
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void
operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT
{
@ -157,7 +158,7 @@ operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT
Calls operator delete(ptr)
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void
operator delete[] (void* ptr) _NOEXCEPT
{
@ -169,7 +170,7 @@ operator delete[] (void* ptr) _NOEXCEPT
calls operator delete[](ptr)
*/
__attribute__((__weak__, __visibility__("default")))
_LIBCXXABI_WEAK
void
operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT
{

View File

@ -22,8 +22,6 @@
namespace __cxxabiv1 {
#pragma GCC visibility push(default)
extern "C" {
void
@ -55,6 +53,4 @@ __cxa_uncaught_exceptions() throw() { return 0; }
} // extern "C"
#pragma GCC visibility pop
} // abi

View File

@ -20,7 +20,7 @@ namespace __cxxabiv1 {
#ifndef HAVE___CXA_THREAD_ATEXIT_IMPL
// A weak symbol is used to detect this function's presence in the C library
// at runtime, even if libc++ is built against an older libc
__attribute__((__weak__))
_LIBCXXABI_WEAK
#endif
int __cxa_thread_atexit_impl(Dtor, void*, void*);

View File

@ -14,14 +14,10 @@
namespace __cxxabiv1
{
#pragma GCC visibility push(default)
extern "C"
{
}
#pragma GCC visibility pop
} // namespace __cxxabiv1

View File

@ -194,8 +194,6 @@ size_t print_free_list () {
namespace __cxxabiv1 {
#pragma GCC visibility push(hidden)
void * __malloc_with_fallback(size_t size) {
void *ptr = std::malloc(size);
if (NULL == ptr) // if malloc fails, fall back to emergency stash
@ -221,6 +219,4 @@ void __free_with_fallback(void *ptr) {
std::free(ptr);
}
#pragma GCC visibility pop
} // namespace __cxxabiv1

View File

@ -10,21 +10,18 @@
#ifndef _FALLBACK_MALLOC_H
#define _FALLBACK_MALLOC_H
#include "__cxxabi_config.h"
#include <cstddef> // for size_t
namespace __cxxabiv1 {
#pragma GCC visibility push(hidden)
// Allocate some memory from _somewhere_
void * __malloc_with_fallback(size_t size);
_LIBCXXABI_HIDDEN void * __malloc_with_fallback(size_t size);
// Allocate and zero-initialize memory from _somewhere_
void * __calloc_with_fallback(size_t count, size_t size);
_LIBCXXABI_HIDDEN void * __calloc_with_fallback(size_t count, size_t size);
void __free_with_fallback(void *ptr);
#pragma GCC visibility pop
_LIBCXXABI_HIDDEN void __free_with_fallback(void *ptr);
} // namespace __cxxabiv1

View File

@ -55,12 +55,7 @@
#include <string.h>
#endif
namespace __cxxabiv1
{
#pragma GCC visibility push(hidden)
inline
static inline
bool
is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp)
{
@ -73,6 +68,8 @@ is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp)
#endif
}
namespace __cxxabiv1
{
// __shim_type_info
@ -538,9 +535,6 @@ bool __pointer_to_member_type_info::can_catch_nested(
#pragma clang diagnostic pop
#endif
#pragma GCC visibility pop
#pragma GCC visibility push(default)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
@ -715,9 +709,6 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
#pragma clang diagnostic pop
#endif
#pragma GCC visibility pop
#pragma GCC visibility push(hidden)
// Call this function when you hit a static_type which is a base (above) a dst_type.
// Let caller know you hit a static_type. But only start recording details if
// this is (static_ptr, static_type) -- the node we are casting from.
@ -1300,6 +1291,4 @@ __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
use_strcmp);
}
#pragma GCC visibility pop
} // __cxxabiv1

View File

@ -16,7 +16,6 @@
#include <cstddef>
namespace __cxxabiv1 {
#pragma GCC visibility push(hidden)
class _LIBCXXABI_TYPE_VIS __shim_type_info : public std::type_info {
public:
@ -67,7 +66,7 @@ enum
class _LIBCXXABI_TYPE_VIS __class_type_info;
struct __dynamic_cast_info
struct _LIBCXXABI_HIDDEN __dynamic_cast_info
{
// const data supplied to the search:
@ -153,7 +152,7 @@ public:
has_unambiguous_public_base(__dynamic_cast_info *, void *, int) const;
};
struct __base_class_type_info
struct _LIBCXXABI_HIDDEN __base_class_type_info
{
public:
const __class_type_info* __base_type;
@ -248,8 +247,6 @@ public:
_LIBCXXABI_HIDDEN bool can_catch_nested(const __shim_type_info *) const;
};
#pragma GCC visibility pop
} // __cxxabiv1
#endif // __PRIVATE_TYPEINFO_H_

View File

@ -9,8 +9,6 @@
#include <exception>
#pragma GCC visibility push(default)
namespace std
{
@ -37,5 +35,3 @@ const char* bad_exception::what() const _NOEXCEPT
}
} // std
#pragma GCC visibility pop