Skip to content

Commit

Permalink
bug fix for handling of fscanf/__isoc99_fscanf
Browse files Browse the repository at this point in the history
  • Loading branch information
shanedsnyder committed Jan 25, 2024
1 parent cd84ee5 commit 7d4e25c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
22 changes: 9 additions & 13 deletions darshan-runtime/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -740,19 +740,15 @@ if test "x$enable_darshan_runtime" = xyes ; then
# End of MPI-only checks
#

AC_MSG_CHECKING(for fscanf redirect)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <stdio.h>
int fscanf(FILE *stream, const char *format, ...) {return(0);}
int __isoc99_fscanf(FILE *stream, const char *format, ...) {return(0);}
]])],
[AC_MSG_RESULT(no)
DARSHAN_STDIO_ADD_FSCANF_LD_OPTS="--wrap=__isoc99_fscanf"],
[AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_FSCANF_REDIRECT], 1,
[Define if fscanf is redirected to another function])
DARSHAN_STDIO_ADD_FSCANF_LD_OPTS=""]
# Newer glibc implementations will redirect fscanf calls to
# __isoc99_fscanf calls. To properly handle this, we detect the
# presence of the __isoc99_fscanf symbol and compile it's wrapper
# if found. Otherwise, we will use the traditional fscanf wrapper.
# We must only wrap one of these calls to avoid multiple definition
# errors when building Darshan.
AC_CHECK_FUNCS([__isoc99_fscanf],
[DARSHAN_STDIO_ADD_FSCANF_LD_OPTS="--wrap=__isoc99_fscanf"],
[DARSHAN_STDIO_ADD_FSCANF_LD_OPTS="--wrap=fscanf"]
)

# look for glibc-specific functions
Expand Down
11 changes: 6 additions & 5 deletions darshan-runtime/lib/darshan-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ DARSHAN_FORWARD_DECL(fgetc, int, (FILE *stream));
DARSHAN_FORWARD_DECL(getw, int, (FILE *stream));
DARSHAN_FORWARD_DECL(_IO_getc, int, (FILE *stream));
DARSHAN_FORWARD_DECL(_IO_putc, int, (int, FILE *stream));
DARSHAN_FORWARD_DECL(fscanf, int, (FILE *stream, const char *format, ...));
#ifndef HAVE_FSCANF_REDIRECT
#ifdef HAVE___ISOC99_FSCANF
DARSHAN_FORWARD_DECL(__isoc99_fscanf, int, (FILE *stream, const char *format, ...));
#else
DARSHAN_FORWARD_DECL(fscanf, int, (FILE *stream, const char *format, ...));
#endif
DARSHAN_FORWARD_DECL(vfscanf, int, (FILE *stream, const char *format, va_list ap));
DARSHAN_FORWARD_DECL(fgets, char*, (char *s, int size, FILE *stream));
Expand Down Expand Up @@ -739,7 +740,7 @@ int DARSHAN_DECL(getw)(FILE *stream)
return(ret);
}

#ifndef HAVE_FSCANF_REDIRECT
#ifdef HAVE___ISOC99_FSCANF
/* NOTE: some glibc versions use __isoc99_fscanf as the underlying symbol
* rather than fscanf
*/
Expand Down Expand Up @@ -770,8 +771,7 @@ int DARSHAN_DECL(__isoc99_fscanf)(FILE *stream, const char *format, ...)

return(ret);
}
#endif

#else
int DARSHAN_DECL(fscanf)(FILE *stream, const char *format, ...)
{
int ret;
Expand Down Expand Up @@ -799,6 +799,7 @@ int DARSHAN_DECL(fscanf)(FILE *stream, const char *format, ...)

return(ret);
}
#endif

int DARSHAN_DECL(vfscanf)(FILE *stream, const char *format, va_list ap)
{
Expand Down
1 change: 0 additions & 1 deletion darshan-runtime/share/ld-opts/darshan-stdio-ld-opts.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
--wrap=fwrite
--wrap=fread
--wrap=fgetc
--wrap=fscanf
--wrap=vfscanf
--wrap=_IO_getc
--wrap=_IO_putc
Expand Down

0 comments on commit 7d4e25c

Please sign in to comment.