Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
ms32coff: add "_" to alternate symbol name declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers committed Aug 29, 2015
1 parent e054ff2 commit de0e1e1
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/rt/stdio_msvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ int _set_output_format(int format); // VS2013-
//extern const char* __acrt_iob_func;
extern const char* _nullfunc = 0;

#pragma comment(linker, "/alternatename:__acrt_iob_func=_nullfunc")
#pragma comment(linker, "/alternatename:__iob_func=_nullfunc")
#pragma comment(linker, "/alternatename:_set_output_format=_nullfunc")
#if defined _M_IX86
#define C_PREFIX "_"
#elif defined _M_X64 || defined _M_ARM || defined _M_ARM64
#define C_PREFIX ""
#else
#error Unsupported architecture
#endif

#define DECLARE_ALTERNATE_NAME(name, alternate_name) \
__pragma(comment(linker, "/alternatename:" C_PREFIX #name "=" C_PREFIX #alternate_name))

DECLARE_ALTERNATE_NAME ("__acrt_iob_func", "_nullfunc");
DECLARE_ALTERNATE_NAME ("__iob_func", "_nullfunc");
DECLARE_ALTERNATE_NAME ("_set_output_format", "_nullfunc");

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

#pragma comment(linker, "/alternatename:snprintf=_snprintf")
#pragma comment(linker, "/alternatename:vsnprintf=_vsnprintf")
DECLARE_ALTERNATE_NAME ("snprintf", "_snprintf");
DECLARE_ALTERNATE_NAME ("vsnprintf", "_vsnprintf");

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

#pragma comment(linker, "/alternatename:_fputc_nolock=_msvc_fputc_nolock")
#pragma comment(linker, "/alternatename:_fgetc_nolock=_msvc_fgetc_nolock")
#pragma comment(linker, "/alternatename:rewind=_msvc_rewind")
#pragma comment(linker, "/alternatename:clearerr=_msvc_clearerr")
#pragma comment(linker, "/alternatename:feof=_msvc_feof")
#pragma comment(linker, "/alternatename:ferror=_msvc_ferror")
#pragma comment(linker, "/alternatename:fileno=_msvc_fileno")
DECLARE_ALTERNATE_NAME ("_fputc_nolock", "_msvc_fputc_nolock");
DECLARE_ALTERNATE_NAME ("_fgetc_nolock", "_msvc_fgetc_nolock");
DECLARE_ALTERNATE_NAME ("rewind", "_msvc_rewind");
DECLARE_ALTERNATE_NAME ("clearerr", "_msvc_clearerr");
DECLARE_ALTERNATE_NAME ("feof", "_msvc_feof");
DECLARE_ALTERNATE_NAME ("ferror", "_msvc_ferror");
DECLARE_ALTERNATE_NAME ("fileno", "_msvc_fileno");

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

#pragma comment(linker, "/alternatename:_filbuf=_nullfunc")
#pragma comment(linker, "/alternatename:_flsbuf=_nullfunc")
DECLARE_ALTERNATE_NAME ("_filbuf", "_nullfunc");
DECLARE_ALTERNATE_NAME ("_flsbuf", "_nullfunc");

int _msvc_fputc_nolock(int c, FILE* fp)
{
Expand Down

0 comments on commit de0e1e1

Please sign in to comment.