Skip to content

strdup missing dllimport declaration (Windows) #12948

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
vikhik opened this issue May 4, 2025 · 6 comments · Fixed by #12951
Closed

strdup missing dllimport declaration (Windows) #12948

vikhik opened this issue May 4, 2025 · 6 comments · Fixed by #12951
Assignees
Milestone

Comments

@vikhik
Copy link

vikhik commented May 4, 2025

Running clang-tidy with a reasonably "default" (based on llvm) set of checks on the clear renderer sample gives this:

D:/dev/proj/build/Windows/_deps/sdl3-src/include\SDL3/SDL_stdinc.h:5966:7: error: 'strdup' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [clang-diagnostic-inconsistent-dllimport]
 5966 | char *strdup(const char *str);
      |       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:532:28: note: previous declaration is here
  532 |     _ACRTIMP char* __cdecl strdup(
      |                            ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:532:5: note: previous attribute is here
  532 |     _ACRTIMP char* __cdecl strdup(
      |     ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:136:37: note: expanded from macro '_ACRTIMP'
  136 |         #define _ACRTIMP __declspec(dllimport)
      |                                     ^
@vikhik vikhik changed the title strdup missing dllimport declaration strdup missing dllimport declaration (Windows) May 4, 2025
@slouken slouken added this to the 3.x milestone May 4, 2025
@slouken slouken modified the milestones: 3.x, 3.4.0 May 4, 2025
@madebr
Copy link
Contributor

madebr commented May 4, 2025

SDL/include/SDL3/SDL_stdinc.h

Lines 5955 to 6023 in 15c6acf

/* force builds using Clang's static analysis tools to use literal C runtime
here, since there are possibly tests that are ineffective otherwise. */
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
/* The analyzer knows about strlcpy even when the system doesn't provide it */
#if !defined(HAVE_STRLCPY) && !defined(strlcpy)
size_t strlcpy(char *dst, const char *src, size_t size);
#endif
/* The analyzer knows about strlcat even when the system doesn't provide it */
#if !defined(HAVE_STRLCAT) && !defined(strlcat)
size_t strlcat(char *dst, const char *src, size_t size);
#endif
#if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
#endif
#if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
#endif
/* strdup is not ANSI but POSIX, and its prototype might be hidden... */
char *strdup(const char *str);
/* Starting LLVM 16, the analyser errors out if these functions do not have
their prototype defined (clang-diagnostic-implicit-function-declaration) */
#include <stdio.h>
#include <stdlib.h>
#define SDL_malloc malloc
#define SDL_calloc calloc
#define SDL_realloc realloc
#define SDL_free free
#ifndef SDL_memcpy
#define SDL_memcpy memcpy
#endif
#ifndef SDL_memmove
#define SDL_memmove memmove
#endif
#ifndef SDL_memset
#define SDL_memset memset
#endif
#define SDL_memcmp memcmp
#define SDL_strlcpy strlcpy
#define SDL_strlcat strlcat
#define SDL_strlen strlen
#define SDL_wcslen wcslen
#define SDL_wcslcpy wcslcpy
#define SDL_wcslcat wcslcat
#define SDL_strdup strdup
#define SDL_wcsdup wcsdup
#define SDL_strchr strchr
#define SDL_strrchr strrchr
#define SDL_strstr strstr
#define SDL_wcsstr wcsstr
#define SDL_strtok_r strtok_r
#define SDL_strcmp strcmp
#define SDL_wcscmp wcscmp
#define SDL_strncmp strncmp
#define SDL_wcsncmp wcsncmp
#define SDL_strcasecmp strcasecmp
#define SDL_strncasecmp strncasecmp
#define SDL_strpbrk strpbrk
#define SDL_sscanf sscanf
#define SDL_vsscanf vsscanf
#define SDL_snprintf snprintf
#define SDL_vsnprintf vsnprintf
#endif

I'd remove our declarations and do #include <string.h> when using __clang_analyzer__.
What do you think @sezero?

@sezero
Copy link
Contributor

sezero commented May 4, 2025

string.h is already included, as the error message shows. The problem is with our prototype, which was added to fix #11219, conflicting with the one in string.h.

@sezero
Copy link
Contributor

sezero commented May 4, 2025

One thing I can think of is removing our proto, but defining prerequite macros (_GNU_SOURCE? __POSIX_C_SOURCE?? whatever) to ensure strdup prototype is visible from string.h when in clang-analyzer mode.

@sezero
Copy link
Contributor

sezero commented May 4, 2025

One thing I can think of is removing our proto, but defining prerequite macros (_GNU_SOURCE? __POSIX_C_SOURCE?? whatever) to ensure strdup prototype is visible from string.h when in clang-analyzer mode.

Thinking about it, that would require definig the necessary macro(s) before including any system headers, just because of this.

How about just guarding our prototype simply with #ifndef _WIN32 ?

@madebr
Copy link
Contributor

madebr commented May 4, 2025

How about just guarding our prototype simply with #ifndef _WIN32 ?

That seems fine to me. (I don't understand the problem well enough.)

From #11219 (comment), @Sackzement was also running into this problem. Would this fix the problem for you too? (without needing a SDL_DISABLE_ANALYZE_MACROS macro)

@sezero
Copy link
Contributor

sezero commented May 4, 2025

Pull request: #12951

@slouken slouken closed this as completed in 17bba02 May 4, 2025
slouken pushed a commit that referenced this issue May 4, 2025
sezero added a commit that referenced this issue May 4, 2025
sezero added a commit that referenced this issue May 4, 2025
Hancock33 added a commit to Hancock33/batocera.piboy that referenced this issue May 5, 2025
---------------------------------------------------------------------------------------
applewin.mk ae55d5cb42ab17a4ad0b7a541a88a764b38505b4 # Version: Commits on May 04, 2025
---------------------------------------------------------------------------------------
Merge pull request #267 from audetto/update

Update,

-------------------------------------------------------------------------------------
azahar.mk d31ff9634f67c17629009de31e4ce42637b3bb12 # Version: Commits on May 04, 2025
-------------------------------------------------------------------------------------
skip VerifySignature and no delete on unlink,

-----------------------------------------------------------------------------------
cemu.mk 33d5c6d490681b49f447c9a3e94c5451b241aba1 # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------
nsyshid: Add Skylander Xbox 360 Portal support (#1550),

--------------------------------------------------------------------------------------
flycast.mk 7538424efb8c184df89f0211ab3d2f42e7898a96 # Version: Commits on May 04, 2025
--------------------------------------------------------------------------------------
cheat to allow The Next Tetris online features

Bypass check of modulation type and rx/tx speeds.,

-------------------------------------------------------------------------------------
hatari.mk 74be26203c3c39f319a48cf692856b7bd6751c02 # Version: Commits on May 04, 2025
-------------------------------------------------------------------------------------
Remove CYCLES_COUNTER_SOUND and CYCLES_COUNTER_CPU (not used anymore),

-----------------------------------------------------------------------------------------
lightspark.mk 1a2ab29b9df24b3c46506434f9f4f1dfd5c0095c # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------------
[BitmapData] ensure data is refreshed before calling getPixel/getPixel32

makes ruffle test avm1/bitmap_data pass again,

--------------------------------------------------------------------------------------
openmsx.mk 4be6da399801c1b1969053645723904b65ce005f # Version: Commits on May 04, 2025
--------------------------------------------------------------------------------------
Fix indent of new View Only mode checkbox.

Oops, I missed this. Thanks to Wouter for spotting it.,

----------------------------------------------------
pcsx2.mk v2.3.322 # Version: Commits on May 04, 2025
----------------------------------------------------
- [Audio: Fix global settings overriding per-game ones](PCSX2/pcsx2#12593)

------------------------------------------------------------------------------------
rpcs3.mk 4958d7a88f36512c65fd81d153be4520404da01a # Version: Commits on May 04, 2025
------------------------------------------------------------------------------------
rsx: Do not interpolate when performing image reconstruction

- Interpolation introduces cross-channel bit-leakage and noise,

--------------------------------------------------------------------------------------
scummvm.mk 8c678695c8795de8b98f5f7e1a42f43e86a80286 # Version: Commits on May 04, 2025
--------------------------------------------------------------------------------------
NEWS: Atari changes for 2.9.1,

---------------------------------------------------------
sdl3.mk release-3.2.12 # Version: Commits on May 04, 2025
---------------------------------------------------------
don't prototype strdup() for __clang_analyzer__ case in windows builds.

Fixes:  libsdl-org/SDL#12948.

(cherry picked from commit 17bba029ba6717c3da460a2426fd81fd2772f66f),

---------------------------------------------------------------------------------------
corsixth.mk ceb7cdab072c5934207e1c5779f6934345913fa9 # Version: Commits on May 04, 2025
---------------------------------------------------------------------------------------
Merge pull request #2824 from Alberth289346/marker-split-add-and-improve

Marker split add and improve,

-------------------------------------------------------------------------------------------
jazz2-native.mk 3eabfba6e60a4a5f6c1738bd480286e5fdbfbaea # Version: Commits on May 04, 2025
-------------------------------------------------------------------------------------------
Fixed build,

----------------------------------------------------------------------------------------
openmohaa.mk 1d7d7deaeda3367b88933a88ec619648cf41d190 # Version: Commits on May 04, 2025
----------------------------------------------------------------------------------------
Set the default mode to -2.

-2 makes the game use the current desktop resolution.,

------------------------------------------------------------------------------------------
openbor7530.mk 19e2edebba97243a1a00f7f578401d02717e539e # Version: Commits on May 04, 2025
------------------------------------------------------------------------------------------
Merge pull request #332 from DCurrent/legacy_compile_fix

Legacy compile fix.,

-----------------------------------------------------------------------------------------
libdmdutil.mk 9ff1d0f238fe6859008dd5c716e0c742931b46cc # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------------
flush dump files before closing (#75),

-----------------------------------------------------
libserum.mk v2.0.3 # Version: Commits on May 04, 2025
-----------------------------------------------------
Bug fix: The bounding box for sprites was not working on both sides (left and right, top and bottom) if needed

-----------------------------------------------------------------------------------
tr1x.mk 0351429d87af2c0d7b54e84654dd51a8777f4ee6 # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------
rooms: merge NO_ROOM definitions

This merges the two NO_ROOM concepts so -1 is the standard. Legacy

sector pit and sky portals will be converted on level load. This

ultimately paves the way for allowing more than 256 rooms in a level

via alternate sector data provided by injections (to be implemented).,

-----------------------------------------------------------------------------------
tr2x.mk 0351429d87af2c0d7b54e84654dd51a8777f4ee6 # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------
rooms: merge NO_ROOM definitions

This merges the two NO_ROOM concepts so -1 is the standard. Legacy

sector pit and sky portals will be converted on level load. This

ultimately paves the way for allowing more than 256 rooms in a level

via alternate sector data provided by injections (to be implemented).,

-----------------------------------------------------------------------------------------------
hlsdk-xash3d-dmc.mk 57ecdef06d4b58a3bcd9ad0e5aa65f534da73012 # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------------------
Use safe string functions.,

---------------------------------------------------------------------------------------------------
hlsdk-xash3d-zombiex.mk 08cd1b5926decd91e5395d5d011729bb5c813fa0 # Version: Commits on May 04, 2025
---------------------------------------------------------------------------------------------------
Merge branch 'sohl1.2' into zombie-x,

-----------------------------------------------------------------------------------------------
libretro-flycast.mk 7538424efb8c184df89f0211ab3d2f42e7898a96 # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------------------
cheat to allow The Next Tetris online features

Bypass check of modulation type and rx/tx speeds.,

-----------------------------------------------------------------------------------------------
libretro-scummvm.mk 8c678695c8795de8b98f5f7e1a42f43e86a80286 # Version: Commits on May 04, 2025
-----------------------------------------------------------------------------------------------
NEWS: Atari changes for 2.9.1,

---------------------------------------------------------------------------------------------
libretro-vba-m.mk 116af5c6a857dbf599fe06fa17fd6aa4951deb1a # Version: Commits on May 04, 2025
---------------------------------------------------------------------------------------------
build: replace sdl2 vcpkg port with sdl3

Signed-off-by: Rafael Kitover <[email protected]>,

--------------------------------------------------------------------------------------------
slang-shaders.mk 3a0feed2547c21061ff32e22ff7aad128dbd3ce8 # Version: Commits on May 04, 2025
--------------------------------------------------------------------------------------------
Update Interpolation folder (#701),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants