Skip to content

Add linker map and .def file #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,39 @@ jobs:
pool_tracking: ['ON', 'OFF']
shared_library: ['OFF']
sanitizers: [{asan: OFF}]
os_provider: ['ON']
include:
- os: 'windows-2022'
build_type: Release
compiler: {c: clang-cl, cxx: clang-cl}
pool_tracking: 'ON'
os_provider: 'ON'
toolset: "-T ClangCL"
- os: 'windows-2022'
build_type: Release
compiler: {c: cl, cxx: cl}
pool_tracking: 'ON'
shared_library: 'ON'
os_provider: 'ON'
- os: 'windows-2022'
build_type: Release
compiler: {c: cl, cxx: cl}
pool_tracking: 'ON'
shared_library: 'ON'
os_provider: 'OFF'
- os: 'windows-2022'
build_type: Debug
compiler: {c: cl, cxx: cl}
pool_tracking: 'OFF'
shared_library: 'OFF'
os_provider: 'ON'
sanitizers: {asan: ON}
- os: 'windows-2022'
build_type: Debug
compiler: {c: clang-cl, cxx: clang-cl}
pool_tracking: 'OFF'
shared_library: 'OFF'
os_provider: 'ON'
sanitizers: {asan: ON}

runs-on: ${{matrix.os}}
Expand Down Expand Up @@ -261,6 +272,7 @@ jobs:
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
-DUSE_ASAN=${{matrix.sanitizers.asan}}
-DUMF_BUILD_OS_MEMORY_PROVIDER=${{matrix.os_provider}}

- name: Build UMF
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS
Expand Down
4 changes: 3 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

include(FindThreads)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(WARNING "The ubench SHOULD NOT be run in the Debug build type!")
endif()
Expand Down Expand Up @@ -29,7 +31,7 @@ target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
target_link_libraries(ubench
umf
${LIBS_OPTIONAL}
pthread
${CMAKE_THREAD_LIBS_INIT}
m)

if (UMF_BUILD_OS_MEMORY_PROVIDER)
Expand Down
21 changes: 20 additions & 1 deletion cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,33 @@ endfunction()
function(add_umf_library)
# NAME - a name of the library
# TYPE - type of the library (shared or static)
# if shared library, LINUX_MAP_FILE and WINDOWS_DEF_FILE must also be specified
# SRCS - source files
# LIBS - libraries to be linked with
set(oneValueArgs NAME TYPE)
# LINUX_MAP_FILE - path to linux linker map (.map) file
# WINDOWS_DEF_FILE - path to windows module-definition (DEF) file

set(oneValueArgs NAME TYPE LINUX_MAP_FILE WINDOWS_DEF_FILE)
set(multiValueArgs SRCS LIBS)
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

add_library(${ARG_NAME} ${ARG_TYPE} ${ARG_SRCS})

string(TOUPPER "${ARG_TYPE}" ARG_TYPE)
if(ARG_TYPE STREQUAL "SHARED")
if(NOT ARG_LINUX_MAP_FILE OR NOT ARG_WINDOWS_DEF_FILE)
message(FATAL_ERROR "LINUX_MAP_FILE or WINDOWS_DEF_FILE not specified")
endif()

if (WINDOWS)
target_link_options(${ARG_NAME} PRIVATE /DEF:${ARG_WINDOWS_DEF_FILE})
else()
target_link_options(${ARG_NAME} PRIVATE "-Wl,--version-script=${ARG_LINUX_MAP_FILE}")
endif()
endif()

target_link_libraries(${ARG_NAME} PRIVATE ${ARG_LIBS})

target_include_directories(${ARG_NAME} PRIVATE
${UMF_CMAKE_SOURCE_DIR}/include
${UMF_CMAKE_SOURCE_DIR}/src/base_alloc)
Expand Down
6 changes: 0 additions & 6 deletions include/umf/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
extern "C" {
#endif

#if defined(_WIN32) && defined(UMF_SHARED_LIBRARY)
#define UMF_EXPORT __declspec(dllexport)
#else
#define UMF_EXPORT
#endif

/// @brief Generates generic 'UMF' API versions
#define UMF_MAKE_VERSION(_major, _minor) \
((_major << 16) | (_minor & 0x0000ffff))
Expand Down
39 changes: 17 additions & 22 deletions include/umf/memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,24 @@ typedef enum umf_pool_create_flag_t {
/// @param hPool [out] handle to the newly created memory pool
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
///
UMF_EXPORT umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
umf_memory_provider_handle_t provider,
void *params,
umf_pool_create_flags_t flags,
umf_memory_pool_handle_t *hPool);
umf_result_t umfPoolCreate(const umf_memory_pool_ops_t *ops,
umf_memory_provider_handle_t provider, void *params,
umf_pool_create_flags_t flags,
umf_memory_pool_handle_t *hPool);

///
/// @brief Destroys memory pool.
/// @param hPool handle to the pool
///
UMF_EXPORT void umfPoolDestroy(umf_memory_pool_handle_t hPool);
void umfPoolDestroy(umf_memory_pool_handle_t hPool);

///
/// @brief Allocates \p size bytes of uninitialized storage from \p hPool
/// @param hPool specified memory hPool
/// @param size number of bytes to allocate
/// @return Pointer to the allocated memory.
///
UMF_EXPORT void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);

///
/// @brief Allocates \p size bytes of uninitialized storage from the specified \p hPool
Expand All @@ -80,8 +79,8 @@ UMF_EXPORT void *umfPoolMalloc(umf_memory_pool_handle_t hPool, size_t size);
/// @param alignment alignment of the allocation in bytes
/// @return Pointer to the allocated memory
///
UMF_EXPORT void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool,
size_t size, size_t alignment);
void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool, size_t size,
size_t alignment);

///
/// @brief Allocates memory from \p hPool for an array of \p num elements
Expand All @@ -92,8 +91,7 @@ UMF_EXPORT void *umfPoolAlignedMalloc(umf_memory_pool_handle_t hPool,
/// @param size number of bytes to allocate for each object
/// @return Pointer to the allocated memory
///
UMF_EXPORT void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num,
size_t size);
void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num, size_t size);

///
/// @brief Reallocates memory from \p hPool
Expand All @@ -102,17 +100,15 @@ UMF_EXPORT void *umfPoolCalloc(umf_memory_pool_handle_t hPool, size_t num,
/// @param size new size for the memory block in bytes
/// @return Pointer to the allocated memory
///
UMF_EXPORT void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr,
size_t size);
void *umfPoolRealloc(umf_memory_pool_handle_t hPool, void *ptr, size_t size);

///
/// @brief Obtains size of block of memory allocated from the \p hPool for a given \p ptr
/// @param hPool specified memory hPool
/// @param ptr pointer to the allocated memory
/// @return size of the memory block allocated from the \p hPool
///
UMF_EXPORT size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool,
void *ptr);
size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool, void *ptr);

///
/// @brief Frees the memory space of the specified \p hPool pointed by \p ptr
Expand All @@ -122,7 +118,7 @@ UMF_EXPORT size_t umfPoolMallocUsableSize(umf_memory_pool_handle_t hPool,
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
/// depends on the memory provider used by the \p hPool.
///
UMF_EXPORT umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);

///
/// @brief Frees the memory space pointed by ptr if it belongs to UMF pool, does nothing otherwise.
Expand All @@ -131,7 +127,7 @@ UMF_EXPORT umf_result_t umfPoolFree(umf_memory_pool_handle_t hPool, void *ptr);
/// Whether any status other than UMF_RESULT_SUCCESS can be returned
/// depends on the memory provider used by the pool.
///
UMF_EXPORT umf_result_t umfFree(void *ptr);
umf_result_t umfFree(void *ptr);

///
/// @brief Retrieve \p umf_result_t representing the error of the last failed allocation
Expand All @@ -151,16 +147,15 @@ UMF_EXPORT umf_result_t umfFree(void *ptr);
/// @return Error code desciribng the failure of the last failed allocation operation.
/// The value is undefined if the previous allocation was successful.
///
UMF_EXPORT umf_result_t
umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);
umf_result_t umfPoolGetLastAllocationError(umf_memory_pool_handle_t hPool);

///
/// @brief Retrieve memory pool associated with a given ptr. Only memory allocated
/// with the usage of a memory provider is being tracked.
/// @param ptr pointer to memory belonging to a memory pool
/// @return Handle to a memory pool that contains ptr or NULL if pointer does not belong to any UMF pool.
///
UMF_EXPORT umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);

///
/// @brief Retrieve memory provider associated with a given pool.
Expand All @@ -169,8 +164,8 @@ UMF_EXPORT umf_memory_pool_handle_t umfPoolByPtr(const void *ptr);
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
/// UMF_RESULT_ERROR_INVALID_ARGUMENT if hProvider is NULL
///
UMF_EXPORT umf_result_t umfPoolGetMemoryProvider(
umf_memory_pool_handle_t hPool, umf_memory_provider_handle_t *hProvider);
umf_result_t umfPoolGetMemoryProvider(umf_memory_pool_handle_t hPool,
umf_memory_provider_handle_t *hProvider);

#ifdef __cplusplus
}
Expand Down
51 changes: 25 additions & 26 deletions include/umf/memory_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t;
/// @param hProvider [out] pointer to the newly created memory provider
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
///
UMF_EXPORT umf_result_t
umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, void *params,
umf_memory_provider_handle_t *hProvider);
umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
void *params,
umf_memory_provider_handle_t *hProvider);

///
/// @brief Destroys memory provider.
/// @param hProvider handle to the memory provider
///
UMF_EXPORT void
umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);

///
/// @brief Allocates \p size bytes of uninitialized storage from memory \p hProvider
Expand All @@ -47,9 +46,8 @@ umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider);
/// @param ptr [out] pointer to the allocated memory
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
///
UMF_EXPORT umf_result_t
umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider, size_t size,
size_t alignment, void **ptr);
umf_result_t umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider,
size_t size, size_t alignment, void **ptr);

///
/// @brief Frees the memory space pointed by \p ptr from the memory \p hProvider
Expand All @@ -58,8 +56,8 @@ umfMemoryProviderAlloc(umf_memory_provider_handle_t hProvider, size_t size,
/// @param size size of the allocation
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
///
UMF_EXPORT umf_result_t umfMemoryProviderFree(
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
umf_result_t umfMemoryProviderFree(umf_memory_provider_handle_t hProvider,
void *ptr, size_t size);

///
/// @brief Retrieve string representation of the underlying provider specific
Expand All @@ -85,9 +83,9 @@ UMF_EXPORT umf_result_t umfMemoryProviderFree(
/// result in string representation
/// @param pError [out] pointer to an integer where the adapter specific error code will be stored
///
UMF_EXPORT void
umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
const char **ppMessage, int32_t *pError);
void umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
const char **ppMessage,
int32_t *pError);

///
/// @brief Retrieve recommended page size for a given allocation size.
Expand All @@ -96,8 +94,9 @@ umfMemoryProviderGetLastNativeError(umf_memory_provider_handle_t hProvider,
/// @param pageSize [out] pointer to the recommended page size
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
///
UMF_EXPORT umf_result_t umfMemoryProviderGetRecommendedPageSize(
umf_memory_provider_handle_t hProvider, size_t size, size_t *pageSize);
umf_result_t
umfMemoryProviderGetRecommendedPageSize(umf_memory_provider_handle_t hProvider,
size_t size, size_t *pageSize);

///
/// @brief Retrieve minimum possible page size used by memory region referenced by a given \p ptr
Expand All @@ -107,8 +106,9 @@ UMF_EXPORT umf_result_t umfMemoryProviderGetRecommendedPageSize(
/// @param pageSize [out] pointer to the minimum possible page size
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
///
UMF_EXPORT umf_result_t umfMemoryProviderGetMinPageSize(
umf_memory_provider_handle_t hProvider, void *ptr, size_t *pageSize);
umf_result_t
umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider,
void *ptr, size_t *pageSize);

///
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr
Expand All @@ -120,8 +120,8 @@ UMF_EXPORT umf_result_t umfMemoryProviderGetMinPageSize(
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
///
UMF_EXPORT umf_result_t umfMemoryProviderPurgeLazy(
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
void *ptr, size_t size);

///
/// @brief Discard physical pages within the virtual memory mapping associated at the given addr and \p size.
Expand All @@ -133,16 +133,15 @@ UMF_EXPORT umf_result_t umfMemoryProviderPurgeLazy(
/// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
/// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
///
UMF_EXPORT umf_result_t umfMemoryProviderPurgeForce(
umf_memory_provider_handle_t hProvider, void *ptr, size_t size);
umf_result_t umfMemoryProviderPurgeForce(umf_memory_provider_handle_t hProvider,
void *ptr, size_t size);

///
/// @brief Retrieve name of a given memory \p hProvider.
/// @param hProvider handle to the memory provider
/// @return pointer to a string containing the name of the \p hProvider
///
UMF_EXPORT const char *
umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
const char *umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);

///
/// @brief Retrieve handle to the last memory provider that returned status other
Expand All @@ -154,7 +153,7 @@ umfMemoryProviderGetName(umf_memory_provider_handle_t hProvider);
///
/// @return Handle to the memory provider
///
UMF_EXPORT umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);

///
/// @brief Splits a coarse grain allocation into 2 adjacent allocations that
Expand All @@ -166,7 +165,7 @@ UMF_EXPORT umf_memory_provider_handle_t umfGetLastFailedMemoryProvider(void);
// has a size equal to totalSize - firstSize
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
///
UMF_EXPORT umf_result_t
umf_result_t
umfMemoryProviderAllocationSplit(umf_memory_provider_handle_t hProvider,
void *ptr, size_t totalSize, size_t firstSize);

Expand All @@ -180,7 +179,7 @@ umfMemoryProviderAllocationSplit(umf_memory_provider_handle_t hProvider,
/// to the sum of sizes of allocations beginning at lowPtr and highPtr
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
///
UMF_EXPORT umf_result_t
umf_result_t
umfMemoryProviderAllocationMerge(umf_memory_provider_handle_t hProvider,
void *lowPtr, void *highPtr, size_t totalSize);

Expand Down
2 changes: 1 addition & 1 deletion include/umf/pools/pool_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
extern "C" {
#endif

UMF_EXPORT umf_memory_pool_ops_t *umfProxyPoolOps(void);
umf_memory_pool_ops_t *umfProxyPoolOps(void);

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ if(UMF_BUILD_SHARED_LIBRARY)
add_umf_library(NAME umf
TYPE SHARED
SRCS ${UMF_SOURCES}
LIBS ${UMF_LIBS})
LIBS ${UMF_LIBS}
LINUX_MAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.map
WINDOWS_DEF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libumf.def)
target_compile_definitions(umf PUBLIC UMF_SHARED_LIBRARY)
set_target_properties(umf PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_UMF_OUTPUT_DIRECTORY})
Expand Down
Loading