Skip to content

Commit 12315ed

Browse files
committed
ibc++abi: mark visibility
Mark functions and types with the appropriate visibility. This is particularly useful for environments which explicitly indicate origin of functions (Windows). This aids in generating libc++abi as a DSO which exposes only the public interfaces. llvm-svn: 254691
1 parent 242d67b commit 12315ed

10 files changed

+264
-212
lines changed

libcxxabi/include/__cxxabi_config.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,28 @@
1717
#define LIBCXXABI_ARM_EHABI 0
1818
#endif
1919

20+
#if !defined(__has_attribute)
21+
#define __has_attribute(_attribute_) 0
22+
#endif
23+
24+
#if defined(_LIBCXXABI_DLL)
25+
#if defined(cxxabi_EXPORTS)
26+
#define _LIBCXXABI_HIDDEN
27+
#define _LIBCXXABI_FUNC_VIS __declspec(dllexport)
28+
#define _LIBCXXABI_TYPE_VIS __declspec(dllexport)
29+
#else
30+
#define _LIBCXXABI_HIDDEN
31+
#define _LIBCXXABI_FUNC_VIS __declspec(dllimport)
32+
#define _LIBCXXABI_TYPE_VIS __declspec(dllimport)
33+
#endif
34+
#else
35+
#define _LIBCXXABI_HIDDEN __attribute__((__visibility__("hidden")))
36+
#define _LIBCXXABI_FUNC_VIS __attribute__((__visibility__("default")))
37+
#if __has_attribute(__type_visibility__)
38+
#define _LIBCXXABI_TYPE_VIS __attribute__((__type_visibility__("default")))
39+
#else
40+
#define _LIBCXXABI_TYPE_VIS __attribute__((__visibility__("default")))
41+
#endif
42+
#endif
43+
2044
#endif // ____CXXABI_CONFIG_H

libcxxabi/include/cxxabi.h

Lines changed: 96 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
#ifdef __cplusplus
2727

2828
namespace std {
29+
#if defined(_WIN32)
30+
class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
31+
#else
2932
class type_info; // forward declaration
33+
#endif
3034
}
3135

3236

@@ -35,113 +39,132 @@ namespace __cxxabiv1 {
3539
extern "C" {
3640

3741
// 2.4.2 Allocating the Exception Object
38-
extern void *__cxa_allocate_exception(size_t thrown_size) throw();
39-
extern void __cxa_free_exception(void *thrown_exception) throw();
42+
extern _LIBCXXABI_FUNC_VIS void *
43+
__cxa_allocate_exception(size_t thrown_size) throw();
44+
extern _LIBCXXABI_FUNC_VIS void
45+
__cxa_free_exception(void *thrown_exception) throw();
4046

4147
// 2.4.3 Throwing the Exception Object
42-
extern LIBCXXABI_NORETURN void __cxa_throw(void *thrown_exception,
43-
std::type_info *tinfo,
44-
void (*dest)(void *));
48+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void
49+
__cxa_throw(void *thrown_exception, std::type_info *tinfo,
50+
void (*dest)(void *));
4551

4652
// 2.5.3 Exception Handlers
47-
extern void *__cxa_get_exception_ptr(void *exceptionObject) throw();
48-
extern void *__cxa_begin_catch(void *exceptionObject) throw();
49-
extern void __cxa_end_catch();
53+
extern _LIBCXXABI_FUNC_VIS void *
54+
__cxa_get_exception_ptr(void *exceptionObject) throw();
55+
extern _LIBCXXABI_FUNC_VIS void *
56+
__cxa_begin_catch(void *exceptionObject) throw();
57+
extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
5058
#if LIBCXXABI_ARM_EHABI
51-
extern bool __cxa_begin_cleanup(void *exceptionObject) throw();
52-
extern void __cxa_end_cleanup();
59+
extern _LIBCXXABI_FUNC_VIS bool
60+
__cxa_begin_cleanup(void *exceptionObject) throw();
61+
extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
5362
#endif
54-
extern std::type_info *__cxa_current_exception_type();
63+
extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
5564

5665
// 2.5.4 Rethrowing Exceptions
57-
extern LIBCXXABI_NORETURN void __cxa_rethrow();
66+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_rethrow();
5867

5968
// 2.6 Auxiliary Runtime APIs
60-
extern LIBCXXABI_NORETURN void __cxa_bad_cast(void);
61-
extern LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
62-
extern LIBCXXABI_NORETURN void __cxa_throw_bad_array_new_length(void);
69+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_bad_cast(void);
70+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
71+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void
72+
__cxa_throw_bad_array_new_length(void);
6373

6474
// 3.2.6 Pure Virtual Function API
65-
extern LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
75+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
6676

6777
// 3.2.7 Deleted Virtual Function API
68-
extern LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
78+
extern _LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
6979

7080
// 3.3.2 One-time Construction API
7181
#ifdef __arm__
72-
extern int __cxa_guard_acquire(uint32_t *);
73-
extern void __cxa_guard_release(uint32_t *);
74-
extern void __cxa_guard_abort(uint32_t *);
82+
extern _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(uint32_t *);
83+
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_release(uint32_t *);
84+
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(uint32_t *);
7585
#else
76-
extern int __cxa_guard_acquire(uint64_t *);
77-
extern void __cxa_guard_release(uint64_t *);
78-
extern void __cxa_guard_abort(uint64_t *);
86+
extern _LIBCXXABI_FUNC_VIS int __cxa_guard_acquire(uint64_t *);
87+
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_release(uint64_t *);
88+
extern _LIBCXXABI_FUNC_VIS void __cxa_guard_abort(uint64_t *);
7989
#endif
8090

8191
// 3.3.3 Array Construction and Destruction API
82-
extern void *__cxa_vec_new(size_t element_count, size_t element_size,
83-
size_t padding_size, void (*constructor)(void *),
84-
void (*destructor)(void *));
85-
86-
extern void *__cxa_vec_new2(size_t element_count, size_t element_size,
87-
size_t padding_size, void (*constructor)(void *),
88-
void (*destructor)(void *), void *(*alloc)(size_t),
89-
void (*dealloc)(void *));
90-
91-
extern void *__cxa_vec_new3(size_t element_count, size_t element_size,
92-
size_t padding_size, void (*constructor)(void *),
93-
void (*destructor)(void *), void *(*alloc)(size_t),
94-
void (*dealloc)(void *, size_t));
95-
96-
extern void __cxa_vec_ctor(void *array_address, size_t element_count,
97-
size_t element_size, void (*constructor)(void *),
98-
void (*destructor)(void *));
99-
100-
extern void __cxa_vec_dtor(void *array_address, size_t element_count,
101-
size_t element_size, void (*destructor)(void *));
102-
103-
extern void __cxa_vec_cleanup(void *array_address, size_t element_count,
104-
size_t element_size, void (*destructor)(void *));
105-
106-
extern void __cxa_vec_delete(void *array_address, size_t element_size,
107-
size_t padding_size, void (*destructor)(void *));
108-
109-
extern void __cxa_vec_delete2(void *array_address, size_t element_size,
110-
size_t padding_size, void (*destructor)(void *),
111-
void (*dealloc)(void *));
112-
113-
extern void __cxa_vec_delete3(void *__array_address, size_t element_size,
114-
size_t padding_size, void (*destructor)(void *),
115-
void (*dealloc)(void *, size_t));
116-
117-
extern void __cxa_vec_cctor(void *dest_array, void *src_array,
118-
size_t element_count, size_t element_size,
119-
void (*constructor)(void *, void *),
120-
void (*destructor)(void *));
92+
extern _LIBCXXABI_FUNC_VIS void *
93+
__cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size,
94+
void (*constructor)(void *), void (*destructor)(void *));
95+
96+
extern _LIBCXXABI_FUNC_VIS void *
97+
__cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size,
98+
void (*constructor)(void *), void (*destructor)(void *),
99+
void *(*alloc)(size_t), void (*dealloc)(void *));
100+
101+
extern _LIBCXXABI_FUNC_VIS void *
102+
__cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size,
103+
void (*constructor)(void *), void (*destructor)(void *),
104+
void *(*alloc)(size_t), void (*dealloc)(void *, size_t));
105+
106+
extern _LIBCXXABI_FUNC_VIS void
107+
__cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size,
108+
void (*constructor)(void *), void (*destructor)(void *));
109+
110+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address,
111+
size_t element_count,
112+
size_t element_size,
113+
void (*destructor)(void *));
114+
115+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address,
116+
size_t element_count,
117+
size_t element_size,
118+
void (*destructor)(void *));
119+
120+
extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address,
121+
size_t element_size,
122+
size_t padding_size,
123+
void (*destructor)(void *));
124+
125+
extern _LIBCXXABI_FUNC_VIS void
126+
__cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size,
127+
void (*destructor)(void *), void (*dealloc)(void *));
128+
129+
extern _LIBCXXABI_FUNC_VIS void
130+
__cxa_vec_delete3(void *__array_address, size_t element_size,
131+
size_t padding_size, void (*destructor)(void *),
132+
void (*dealloc)(void *, size_t));
133+
134+
extern _LIBCXXABI_FUNC_VIS void
135+
__cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count,
136+
size_t element_size, void (*constructor)(void *, void *),
137+
void (*destructor)(void *));
121138

122139
// 3.3.5.3 Runtime API
123-
extern int __cxa_atexit(void (*f)(void *), void *p, void *d);
124-
extern int __cxa_finalize(void *);
140+
extern _LIBCXXABI_FUNC_VIS int __cxa_atexit(void (*f)(void *), void *p,
141+
void *d);
142+
extern _LIBCXXABI_FUNC_VIS int __cxa_finalize(void *);
125143

126144
// 3.4 Demangler API
127-
extern char *__cxa_demangle(const char *mangled_name, char *output_buffer,
128-
size_t *length, int *status);
145+
extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
146+
char *output_buffer,
147+
size_t *length, int *status);
129148

130149
// Apple additions to support C++ 0x exception_ptr class
131150
// These are primitives to wrap a smart pointer around an exception object
132-
extern void *__cxa_current_primary_exception() throw();
133-
extern void __cxa_rethrow_primary_exception(void *primary_exception);
134-
extern void __cxa_increment_exception_refcount(void *primary_exception) throw();
135-
extern void __cxa_decrement_exception_refcount(void *primary_exception) throw();
151+
extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
152+
extern _LIBCXXABI_FUNC_VIS void
153+
__cxa_rethrow_primary_exception(void *primary_exception);
154+
extern _LIBCXXABI_FUNC_VIS void
155+
__cxa_increment_exception_refcount(void *primary_exception) throw();
156+
extern _LIBCXXABI_FUNC_VIS void
157+
__cxa_decrement_exception_refcount(void *primary_exception) throw();
136158

137159
// Apple extension to support std::uncaught_exception()
138-
extern bool __cxa_uncaught_exception() throw();
139-
extern unsigned int __cxa_uncaught_exceptions() throw();
160+
extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
161+
extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
140162

141163
#ifdef __linux__
142164
// Linux TLS support. Not yet an official part of the Itanium ABI.
143165
// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
144-
extern int __cxa_thread_atexit(void (*)(void *), void *, void *) throw();
166+
extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
167+
void *) throw();
145168
#endif
146169

147170
} // extern "C"

libcxxabi/src/cxa_aux_runtime.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616

1717
namespace __cxxabiv1 {
1818
extern "C" {
19-
LIBCXXABI_NORETURN
20-
void __cxa_bad_cast(void) { throw std::bad_cast(); }
19+
_LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_bad_cast(void) {
20+
throw std::bad_cast();
21+
}
2122

22-
LIBCXXABI_NORETURN
23-
void __cxa_bad_typeid(void) { throw std::bad_typeid(); }
23+
_LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_bad_typeid(void) {
24+
throw std::bad_typeid();
25+
}
2426

25-
LIBCXXABI_NORETURN
26-
void __cxa_throw_bad_array_new_length(void) {
27+
_LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void
28+
__cxa_throw_bad_array_new_length(void) {
2729
throw std::bad_array_new_length();
2830
}
2931
} // extern "C"

libcxxabi/src/cxa_demangle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define _LIBCPP_EXTERN_TEMPLATE(...)
1111
#define _LIBCPP_NO_EXCEPTIONS
1212

13+
#include "__cxxabi_config.h"
14+
1315
#include <vector>
1416
#include <algorithm>
1517
#include <string>
@@ -4922,7 +4924,7 @@ struct Db
49224924

49234925
} // unnamed namespace
49244926

4925-
extern "C" __attribute__((__visibility__("default"))) char *
4927+
extern "C" _LIBCXXABI_FUNC_VIS char *
49264928
__cxa_demangle(const char *mangled_name, char *buf, size_t *n, int *status) {
49274929
if (mangled_name == nullptr || (buf != nullptr && n == nullptr))
49284930
{

libcxxabi/src/cxa_exception.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ extern "C" {
156156
// object. Zero-fill the object. If memory can't be allocated, call
157157
// std::terminate. Return a pointer to the memory to be used for the
158158
// user's exception object.
159-
void *__cxa_allocate_exception(size_t thrown_size) throw() {
159+
_LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() {
160160
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
161161
__cxa_exception* exception_header = static_cast<__cxa_exception*>(do_malloc(actual_size));
162162
if (NULL == exception_header)
@@ -167,7 +167,7 @@ void *__cxa_allocate_exception(size_t thrown_size) throw() {
167167

168168

169169
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
170-
void __cxa_free_exception(void *thrown_object) throw() {
170+
_LIBCXXABI_FUNC_VIS void __cxa_free_exception(void *thrown_object) throw() {
171171
do_free(cxa_exception_from_thrown_object(thrown_object));
172172
}
173173

@@ -218,9 +218,8 @@ handler, _Unwind_RaiseException may return. In that case, __cxa_throw
218218
will call terminate, assuming that there was no handler for the
219219
exception.
220220
*/
221-
LIBCXXABI_NORETURN
222-
void __cxa_throw(void *thrown_object, std::type_info *tinfo,
223-
void (*dest)(void *)) {
221+
_LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void
222+
__cxa_throw(void *thrown_object, std::type_info *tinfo, void (*dest)(void *)) {
224223
__cxa_eh_globals *globals = __cxa_get_globals();
225224
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
226225

@@ -252,6 +251,7 @@ The adjusted pointer is computed by the personality routine during phase 1
252251
253252
Requires: exception is native
254253
*/
254+
_LIBCXXABI_FUNC_VIS
255255
void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
256256
#if LIBCXXABI_ARM_EHABI
257257
return reinterpret_cast<void*>(
@@ -267,6 +267,7 @@ void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
267267
The routine to be called before the cleanup. This will save __cxa_exception in
268268
__cxa_eh_globals, so that __cxa_end_cleanup() can recover later.
269269
*/
270+
_LIBCXXABI_FUNC_VIS
270271
bool __cxa_begin_cleanup(void *unwind_arg) throw() {
271272
_Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
272273
__cxa_eh_globals* globals = __cxa_get_globals();
@@ -438,7 +439,7 @@ For a foreign exception:
438439
* If it has been rethrown, there is nothing to do.
439440
* Otherwise delete the exception and pop the catch stack to empty.
440441
*/
441-
void __cxa_end_catch() {
442+
_LIBCXXABI_FUNC_VIS void __cxa_end_catch() {
442443
static_assert(sizeof(__cxa_exception) == sizeof(__cxa_dependent_exception),
443444
"sizeof(__cxa_exception) must be equal to "
444445
"sizeof(__cxa_dependent_exception)");
@@ -515,7 +516,7 @@ void __cxa_end_catch() {
515516
// Note: exception_header may be masquerading as a __cxa_dependent_exception
516517
// and that's ok. exceptionType is there too.
517518
// However watch out for foreign exceptions. Return null for them.
518-
std::type_info *__cxa_current_exception_type() {
519+
_LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type() {
519520
// get the current exception
520521
__cxa_eh_globals *globals = __cxa_get_globals_fast();
521522
if (NULL == globals)
@@ -540,8 +541,7 @@ If the exception is native:
540541
Note: exception_header may be masquerading as a __cxa_dependent_exception
541542
and that's ok.
542543
*/
543-
LIBCXXABI_NORETURN
544-
void __cxa_rethrow() {
544+
_LIBCXXABI_FUNC_VIS LIBCXXABI_NORETURN void __cxa_rethrow() {
545545
__cxa_eh_globals* globals = __cxa_get_globals();
546546
__cxa_exception* exception_header = globals->caughtExceptions;
547547
if (NULL == exception_header)
@@ -586,7 +586,8 @@ void __cxa_rethrow() {
586586
587587
Requires: If thrown_object is not NULL, it is a native exception.
588588
*/
589-
void __cxa_increment_exception_refcount(void *thrown_object) throw() {
589+
_LIBCXXABI_FUNC_VIS void
590+
__cxa_increment_exception_refcount(void *thrown_object) throw() {
590591
if (thrown_object != NULL )
591592
{
592593
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@@ -602,7 +603,8 @@ void __cxa_increment_exception_refcount(void *thrown_object) throw() {
602603
603604
Requires: If thrown_object is not NULL, it is a native exception.
604605
*/
605-
void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
606+
_LIBCXXABI_FUNC_VIS void
607+
__cxa_decrement_exception_refcount(void *thrown_object) throw() {
606608
if (thrown_object != NULL )
607609
{
608610
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
@@ -625,7 +627,7 @@ void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
625627
been no exceptions thrown, ever, on this thread, we can return NULL without
626628
the need to allocate the exception-handling globals.
627629
*/
628-
void *__cxa_current_primary_exception() throw() {
630+
_LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw() {
629631
// get the current exception
630632
__cxa_eh_globals* globals = __cxa_get_globals_fast();
631633
if (NULL == globals)

0 commit comments

Comments
 (0)