Skip to content

Commit

Permalink
Add visibility attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
  • Loading branch information
phprus committed Jun 3, 2023
1 parent c41cedf commit 09a6491
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 64 deletions.
16 changes: 9 additions & 7 deletions include/oneapi/tbb/detail/_export.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2021 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,27 +18,29 @@
#define __TBB_detail__export_H

#if defined(__MINGW32__)
#define _EXPORT __declspec(dllexport)
#elif defined(_WIN32) || defined(__unix__) || defined(__APPLE__) // Use .def files for these
#define _EXPORT
#define __TBB_EXPORT __declspec(dllexport)
#elif defined(_WIN32) // Use .def files for these
#define __TBB_EXPORT
#elif defined(__unix__) || defined(__APPLE__) // Use .def files for these
#define __TBB_EXPORT __attribute__ ((visibility ("default")))
#else
#error "Unknown platform/compiler"
#endif

#if __TBB_BUILD
#define TBB_EXPORT _EXPORT
#define TBB_EXPORT __TBB_EXPORT
#else
#define TBB_EXPORT
#endif

#if __TBBMALLOC_BUILD
#define TBBMALLOC_EXPORT _EXPORT
#define TBBMALLOC_EXPORT __TBB_EXPORT
#else
#define TBBMALLOC_EXPORT
#endif

#if __TBBBIND_BUILD
#define TBBBIND_EXPORT _EXPORT
#define TBBBIND_EXPORT __TBB_EXPORT
#else
#define TBBBIND_EXPORT
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/tbb/queuing_rw_mutex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -608,7 +608,7 @@ bool __TBB_EXPORTED_FUNC downgrade_to_reader(d1::queuing_rw_mutex::scoped_lock&
return queuing_rw_mutex_impl::downgrade_to_reader(s);
}

void __TBB_EXPORTED_FUNC construct(d1::queuing_rw_mutex& m) {
TBB_EXPORT void __TBB_EXPORTED_FUNC construct(d1::queuing_rw_mutex& m) {
queuing_rw_mutex_impl::construct(m);
}

Expand Down
62 changes: 31 additions & 31 deletions src/tbbmalloc_proxy/proxy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -133,7 +133,7 @@ static inline void initPageSize()
2) check that dlsym("malloc") found something different from our replacement malloc
*/

extern "C" void *__TBB_malloc_proxy(size_t) __TBB_ALIAS_ATTR_COPY(malloc);
extern "C" __TBB_EXPORT void *__TBB_malloc_proxy(size_t) __TBB_ALIAS_ATTR_COPY(malloc);

static void *orig_msize;

Expand Down Expand Up @@ -184,23 +184,23 @@ inline void InitOrigPointers() {}

#endif // MALLOC_UNIXLIKE_OVERLOAD_ENABLED and MALLOC_ZONE_OVERLOAD_ENABLED

void *PREFIX(malloc)(ZONE_ARG size_t size) __THROW
__TBB_EXPORT void *PREFIX(malloc)(ZONE_ARG size_t size) __THROW
{
return scalable_malloc(size);
}

void *PREFIX(calloc)(ZONE_ARG size_t num, size_t size) __THROW
__TBB_EXPORT void *PREFIX(calloc)(ZONE_ARG size_t num, size_t size) __THROW
{
return scalable_calloc(num, size);
}

void PREFIX(free)(ZONE_ARG void *object) __THROW
__TBB_EXPORT void PREFIX(free)(ZONE_ARG void *object) __THROW
{
InitOrigPointers();
__TBB_malloc_safer_free(object, (void (*)(void*))orig_free);
}

void *PREFIX(realloc)(ZONE_ARG void* ptr, size_t sz) __THROW
__TBB_EXPORT void *PREFIX(realloc)(ZONE_ARG void* ptr, size_t sz) __THROW
{
InitOrigPointers();
return __TBB_malloc_safer_realloc(ptr, sz, orig_realloc);
Expand All @@ -209,13 +209,13 @@ void *PREFIX(realloc)(ZONE_ARG void* ptr, size_t sz) __THROW
/* The older *NIX interface for aligned allocations;
it's formally substituted by posix_memalign and deprecated,
so we do not expect it to cause cyclic dependency with C RTL. */
void *PREFIX(memalign)(ZONE_ARG size_t alignment, size_t size) __THROW
__TBB_EXPORT void *PREFIX(memalign)(ZONE_ARG size_t alignment, size_t size) __THROW
{
return scalable_aligned_malloc(size, alignment);
}

/* valloc allocates memory aligned on a page boundary */
void *PREFIX(valloc)(ZONE_ARG size_t size) __THROW
__TBB_EXPORT void *PREFIX(valloc)(ZONE_ARG size_t size) __THROW
{
if (! memoryPageSize) initPageSize();

Expand All @@ -229,23 +229,23 @@ void *PREFIX(valloc)(ZONE_ARG size_t size) __THROW

// match prototype from system headers
#if __ANDROID__
size_t malloc_usable_size(const void *ptr) __THROW
__TBB_EXPORT size_t malloc_usable_size(const void *ptr) __THROW
#else
size_t malloc_usable_size(void *ptr) __THROW
__TBB_EXPORT size_t malloc_usable_size(void *ptr) __THROW
#endif
{
InitOrigPointers();
return __TBB_malloc_safer_msize(const_cast<void*>(ptr), (size_t (*)(void*))orig_msize);
}

int posix_memalign(void **memptr, size_t alignment, size_t size) __THROW
__TBB_EXPORT int posix_memalign(void **memptr, size_t alignment, size_t size) __THROW
{
return scalable_posix_memalign(memptr, alignment, size);
}

/* pvalloc allocates smallest set of complete pages which can hold
the requested number of bytes. Result is aligned on page boundary. */
void *pvalloc(size_t size) __THROW
__TBB_EXPORT void *pvalloc(size_t size) __THROW
{
if (! memoryPageSize) initPageSize();
// align size up to the page size,
Expand All @@ -255,13 +255,13 @@ void *pvalloc(size_t size) __THROW
return scalable_aligned_malloc(size, memoryPageSize);
}

int mallopt(int /*param*/, int /*value*/) __THROW
__TBB_EXPORT int mallopt(int /*param*/, int /*value*/) __THROW
{
return 1;
}

#if defined(__GLIBC__) || defined(__ANDROID__)
struct mallinfo mallinfo() __THROW
__TBB_EXPORT struct mallinfo mallinfo() __THROW
{
struct mallinfo m;
memset(&m, 0, sizeof(struct mallinfo));
Expand All @@ -274,30 +274,30 @@ struct mallinfo mallinfo() __THROW
// Android doesn't have malloc_usable_size, provide it to be compatible
// with Linux, in addition overload dlmalloc_usable_size() that presented
// under Android.
size_t dlmalloc_usable_size(const void *ptr) __TBB_ALIAS_ATTR_COPY(malloc_usable_size);
__TBB_EXPORT size_t dlmalloc_usable_size(const void *ptr) __TBB_ALIAS_ATTR_COPY(malloc_usable_size);
#else // __ANDROID__
// TODO: consider using __typeof__ to guarantee the correct declaration types
// C11 function, supported starting GLIBC 2.16
void *aligned_alloc(size_t alignment, size_t size) __TBB_ALIAS_ATTR_COPY(memalign);
__TBB_EXPORT void *aligned_alloc(size_t alignment, size_t size) __TBB_ALIAS_ATTR_COPY(memalign);
// Those non-standard functions are exported by GLIBC, and might be used
// in conjunction with standard malloc/free, so we must overload them.
// Bionic doesn't have them. Not removing from the linker scripts,
// as absent entry points are ignored by the linker.

void *__libc_malloc(size_t size) __TBB_ALIAS_ATTR_COPY(malloc);
void *__libc_calloc(size_t num, size_t size) __TBB_ALIAS_ATTR_COPY(calloc);
void *__libc_memalign(size_t alignment, size_t size) __TBB_ALIAS_ATTR_COPY(memalign);
void *__libc_pvalloc(size_t size) __TBB_ALIAS_ATTR_COPY(pvalloc);
void *__libc_valloc(size_t size) __TBB_ALIAS_ATTR_COPY(valloc);
__TBB_EXPORT void *__libc_malloc(size_t size) __TBB_ALIAS_ATTR_COPY(malloc);
__TBB_EXPORT void *__libc_calloc(size_t num, size_t size) __TBB_ALIAS_ATTR_COPY(calloc);
__TBB_EXPORT void *__libc_memalign(size_t alignment, size_t size) __TBB_ALIAS_ATTR_COPY(memalign);
__TBB_EXPORT void *__libc_pvalloc(size_t size) __TBB_ALIAS_ATTR_COPY(pvalloc);
__TBB_EXPORT void *__libc_valloc(size_t size) __TBB_ALIAS_ATTR_COPY(valloc);

// call original __libc_* to support naive replacement of free via __libc_free etc
void __libc_free(void *ptr)
__TBB_EXPORT void __libc_free(void *ptr)
{
InitOrigPointers();
__TBB_malloc_safer_free(ptr, (void (*)(void*))orig_libc_free);
}

void *__libc_realloc(void *ptr, size_t size)
__TBB_EXPORT void *__libc_realloc(void *ptr, size_t size)
{
InitOrigPointers();
return __TBB_malloc_safer_realloc(ptr, size, orig_libc_realloc);
Expand All @@ -308,31 +308,31 @@ void *__libc_realloc(void *ptr, size_t size)

/*** replacements for global operators new and delete ***/

void* operator new(size_t sz) {
__TBB_EXPORT void* operator new(size_t sz) {
return InternalOperatorNew(sz);
}
void* operator new[](size_t sz) {
__TBB_EXPORT void* operator new[](size_t sz) {
return InternalOperatorNew(sz);
}
void operator delete(void* ptr) noexcept {
__TBB_EXPORT void operator delete(void* ptr) noexcept {
InitOrigPointers();
__TBB_malloc_safer_free(ptr, (void (*)(void*))orig_free);
}
void operator delete[](void* ptr) noexcept {
__TBB_EXPORT void operator delete[](void* ptr) noexcept {
InitOrigPointers();
__TBB_malloc_safer_free(ptr, (void (*)(void*))orig_free);
}
void* operator new(size_t sz, const std::nothrow_t&) noexcept {
__TBB_EXPORT void* operator new(size_t sz, const std::nothrow_t&) noexcept {
return scalable_malloc(sz);
}
void* operator new[](std::size_t sz, const std::nothrow_t&) noexcept {
__TBB_EXPORT void* operator new[](std::size_t sz, const std::nothrow_t&) noexcept {
return scalable_malloc(sz);
}
void operator delete(void* ptr, const std::nothrow_t&) noexcept {
__TBB_EXPORT void operator delete(void* ptr, const std::nothrow_t&) noexcept {
InitOrigPointers();
__TBB_malloc_safer_free(ptr, (void (*)(void*))orig_free);
}
void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
__TBB_EXPORT void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
InitOrigPointers();
__TBB_malloc_safer_free(ptr, (void (*)(void*))orig_free);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tbbmalloc_proxy/proxy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2021 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@ extern "C" {
TBBMALLOC_EXPORT size_t __TBB_malloc_safer_aligned_msize( void *ptr, size_t, size_t, size_t (*orig_msize_crt80d)(void*,size_t,size_t));

#if MALLOC_ZONE_OVERLOAD_ENABLED
void __TBB_malloc_free_definite_size(void *object, size_t size);
TBBMALLOC_EXPORT void __TBB_malloc_free_definite_size(void *object, size_t size);
#endif
} // extern "C"

Expand Down
4 changes: 2 additions & 2 deletions test/tbb/test_dynamic_link.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2021 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ enum FOO_TYPE {
#if _WIN32 || _WIN64
#define TEST_EXPORT
#else
#define TEST_EXPORT extern "C"
#define TEST_EXPORT extern "C" __TBB_EXPORT
#endif /* _WIN32 || _WIN64 */

// foo "implementations".
Expand Down
4 changes: 3 additions & 1 deletion test/tbbmalloc/test_malloc_atexit.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,8 @@
#if _USRDLL
#if _WIN32||_WIN64
extern __declspec(dllexport)
#else
__TBB_EXPORT
#endif
bool dll_isMallocOverloaded()
#else
Expand Down
36 changes: 20 additions & 16 deletions test/tbbmalloc/test_malloc_lib_unload.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -23,24 +23,28 @@
const char *globalCallMsg = "A TBB allocator function call is resolved into wrong implementation.";

#if _WIN32||_WIN64
#define TEST_EXPORT __declspec(dllexport)
#else
#define TEST_EXPORT __TBB_EXPORT
#endif

// must be defined in DLL for linker to not drop the dependency on the DLL.
extern "C" {
extern __declspec(dllexport) void *scalable_malloc(size_t);
extern __declspec(dllexport) void scalable_free (void *);
extern __declspec(dllexport) void safer_scalable_free (void *, void (*)(void*));
extern __declspec(dllexport) void *scalable_realloc(void *, size_t);
extern __declspec(dllexport) void *safer_scalable_realloc(void *, size_t, void *);
extern __declspec(dllexport) void *scalable_calloc(size_t, size_t);
extern __declspec(dllexport) int scalable_posix_memalign(void **, size_t, size_t);
extern __declspec(dllexport) void *scalable_aligned_malloc(size_t, size_t);
extern __declspec(dllexport) void *scalable_aligned_realloc(void *, size_t, size_t);
extern __declspec(dllexport) void *safer_scalable_aligned_realloc(void *, size_t, size_t, void *);
extern __declspec(dllexport) void scalable_aligned_free(void *);
extern __declspec(dllexport) size_t scalable_msize(void *);
extern __declspec(dllexport) size_t safer_scalable_msize (void *, size_t (*)(void*));
extern __declspec(dllexport) int anchor();
extern TEST_EXPORT void *scalable_malloc(size_t);
extern TEST_EXPORT void scalable_free (void *);
extern TEST_EXPORT void safer_scalable_free (void *, void (*)(void*));
extern TEST_EXPORT void *scalable_realloc(void *, size_t);
extern TEST_EXPORT void *safer_scalable_realloc(void *, size_t, void *);
extern TEST_EXPORT void *scalable_calloc(size_t, size_t);
extern TEST_EXPORT int scalable_posix_memalign(void **, size_t, size_t);
extern TEST_EXPORT void *scalable_aligned_malloc(size_t, size_t);
extern TEST_EXPORT void *scalable_aligned_realloc(void *, size_t, size_t);
extern TEST_EXPORT void *safer_scalable_aligned_realloc(void *, size_t, size_t, void *);
extern TEST_EXPORT void scalable_aligned_free(void *);
extern TEST_EXPORT size_t scalable_msize(void *);
extern TEST_EXPORT size_t safer_scalable_msize (void *, size_t (*)(void*));
extern TEST_EXPORT int anchor();
}
#endif

extern "C" int anchor() {
return 42;
Expand Down
8 changes: 5 additions & 3 deletions test/tbbmalloc/test_malloc_used_by_lib.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2022 Intel Corporation
Copyright (c) 2005-2023 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -23,11 +23,13 @@
#include "common/utils_assert.h"
#include "tbb/scalable_allocator.h"

#if _WIN32||_WIN64
extern "C" {
#if _WIN32||_WIN64
extern __declspec(dllexport) void callDll();
}
#else
extern __TBB_EXPORT void callDll();
#endif
}

extern "C" void callDll()
{
Expand Down

0 comments on commit 09a6491

Please sign in to comment.