bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

improve clang support (29)


From: Bruno Haible
Subject: improve clang support (29)
Date: Sat, 15 Aug 2020 17:12:02 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; )

clang on Windows, by default, does not link with '-loldnames' (like mingw and
MSVC 14 do). This means that programs that use open(), close(), etc. will get
link errors by default.

For more than 10 years, Microsoft has been deprecating these function names:

access
chdir
chmod
close
creat
dup
dup2
ecvt
execl
execle
execlp
execv
execve
execvp
execvpe
fcloseall
fcvt
fdopen
fileno
gcvt
getcwd
getpid
getw
isatty
j0
j1
jn
lfind
lsearch
lseek
memccpy
mkdir
mktemp
open
putenv
putw
read
rmdir
strdup
swab
tempnam
tzset
umask
unlink
utime
wcsdup
write
y0
y1
yn

mkdir is special: 2 args in POSIX, 1 arg on Windows.
utime is special: no redirect in the header files, there are variants
_utime32 and _utime64.

Using these function names means that
  * You need to link with -loldnames explicitly. While this can be easy
    for executables, I don't think it's worth the trouble when it comes
    to creating libraries.
  * With clang, you also need to add '-Wno-deprecated-declarations' to the
    CPPFLAGS, or you will get a warning for each reference to these function
    names.
  * When looking up the documentation for the functions, you stumble across
    stub pages, such as
    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-close
    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-tzset
    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getcwd
    
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup
    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/mkdir
  * You are living on the "backward compatibility" edge of the existence.
    
https://docs.microsoft.com/en-us/cpp/c-runtime-library/backward-compatibility

I'm therefore changing gnulib to use the underscore-prefixed function names
instead on native Windows. Not only with clang, but also with MSVC and with
mingw.

Essentially this means moving the link-time redirection (from oldnames.lib)
to a preprocessor redirection. Gnulib already does plenty of preprocessor
redirection ("#define foo rpl_foo"); therefore we know that it's a technique
that works.

I'm adding these redirections also when the corresponding gnulib module
is not present. Otherwise there would be the need to add many new module
dependencies, leading to the perception of code bloat for many packages
that use Gnulib.

The first patch is a preparation: ensure that gnulib always generates an
'utime.h' from 'utime.in.h', so that the '#define utime _utime' becomes
always visible.

The second patch contains all the preprocessor redirections.


2020-08-15  Bruno Haible  <bruno@clisp.org>

        Support compiling without -loldnames on native Windows.
        * m4/gnulib-common.m4 (GL_MDA_DEFINES, _GL_MDA_DEFINES): New macros.
        * m4/chown.m4 (AC_FUNC_CHOWN): In the test programs, use GL_MDA_DEFINES.
        (gl_FUNC_CHOWN, gl_FUNC_CHOWN_FOLLOWS_SYMLINK): Likewise.
        * m4/dup.m4 (gl_FUNC_DUP): Likewise.
        * m4/dup2.m4 (gl_FUNC_DUP2): Likewise.
        * m4/fchdir.m4 (gl_FUNC_FCHDIR): Likewise.
        * m4/fchmodat.m4 (gl_FUNC_FCHMODAT): Likewise.
        * m4/fchownat.m4 (gl_FUNC_FCHOWNAT_EMPTY_FILENAME_BUG): Likewise.
        * m4/fcntl-o.m4 (gl_FCNTL_O_FLAGS): Likewise.
        * m4/fcntl.m4 (gl_FUNC_FCNTL): Likewise.
        * m4/fdopen.m4 (gl_FUNC_FDOPEN): Likewise.
        * m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Likewise.
        * m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): Likewise.
        * m4/fopen.m4 (gl_FUNC_FOPEN_GNU): Likewise.
        * m4/freopen.m4 (gl_FUNC_FREOPEN): Likewise.
        * m4/futimens.m4 (gl_FUNC_FUTIMENS): Likewise.
        * m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Likewise.
        * m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Likewise.
        * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL, gl_FUNC_GETCWD_SIGNATURE):
        Likewise.
        * m4/getdtablesize.m4 (gl_FUNC_GETDTABLESIZE): Likewise.
        * m4/linkat.m4 (gl_FUNC_LINKAT): Likewise.
        * m4/lseek.m4 (gl_FUNC_LSEEK): Likewise.
        * m4/mkdir.m4 (gl_FUNC_MKDIR): Likewise.
        * m4/mkstemp.m4 (gl_FUNC_MKSTEMP): Likewise.
        * m4/mktime.m4 (gl_FUNC_MKTIME_WORKS): Likewise.
        * m4/open-slash.m4 (gl_OPEN_TRAILING_SLASH_BUG): Likewise.
        * m4/poll.m4 (gl_FUNC_POLL): Likewise.
        * m4/posix_spawn.m4 (gl_POSIX_SPAWN_WORKS): Likewise.
        * m4/pread.m4 (gl_FUNC_PREAD): Likewise.
        * m4/pselect.m4 (gl_FUNC_PSELECT): Likewise.
        * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Likewise.
        * m4/ptsname_r.m4 (gl_PREREQ_PTSNAME_R): Likewise.
        * m4/putenv.m4 (gl_FUNC_PUTENV): Likewise.
        * m4/pwrite.m4 (gl_FUNC_PWRITE): Likewise.
        * m4/rename.m4 (gl_FUNC_RENAME): Likewise.
        * m4/rmdir-errno.m4 (gl_FUNC_RMDIR_NOTEMPTY): Likewise.
        * m4/rmdir.m4 (gl_FUNC_RMDIR): Likewise.
        * m4/select.m4 (gl_FUNC_SELECT): Likewise.
        * m4/setenv.m4 (gl_FUNC_UNSETENV): Likewise.
        * m4/strncat.m4 (gl_FUNC_STRNCAT): Likewise.
        * m4/ttyname_r.m4 (gl_FUNC_TTYNAME_R): Likewise.
        * m4/unlink-busy.m4 (gl_FUNC_UNLINK_BUSY_TEXT): Likewise.
        * m4/unlink.m4 (gl_FUNC_UNLINK): Likewise.
        * m4/utimens.m4 (gl_UTIMENS): Likewise.
        * m4/utimensat.m4 (gl_FUNC_UTIMENSAT): Likewise.
        * m4/utimes.m4 (gl_FUNC_UTIMES): Likewise.
        * m4/canonicalize.m4 (gl_CANONICALIZE_LGPL): On native Windows, don't
        test for getcwd.
        * m4/utime.m4 (gl_FUNC_UTIME): On native Windows, don't test for utime.
        * m4/wcsdup.m4 (gl_FUNC_WCSDUP): To test for wcsdup, use a test program
        with GL_MDA_DEFINES.
        * lib/c++defs.h (_GL_CXXALIAS_MDA): New macro.
        * lib/fcntl.in.h (creat, open):  On native Windows, use the underscore-
        prefixed symbol.
        * lib/search.in.h (lfind, lsearch): Likewise.
        * lib/stdio.in.h (fcloseall, fdopen, fileno, getw, putw, tempnam):
        Likewise.
        * lib/stdlib.in.h (ecvt, fcvt, gcvt, mktemp, putenv): Likewise.
        * lib/string.in.h (memccpy, strdup): Likewise.
        * lib/sys_stat.in.h (chmod, umask): Likewise.
        * lib/time.in.h (tzset): Likewise.
        * lib/unistd.in.h (access, chdir, close, dup, dup2, execl, execle,
        execlp, execv, execve, execvp, execvpe, getcwd, getpid, isatty, lseek,
        read, rmdir, swab, unlink, write): Likewise.
        * lib/utime.in.h (utime): Likewise.
        * lib/wchar.in.h (wcsdup): Likewise.
        * lib/math.in.h (j0, j1, jn, y0, y1, yn):  Likewise.
        (isfinite, isinf, isnan, signbit): On native Windows, don't define as an
        rpl_-prefixed macro.
        * lib/canonicalize-lgpl.c (__getcwd): On native Windows, use _getcwd.
        * lib/close.c (close_nothrow): On native Windows, use _close.
        * lib/creat.c (orig_creat): On native Windows, use _creat.
        * lib/dup.c (dup_nothrow): On native Windows, use _dup.
        * lib/dup2.c (dup2_nothrow): Use _dup2.
        * lib/fdopen.c (fdopen_nothrow): On native Windows, use _fdopen.
        * lib/getcwd-lgpl.c: On native Windows, use _getcwd.
        * lib/getcwd.c (getcwd_nothrow): Use _getcwd also on mingw.
        * lib/open.c (orig_open): On native Windows, use _open.
        * lib/read.c (read_nothrow): Use _read.
        * lib/rmdir.c: On native Windows, use _rmdir.
        * lib/unlink.c: On native Windows, use _unlink.
        * lib/write.c (write_nothrow): Use _write.
        * lib/sys_select.in.h (close): With clang, don't attach a warning on an
        undefined symbol.
        * lib/sys_socket.in.h (close): Likewise.
        * lib/sys_time.in.h (close): Likewise.
        * tests/test-spawn-pipe-child.c: On native Windows, use _fdopen.

2020-08-14  Bruno Haible  <bruno@clisp.org>

        utime-h: Generate an utime.h file always.
        * modules/utime-h (Makefile.am): Generate utime.h always.
        * m4/utime_h.m4 (gl_UTIME_H): Don't set UTIME_H. Don't define
        GL_GENERATE_UTIME_H.

Attachment: 0001-utime-h-Generate-an-utime.h-file-always.patch
Description: Text Data

Attachment: 0002-Support-compiling-without-loldnames-on-native-Window.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]