Skip to content

undefined symbol: MapViewOfFile2 #22040

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

Open
zux0x3a opened this issue Nov 20, 2024 · 14 comments · May be fixed by #23912
Open

undefined symbol: MapViewOfFile2 #22040

zux0x3a opened this issue Nov 20, 2024 · 14 comments · May be fixed by #23912
Assignees
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. libc Issues related to libzigc and Zig's vendored libc code. upstream An issue with a third party project that Zig uses.
Milestone

Comments

@zux0x3a
Copy link

zux0x3a commented Nov 20, 2024

Zig Version

0.13.0

Steps to Reproduce and Observed Output

it seems MapViewOfFile2 is not declared or linked into Zig code base yet, currently i am declaring it externally :

pub extern "kernel32" fn MapViewOfFile2(
    FileMappingHandle: HANDLE,
    ProcessHandle: HANDLE,
    Offset: u64, 
    BaseAddress: ?*anyopaque, 
    ViewSize: usize, // SIZE_T
    AllocationType: u32, // ULONG
    PageProtection: u32, // ULONG
) callconv(WINAPI) ?*anyopaque; 

raising the following linking error :

error: warning(link): unexpected LLD stderr:
lld-link: warning: undefined symbol: MapViewOfFile2

any alternative solution? if we imported the C headeand then call it from it's name space should be a temporary solution?

Expected Output

error: warning(link): unexpected LLD stderr:
lld-link: warning: undefined symbol: MapViewOfFile2

@zux0x3a zux0x3a added the error message This issue points out an error message that is unhelpful and should be improved. label Nov 20, 2024
@zux0x3a
Copy link
Author

zux0x3a commented Nov 20, 2024

@nektro
Copy link
Contributor

nektro commented Nov 20, 2024

@zux0x3a
Copy link
Author

zux0x3a commented Nov 20, 2024

@nektro I think you are referring to the following

pub extern "api-ms-win-core-memory-l1-1-5" fn UnmapViewOfFile2(
    Process: ?HANDLE,
    BaseAddress: ?*anyopaque,
    UnmapFlags: UNMAP_VIEW_OF_FILE_FLAGS,
) callconv(@import("std").os.windows.WINAPI) BOOL;

and thats limited to windows10.0.15063 check out here : https://github.com/marlersoft/zigwin32/blob/32d085ee67374ad2ec24fc012e6876ca27958fb7/win32/system/memory.zig#L1098

@mesidex
Copy link

mesidex commented Nov 24, 2024

As a workaround, does NtMapViewOfSection suit your use case?

pub extern "ntdll" fn NtMapViewOfSection(

@zux0x3a
Copy link
Author

zux0x3a commented Nov 24, 2024

@mesidex NtMapViewofSection is different than MapViewFile2, however i managed to make it work with following extern API inline call.

https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffilenuma2

pub extern "api-ms-win-core-memory-l1-1-5" fn MapViewOfFileNuma2(
    FileMappingHandle: HANDLE,
    ProcessHandle: HANDLE,
    Offset: u64, // ULONG64
    BaseAddress: ?*anyopaque, // PVOID (optional)
    ViewSize: usize, // SIZE_T
    AllocationType: u32, // ULONG
    PageProtection: u32, // ULONG
) callconv(windows.WINAPI) ?*anyopaque; // Returns PVOID

@vtorri
Copy link

vtorri commented Dec 4, 2024

I have it:

$ fgrep -r MapViewOfFile2 /mingw64/include/memoryapi.h
  WINBASEAPI PVOID MapViewOfFile2(HANDLE FileMappingHandle, HANDLE ProcessHandle, ULONG64 Offset, PVOID BaseAddress, SIZE_T ViewSize, ULONG AllocationType, ULONG PageProtection);

@alexrp
Copy link
Member

alexrp commented Apr 11, 2025

The problem is that it isn't present in any of MinGW-w64's library definition files. Someone needs to file a bug or send a patch upstream.

@alexrp alexrp added upstream An issue with a third party project that Zig uses. libc Issues related to libzigc and Zig's vendored libc code. enhancement Solving this issue will likely involve adding new logic or components to the codebase. and removed error message This issue points out an error message that is unhelpful and should be improved. labels Apr 11, 2025
@vtorri
Copy link

vtorri commented Apr 11, 2025

I use mingw since around 2008, and there is no problem with this function. mingw-w64 provides the header files and the import libraries. The DLL is in the system. I used it for example in the EFL and I compile on Windows and cross compile on linux without any problem

@alexrp
Copy link
Member

alexrp commented Apr 11, 2025

The only occurrence of MapViewOfFile2 in the MinGW-w64 source tree is in mingw-w64-headers/include/memoryapi.h. I don't see it mentioned in any of the import libraries.

@leecannon
Copy link
Contributor

From MSDN:

This function is implemented as an inline function in the header and can't be found in any export library or DLL. It's the same as calling MapViewOfFileNuma2 with the last parameter set to NUMA_NO_PREFERRED_NODE.

@alexrp
Copy link
Member

alexrp commented Apr 11, 2025

Ah, I wasn't aware of that detail. Then this still looks like a MinGW-w64 bug, because it declares MapViewOfFile2 in memoryapi.h but does not define it anywhere, inline or otherwise.

@vtorri
Copy link

vtorri commented Apr 11, 2025

that's how it is defined in the visual studio SDK. I've just reported this to the mingw-w64 devs and one of them told me that he will fix it soon

@zux0x3a
Copy link
Author

zux0x3a commented Apr 11, 2025

@alexrp @vtorri I don't think it is an issue with mingw-w64 while it is working perfectly if you depend on cc compiler. the issue that there is no binding for this specific API call because it is inline function which i fixed in previous extern inline call. it can be fixed by ziglang and not in mingw64

@vtorri
Copy link

vtorri commented Apr 12, 2025

mingw-w64/mingw-w64@c67e9a7

at least, other people who need MapViewOfFile2() will be able to use it

@alexrp alexrp added this to the 0.15.0 milestone Apr 12, 2025
@alexrp alexrp self-assigned this May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. libc Issues related to libzigc and Zig's vendored libc code. upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants