glibc/include
Zack Weinberg 329ea513b4 Avoid cancellable I/O primitives in ld.so.
Neither the <dlfcn.h> entry points, nor lazy symbol resolution, nor
initial shared library load-up, are cancellation points, so ld.so
should exclusively use I/O primitives that are not cancellable.  We
currently achieve this by having the cancellation hooks compile as
no-ops when IS_IN(rtld); this patch changes to using exclusively
_nocancel primitives in the source code instead, which makes the
intent clearer and significantly reduces the amount of code compiled
under IS_IN(rtld) as well as IS_IN(libc) -- in particular,
elf/Makefile no longer thinks we require a copy of unwind.c in
rtld-libc.a.  (The older mechanism is preserved as a backstop.)

The bulk of the change is splitting up the files that define the
_nocancel I/O functions, so they don't also define the variants that
*are* cancellation points; after which, the existing logic for picking
out the bits of libc that need to be recompiled as part of ld.so Just
Works.  I did this for all of the _nocancel functions, not just the
ones used by ld.so, for consistency.

fcntl was a little tricky because it's only a cancellation point for
certain opcodes (F_SETLKW(64), which can block), and the existing
__fcntl_nocancel wasn't applying the FCNTL_ADJUST_CMD hook, which
strikes me as asking for trouble, especially as the only nontrivial
definition of FCNTL_ADJUST_CMD (for powerpc64) changes F_*LK* opcodes.
To fix this, fcntl_common moves to fcntl_nocancel.c along with
__fcntl_nocancel, and changes its name to the extern (but hidden)
symbol __fcntl_nocancel_adjusted, so that regular fcntl can continue
calling it.  __fcntl_nocancel now applies FCNTL_ADJUST_CMD; so that
both both fcntl.c and fcntl_nocancel.c can see it, the only nontrivial
definition moves from sysdeps/u/s/l/powerpc/powerpc64/fcntl.c to
.../powerpc64/sysdep.h and becomes entirely a macro, instead of a macro
that calls an inline function.

The nptl version of libpthread also changes a little, because its
"compat-routines" formerly included files that defined all the
_nocancel functions it uses; instead of continuing to duplicate them,
I exported the relevant ones from libc.so as GLIBC_PRIVATE.  Since the
Linux fcntl.c calls a function defined by fcntl_nocancel.c, it can no
longer be used from libpthread.so; instead, introduce a custom
forwarder, pt-fcntl.c, and export __libc_fcntl from libc.so as
GLIBC_PRIVATE.  The nios2-linux ABI doesn't include a copy of vfork()
in libpthread, and it was handling that by manipulating
libpthread-routines in .../linux/nios2/Makefile; it is cleaner to do
what other such ports do, and have a pt-vfork.S that defines no symbols.

Right now, it appears that Hurd does not implement _nocancel I/O, so
sysdeps/generic/not-cancel.h will forward everything back to the
regular functions.  This changed the names of some of the functions
that sysdeps/mach/hurd/dl-sysdep.c needs to interpose.

	* elf/dl-load.c, elf/dl-misc.c, elf/dl-profile.c, elf/rtld.c
	* sysdeps/unix/sysv/linux/dl-sysdep.c
	Include not-cancel.h.  Use __close_nocancel instead of __close,
	__open64_nocancel instead of __open, __read_nocancel instead of
	__libc_read, and __write_nocancel instead of __libc_write.

	* csu/check_fds.c (check_one_fd)
	* sysdeps/posix/fdopendir.c (__fdopendir)
	* sysdeps/posix/opendir.c (__alloc_dir): Use __fcntl_nocancel
        instead of __fcntl and/or __libc_fcntl.

	* sysdeps/unix/sysv/linux/pthread_setname.c (pthread_setname_np)
	* sysdeps/unix/sysv/linux/pthread_getname.c (pthread_getname_np)
        * sysdeps/unix/sysv/linux/i386/smp.h (is_smp_system):
	Use __open64_nocancel instead of __open_nocancel.

	* sysdeps/unix/sysv/linux/not-cancel.h: Move all of the
	hidden_proto declarations to the end and issue them if either
	IS_IN(libc) or IS_IN(rtld).
	* sysdeps/unix/sysv/linux/Makefile [subdir=io] (sysdep_routines):
	Add close_nocancel, fcntl_nocancel, nanosleep_nocancel,
	open_nocancel, open64_nocancel, openat_nocancel, pause_nocancel,
	read_nocancel, waitpid_nocancel, write_nocancel.

        * io/Versions [GLIBC_PRIVATE]: Add __libc_fcntl,
        __fcntl_nocancel, __open64_nocancel, __write_nocancel.
        * posix/Versions: Add __nanosleep_nocancel, __pause_nocancel.

        * nptl/pt-fcntl.c: New file.
        * nptl/Makefile (pthread-compat-wrappers): Remove fcntl.
        (libpthread-routines): Add pt-fcntl.
        * include/fcntl.h (__fcntl_nocancel_adjusted): New function.
        (__libc_fcntl): Remove attribute_hidden.
	* sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Call
	__fcntl_nocancel_adjusted, not fcntl_common.
        (__fcntl_nocancel): Move to new file fcntl_nocancel.c.
	(fcntl_common): Rename to __fcntl_nocancel_adjusted; also move
	to fcntl_nocancel.c.
	* sysdeps/unix/sysv/linux/fcntl_nocancel.c: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c: Remove file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h:
	Define FCNTL_ADJUST_CMD here, as a self-contained macro.

	* sysdeps/unix/sysv/linux/close.c: Move __close_nocancel to...
	* sysdeps/unix/sysv/linux/close_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/nanosleep.c: Move __nanosleep_nocancel to...
	* sysdeps/unix/sysv/linux/nanosleep_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/open.c: Move __open_nocancel to...
	* sysdeps/unix/sysv/linux/open_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/open64.c: Move __open64_nocancel to...
	* sysdeps/unix/sysv/linux/open64_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/openat.c: Move __openat_nocancel to...
	* sysdeps/unix/sysv/linux/openat_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/openat64.c: Move __openat64_nocancel to...
	* sysdeps/unix/sysv/linux/openat64_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/pause.c: Move __pause_nocancel to...
	* sysdeps/unix/sysv/linux/pause_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/read.c: Move __read_nocancel to...
	* sysdeps/unix/sysv/linux/read_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/waitpid.c: Move __waitpid_nocancel to...
	* sysdeps/unix/sysv/linux/waitpid_nocancel.c: ...this new file.
	* sysdeps/unix/sysv/linux/write.c: Move __write_nocancel to...
	* sysdeps/unix/sysv/linux/write_nocancel.c: ...this new file.

        * sysdeps/unix/sysv/linux/nios2/Makefile: Don't override
        libpthread-routines.
        * sysdeps/unix/sysv/linux/nios2/pt-vfork.S: New file which
        defines nothing.

        * sysdeps/mach/hurd/dl-sysdep.c: Define __read instead of
        __libc_read, and __write instead of __libc_write.  Define
        __open64 in addition to __open.
2018-06-12 09:53:04 -04:00
..
arpa nss_dns: Replace local declarations with declarations from a header file 2017-04-04 20:56:23 +02:00
bits Add build infrastructure for narrowing libm functions. 2018-02-09 21:18:52 +00:00
gnu Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
net Fix resolver if_* namespace (bug 17717). 2014-12-16 18:18:49 +00:00
netinet Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
programs Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
protocols (abmon): Remove spaces. 1998-11-12 18:03:43 +00:00
rpc sunrpc: Remove stray exports without --enable-obsolete-rpc [BZ #23166] 2018-05-11 15:36:50 +02:00
rpcsvc libnsl: Turn remaining symbols into compat symbols [BZ #22701] 2018-01-29 17:42:30 +01:00
sys Use libc_hidden_* for __cmsg_nxthdr (bug 15105). 2018-02-15 20:59:12 +00:00
aio.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
aliases.h Mark internal getXXXbyYYY functions with attribute_hidden [BZ #18822] 2017-10-01 15:21:00 -07:00
alloc_buffer.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
alloca.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
allocate_once.h Implement allocate_once for atomic initialization with allocation 2018-05-23 15:27:01 +02:00
argp-fmtstream.h Mark internal argp functions with attribute_hidden [BZ #18822] 2017-10-01 15:10:27 -07:00
argp.h Mark internal argp functions with attribute_hidden [BZ #18822] 2017-10-01 15:10:27 -07:00
argz.h Use libc_hidden_* for argz_next, __argz_next (bug 15105). 2018-02-15 21:00:02 +00:00
array_length.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
assert.h Introduce NO_RTLD_HIDDEN, make hurd use it instead of NO_HIDDEN 2017-10-03 01:33:38 +02:00
atomic.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
byteswap.h Update. 1998-04-10 10:52:25 +00:00
complex.h float128: Add private _Float128 declarations for libm. 2017-05-15 10:23:28 -03:00
cpio.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
crypt.h Add include/crypt.h. 2016-10-28 22:40:16 -04:00
ctype.h Use libc_hidden_* for tolower, toupper (bug 15105). 2018-02-23 13:54:53 +00:00
des.h Update. 1998-03-24 10:39:42 +00:00
dirent.h Consolidate scandir{at}{64} implementation 2018-04-20 13:57:12 -03:00
dlfcn.h Switch IDNA implementation to libidn2 [BZ #19728] [BZ #19729] [BZ #22247] 2018-05-23 15:27:24 +02:00
dso_handle.h Mark __dso_handle as hidden [BZ #18822] 2017-09-26 16:53:44 -07:00
elf.h Properly compute offsets of note descriptor and next note [BZ #22370] 2017-11-28 09:57:00 -08:00
endian.h Update. 2001-03-30 05:34:59 +00:00
envz.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
err.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
errno.h hurd: Fix accessing errno from rtld 2018-03-25 00:48:01 +01:00
error.h Update. 1997-06-21 02:59:26 +00:00
execinfo.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
fcntl.h Avoid cancellable I/O primitives in ld.so. 2018-06-12 09:53:04 -04:00
features.h manual: Update _DEFAULT_SOURCE. [BZ #22862] 2018-02-21 02:38:42 -08:00
fenv.h Move fenv.h override inline functions to generic math_private.h. 2018-02-01 20:54:44 +00:00
float.h Handle more _FloatN, _FloatNx types in include/float.h. 2017-11-07 23:49:04 +00:00
fmtmsg.h Add more headers to include/ for conform tests. 2014-12-11 21:41:30 +00:00
fnmatch.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
fpu_control.h Hide internal __setfpucw function [BZ #18822] 2017-10-01 17:52:15 -07:00
ftw.h Update. 1997-06-21 02:59:26 +00:00
gconv.h Update. 1997-11-18 02:50:07 +00:00
getopt.h getopt: remove USE_NONOPTION_FLAGS 2017-04-07 07:45:53 -04:00
getopt_int.h Update. 2004-03-09 10:36:53 +00:00
glob.h Hide internal __glob64 function [BZ #18822] 2017-10-01 18:02:10 -07:00
gmp.h Mark internal gmp functions with attribute_hidden [BZ #18822] 2017-10-01 15:15:30 -07:00
gnu-versions.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
grp-merge.h NSS: Implement group merging support. 2016-04-29 22:18:21 -04:00
grp.h Mark internal grp/pwd/shadow functions with attribute_hidden [BZ #18822] 2017-10-01 15:13:13 -07:00
gshadow.h Mark internal gshadow functions with attribute_hidden [BZ #18822] 2017-10-01 15:19:17 -07:00
iconv.h Update. 1999-08-21 00:38:15 +00:00
ifaddrs.h hurd: Fix `getifaddrs' and `freeifaddrs' symbol exposition 2017-09-28 01:05:18 +02:00
ifreq.h Hide internal __ifreq function [BZ #18822] 2017-10-01 17:35:46 -07:00
ifunc-impl-list.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
inline-hashtab.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
inttypes.h Use libc_hidden_* for strtoumax (bug 15105). 2018-02-28 14:16:21 +00:00
langinfo.h Add first fixes for conformtest for POSIX2008 2012-02-26 21:32:56 -05:00
libc-diag.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libc-internal.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libc-pointer-arith.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libc-symbols.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libgen.h Update. 1997-06-21 02:59:26 +00:00
libintl.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
limits.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
link.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
list.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
list_t.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
locale.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
malloc.h Hide internal __malloc_check_init function [BZ #18822] 2017-10-01 16:00:36 -07:00
math-narrow-eval.h Move math_narrow_eval to separate math-narrow-eval.h. 2018-05-09 00:15:10 +00:00
math.h Add support for sqrt asm redirects 2018-03-15 19:21:35 +00:00
mcheck.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
memory.h Update. 1997-06-21 02:59:26 +00:00
mntent.h Hide internal __hasmntopt function [BZ #18822] 2017-10-01 17:37:42 -07:00
monetary.h Hide internal __vstrfmon_l function [BZ #18822] 2017-10-01 17:45:07 -07:00
mqueue.h Fix mq_receive, mq_send mq_timed* namespace (bug 18545). 2015-06-17 20:19:04 +00:00
netdb.h Mark internal getXXXbyYYY functions with attribute_hidden [BZ #18822] 2017-10-01 15:21:00 -07:00
netgroup.h Update. 1997-06-21 02:59:26 +00:00
nl_types.h Update. 1997-12-22 20:53:38 +00:00
nss.h nss: Export nscd hash function as __nss_hash [BZ #22459] 2017-11-23 14:08:11 +01:00
nsswitch.h Update. 1997-06-21 02:59:26 +00:00
obstack.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
plural-exp.h Hide internal __gettextparse function [BZ #18822] 2017-10-01 17:31:05 -07:00
poll.h Update. 2000-08-21 16:02:48 +00:00
printf.h Hide internal printf functions [BZ #18822/21986] 2017-08-22 07:50:57 -07:00
pthread.h Fix mq_notify pthread_barrier_* namespace (bug 18544). 2015-06-17 20:16:56 +00:00
pty.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
pwd.h Mark internal grp/pwd/shadow functions with attribute_hidden [BZ #18822] 2017-10-01 15:13:13 -07:00
regex.h Hide internal regex functions [BZ #18822] 2017-10-01 15:53:15 -07:00
resolv.h Obsolete p_secstodate. 2017-11-22 22:21:10 +00:00
rounding-mode.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sched.h Hide internal __sched_setparam function [BZ #18822] 2017-10-01 17:43:25 -07:00
scratch_buffer.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
search.h Hide internal __tdestroy function [BZ #18822] 2017-10-01 16:06:58 -07:00
set-hooks.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
setjmp.h Revert "hurd: Avoid PLTs for longjmp & siglongjmp" 2018-04-05 09:38:58 +02:00
sgtty.h Update. 1997-06-21 02:59:26 +00:00
shadow.h Mark internal grp/pwd/shadow functions with attribute_hidden [BZ #18822] 2017-10-01 15:13:13 -07:00
shlib-compat.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
signal.h Introduce NO_RTLD_HIDDEN, make hurd use it instead of NO_HIDDEN 2017-10-03 01:33:38 +02:00
spawn.h Update. 2000-10-01 19:15:29 +00:00
stab.h Update. 1997-06-21 02:59:26 +00:00
stackinfo.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
stap-probe.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
stdc-predef.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
stdio.h Mechanically remove _IO_ name aliases for types and constants. 2018-02-21 14:11:05 -05:00
stdio_ext.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
stdlib.h Use libc_hidden_* for atoi (bug 15105). 2018-02-26 18:17:47 +00:00
string.h Introduce NO_RTLD_HIDDEN, make hurd use it instead of NO_HIDDEN 2017-10-03 01:33:38 +02:00
strings.h Update. 1997-06-21 02:59:26 +00:00
stropts.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
stubs-prologue.h * sysdeps/generic/bits/libc-tsd.h [USE___THREAD]: Conditional 2002-10-11 10:52:20 +00:00
syscall.h Update. 1997-06-21 02:59:26 +00:00
sysexits.h Update. 1997-06-21 02:59:26 +00:00
syslog.h Update. 1997-06-21 02:59:26 +00:00
tar.h Update. 1997-06-21 02:59:26 +00:00
termios.h Hide internal __tcgetattr function [BZ #18822] 2017-10-01 17:48:24 -07:00
tgmath.h Update. 1998-09-06 23:45:24 +00:00
time.h time: Use 64-bit time values for time zone parsing 2018-05-11 16:30:30 +02:00
ttyent.h Installed header hygiene (BZ#20366): Test of installed headers. 2016-09-23 08:43:56 -04:00
uchar.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
ucontext.h Update. 1999-10-12 18:17:41 +00:00
ulimit.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
unistd.h posix: Fix posix_spawnp to not execute invalid binaries in non compat mode (BZ#23264) 2018-06-08 17:27:46 -03:00
utime.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00
utmp.h Mark internal utmp functions with attribute_hidden [BZ #18822] 2017-10-01 15:51:56 -07:00
values.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
wchar.h Remove attribute_hidden for wchar ifunc symbols. 2017-11-21 08:43:23 +01:00
wctype.h Remove __need macros from stdio.h and wchar.h. 2017-06-08 13:58:17 -04:00
wordexp.h First steps to get conformtest fully working 2012-02-25 23:18:39 -05:00