This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, libfortran] PR47375 GETLOG thread safety


Janne Blomqvist <blomqvist.janne@gmail.com> writes:

> the attached patch makes the GETLOG intrinsic thread safe by using the
> POSIX getpwuid_r() function, if available.
>
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

This patch broke Solaris bootstrap:

/vol/gcc/src/hg/trunk/local/libgfortran/intrinsics/getlog.c: In function '_gfortran_getlog':
/vol/gcc/src/hg/trunk/local/libgfortran/intrinsics/getlog.c:89:3: error: too many arguments to function 'getpwuid_r'
/usr/include/pwd.h:191:23: note: declared here
/vol/gcc/src/hg/trunk/local/libgfortran/intrinsics/getlog.c:89:7: warning: assignment makes integer from pointer without a cast [enabled by default]

The problem is that <pwd.h> declares two different variants of
getpwuid_r:

#if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
extern int getpwuid_r(uid_t, struct passwd *, char *, int, struct passwd **);
#else
extern struct passwd *getpwuid_r(uid_t, struct passwd *, char *, int);
#endif

There's this comment:

/*
 * getpwuid_r() & getpwnam_r() prototypes are defined here.
 */

/*
 * Previous releases of Solaris, starting at 2.3, provided definitions of
 * various functions as specified in POSIX.1c, Draft 6.  For some of these
 * functions, the final POSIX 1003.1c standard had a different number of
 * arguments and return values.
 *
 * The following segment of this header provides support for the standard
 * interfaces while supporting applications written under earlier
 * releases.  The application defines appropriate values of the feature
 * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
 * whether it was written to expect the Draft 6 or standard versions of
 * these interfaces, before including this header.  This header then
 * provides a mapping from the source version of the interface to an
 * appropriate binary interface.  Such mappings permit an application
 * to be built from libraries and objects which have mixed expectations
 * of the definitions of these functions.

The POSIX.1 definitions of getpwuid_r are only defined

#if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)

I'm not yet sure how and where best to handle this: perhaps we can do
this along the lines of what g++ defines (cf. gcc/config/sol2.h):

        /* For C++ we need to add some additional macro \
           definitions required by the C++ standard     \
           library.  */                                 \
        if (c_dialect_cxx ())                           \
          {                                             \
            builtin_define ("__STDC_VERSION__=199901L");\
            builtin_define ("_XOPEN_SOURCE=600");       \
            builtin_define ("_LARGEFILE_SOURCE=1");     \
            builtin_define ("_LARGEFILE64_SOURCE=1");   \
            builtin_define ("__EXTENSIONS__");          \
          }                                             \

For GNU/Linux, this is probably handled by -D_GNU_SOURCE in Makefile.am
(AM_CPPFLAGS), but this is obviously not general.

Alternatively, one could update the configure check to not only check
for the existance of getpwuid_r, but for a version that takes the
correct number and types of arguments.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]