Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit cca7774

Browse files
committed
fix build for msvc/x86
1 parent 8e13687 commit cca7774

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

src/core/cpuid.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ bool hasCPUID()
845845
return true;
846846
else version(LDC) {
847847
size_t flags;
848-
asm {
848+
asm @nogc nothrow {
849849
pushf;
850850
pop EAX;
851851
mov flags, EAX;

src/ldc/eh/common.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern(C) void fatalerror(in char* format, ...)
3030
// Reading DWARF data
3131
// ------------------------
3232

33-
version (Win64) {} else
33+
version (CRuntime_Microsoft) {} else
3434
{
3535
extern(C)
3636
{
@@ -195,15 +195,15 @@ ubyte* get_encoded_value(ubyte* addr, ref size_t res, ubyte encoding, void* cont
195195
res += cast(size_t)old_addr;
196196
break;
197197
case _DW_EH_Format.DW_EH_PE_funcrel:
198-
version(Win64) fatalerror("Not yet implemented."); else
198+
version(CRuntime_Microsoft) fatalerror("Not yet implemented."); else
199199
res += cast(size_t)_Unwind_GetRegionStart(context);
200200
break;
201201
case _DW_EH_Format.DW_EH_PE_textrel:
202-
version(Win64) fatalerror("Not yet implemented."); else
202+
version(CRuntime_Microsoft) fatalerror("Not yet implemented."); else
203203
res += cast(size_t)_Unwind_GetTextRelBase(context);
204204
break;
205205
case _DW_EH_Format.DW_EH_PE_datarel:
206-
version(Win64) fatalerror("Not yet implemented."); else
206+
version(CRuntime_Microsoft) fatalerror("Not yet implemented."); else
207207
res += cast(size_t)_Unwind_GetDataRelBase(context);
208208
break;
209209
default:
@@ -231,7 +231,7 @@ ptrdiff_t get_base_of_encoded_value(ubyte encoding, void* context)
231231
case DW_EH_PE_aligned:
232232
return 0;
233233

234-
version(Win64) {} else
234+
version(CRuntime_Microsoft) {} else
235235
{
236236
case DW_EH_PE_textrel:
237237
return _Unwind_GetTextRelBase (context);

src/rt/sections_ldc.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private
9696
Section(SEG_DATA, SECT_COMMON)
9797
];
9898
}
99-
else version (Win64)
99+
else version (CRuntime_Microsoft)
100100
{
101101
extern extern (C) __gshared
102102
{
@@ -371,7 +371,7 @@ void initSections()
371371
}
372372
_dyld_register_func_for_add_image(&scanSections);
373373
}
374-
else version (Win64)
374+
else version (CRuntime_Microsoft)
375375
{
376376
pushRange(_data_start__, _data_end__);
377377
if (_bss_start__ != null)

src/rt/stdio_msvc.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,20 @@ int _set_output_format(int format); // VS2013-
3636
//extern const char* __acrt_iob_func;
3737
extern const char* _nullfunc = 0;
3838

39-
#pragma comment(linker, "/alternatename:__acrt_iob_func=_nullfunc")
40-
#pragma comment(linker, "/alternatename:__iob_func=_nullfunc")
41-
#pragma comment(linker, "/alternatename:_set_output_format=_nullfunc")
39+
#if defined _M_IX86
40+
#define C_PREFIX "_"
41+
#elif defined _M_X64 || defined _M_ARM || defined _M_ARM64
42+
#define C_PREFIX ""
43+
#else
44+
#error Unsupported architecture
45+
#endif
46+
47+
#define DECLARE_ALTERNATE_NAME(name, alternate_name) \
48+
__pragma(comment(linker, "/alternatename:" C_PREFIX #name "=" C_PREFIX #alternate_name))
49+
50+
DECLARE_ALTERNATE_NAME (__acrt_iob_func, _nullfunc);
51+
DECLARE_ALTERNATE_NAME (__iob_func, _nullfunc);
52+
DECLARE_ALTERNATE_NAME (_set_output_format, _nullfunc);
4253

4354
void init_msvc()
4455
{
@@ -65,25 +76,25 @@ void init_msvc()
6576
// VS2015+ provides C99-conformant (v)snprintf functions, so weakly
6677
// link to legacy _(v)snprintf (not C99-conformant!) for VS2013- only
6778

68-
#pragma comment(linker, "/alternatename:snprintf=_snprintf")
69-
#pragma comment(linker, "/alternatename:vsnprintf=_vsnprintf")
79+
DECLARE_ALTERNATE_NAME (snprintf, _snprintf);
80+
DECLARE_ALTERNATE_NAME (vsnprintf, _vsnprintf);
7081

7182
// VS2013- implements these functions as macros, VS2015+ provides symbols
7283

73-
#pragma comment(linker, "/alternatename:_fputc_nolock=_msvc_fputc_nolock")
74-
#pragma comment(linker, "/alternatename:_fgetc_nolock=_msvc_fgetc_nolock")
75-
#pragma comment(linker, "/alternatename:rewind=_msvc_rewind")
76-
#pragma comment(linker, "/alternatename:clearerr=_msvc_clearerr")
77-
#pragma comment(linker, "/alternatename:feof=_msvc_feof")
78-
#pragma comment(linker, "/alternatename:ferror=_msvc_ferror")
79-
#pragma comment(linker, "/alternatename:fileno=_msvc_fileno")
84+
DECLARE_ALTERNATE_NAME (_fputc_nolock, _msvc_fputc_nolock);
85+
DECLARE_ALTERNATE_NAME (_fgetc_nolock, _msvc_fgetc_nolock);
86+
DECLARE_ALTERNATE_NAME (rewind, _msvc_rewind);
87+
DECLARE_ALTERNATE_NAME (clearerr, _msvc_clearerr);
88+
DECLARE_ALTERNATE_NAME (feof, _msvc_feof);
89+
DECLARE_ALTERNATE_NAME (ferror, _msvc_ferror);
90+
DECLARE_ALTERNATE_NAME (fileno, _msvc_fileno);
8091

8192
// VS2013- helper functions
8293
int _filbuf(FILE* fp);
8394
int _flsbuf(int c, FILE* fp);
8495

85-
#pragma comment(linker, "/alternatename:_filbuf=_nullfunc")
86-
#pragma comment(linker, "/alternatename:_flsbuf=_nullfunc")
96+
DECLARE_ALTERNATE_NAME(_filbuf, _nullfunc);
97+
DECLARE_ALTERNATE_NAME(_flsbuf, _nullfunc);
8798

8899
int _msvc_fputc_nolock(int c, FILE* fp)
89100
{

0 commit comments

Comments
 (0)