Skip to content

[llvm] DLLExport llvm::allocate_buffer and llvm::deallocate_buffer #127856

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

Closed
wants to merge 1 commit into from

Conversation

andrurogerz
Copy link
Contributor

@andrurogerz andrurogerz commented Feb 19, 2025

Overview

Annotate the llvm::allocate_buffer and llvm::deallocate_buffer functions so they are explicitly included in LLVM's public interface. When building LLVM as a Windows DLL, this annotation exports them from the DLL.

Background

This change is required as part of the overall project to build LLVM as a Windows DLL described in #109483. Without this change, LLVM tools fail to link.

Validation

Built LLVM with MSVC on Windows 11:

cmake -B build -S llvm -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB_VIS=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCLANG_LINK_CLANG_DYLIB=ON
ninja -C build llvm-rc llvm-ar

Verified the annotated interface no longer appears in the list of unresolved external symbols.

@andrurogerz andrurogerz marked this pull request as ready for review February 19, 2025 21:57
@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/pr-subscribers-llvm-support

Author: Andrew Rogers (andrurogerz)

Changes

Overview

Annotate the llvm::allocate_buffer and llvm::deallocate_buffer function` so they are explicitly included in LLVM's public interface. When building LLVM as a Windows DLL, this annotation exports them from the DLL.

Background

This change is required as part of the overall project to build LLVM as a Windows DLL described in #109483. Without this change, LLVM tools fail to link.

Validation

Built LLVM with MSVC on Windows 11:

cmake -B build -S llvm -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB_VIS=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCLANG_LINK_CLANG_DYLIB=ON
ninja -C build llvm-rc llvm-ar

Verified the annotated interface no longer appears in the list of unresolved external symbols.


Full diff: https://github.com/llvm/llvm-project/pull/127856.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/MemAlloc.h (+2-1)
diff --git a/llvm/include/llvm/Support/MemAlloc.h b/llvm/include/llvm/Support/MemAlloc.h
index f3f378b7697a1..19284f6e72087 100644
--- a/llvm/include/llvm/Support/MemAlloc.h
+++ b/llvm/include/llvm/Support/MemAlloc.h
@@ -71,7 +71,7 @@ LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_realloc(void *Ptr, size_t Sz) {
 /// like posix_memalign due to portability. It is mostly intended to allow
 /// compatibility with platforms that, after aligned allocation was added, use
 /// reduced default alignment.
-LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
+LLVM_ABI LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void *
 allocate_buffer(size_t Size, size_t Alignment);
 
 /// Deallocate a buffer of memory with the given size and alignment.
@@ -81,6 +81,7 @@ allocate_buffer(size_t Size, size_t Alignment);
 ///
 /// The pointer must have been allocated with the corresponding new operator,
 /// most likely using the above helper.
+LLVM_ABI
 void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment);
 
 } // namespace llvm

@andrurogerz
Copy link
Contributor Author

@compnerd, @vgvassilev

@andrurogerz andrurogerz changed the title DLLExport llvm::allocate_buffer and llvm::deallocate_buffer [llvm] DLLExport llvm::allocate_buffer and llvm::deallocate_buffer Feb 19, 2025
@nikic
Copy link
Contributor

nikic commented Feb 20, 2025

Do not submit these one by one. Consolidating on the discussion in #127850.

@nikic nikic closed this Feb 20, 2025
@andrurogerz andrurogerz deleted the DLLExport-MemAlloc branch February 26, 2025 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants