To support Intel Control-flow Enforcement Technology (CET) run-time
control:
1. An architecture specific field in the writable ld.so namespace is
needed to indicate if CET features are enabled at run-time.
2. An architecture specific field in struct link_map is needed if
CET features are enabled in an ELF module.
This patch adds dl-procruntime.c to the writable ld.so namespace and
link_map.h to struct link_map.
Tested with build-many-glibcs.py.
* elf/dl-support.c: Include <dl-procruntime.c>.
* include/link.h: Include <link_map.h>.
* sysdeps/generic/dl-procruntime.c: New file.
* sysdeps/generic/link_map.h: Likewise.
* sysdeps/generic/ldsodefs.h: Include <dl-procruntime.c> in
the writable ld.so namespace.
Verify that sizes, alignments and field offsets of jmp_buf as well as
sigjmp_buf are unchanged regardless how struct __jmp_buf_tag is defined.
Since jmp_buf is target specific, jmp_buf-macros.h is added for each
Linux target. A new target must provides its own jmp_buf-macros.h.
TODO: Hurd needs to provide a jmp_buf-macros.h.
Tested with build-many-glibcs.py.
* include/setjmp.h [!_ISOMAC]: Include <stddef.h> and
<jmp_buf-macros.h>.
[!_ISOMAC] (STR_HELPER): New.
[!_ISOMAC] (STR): Likewise.
[!_ISOMAC] (TEST_SIZE): Likewise.
[!_ISOMAC] (TEST_ALIGN): Likewise.
[!_ISOMAC] (TEST_OFFSET): Likewise.
[!_ISOMAC] Add _Static_assert to check sizes, alignments and
field offsets of jmp_buf as well as sigjmp_buf.
* sysdeps/unix/sysv/linux/aarch64/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/alpha/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/arm/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/hppa/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/i386/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/ia64/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/m68k/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/microblaze/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips32/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n32/jmp_buf-macros.h:
Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/jmp_buf-macros.h:
Likewise.
* sysdeps/unix/sysv/linux/nios2/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc32/jmp_buf-macros.h:
Likewise.
* sysdeps/unix/sysv/linux/powerpc/powerpc64/jmp_buf-macros.h:
Likewise.
* sysdeps/unix/sysv/linux/s390/s390-32/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/s390/s390-64/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/sh/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/jmp_buf-macros.h:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/jmp_buf-macros.h:
Likewise.
* sysdeps/unix/sysv/linux/tile/tilepro/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/64/jmp_buf-macros.h: Likewise.
* sysdeps/unix/sysv/linux/x86_64/x32/jmp_buf-macros.h: Likewise.
math.h has a macro _Mlong_double_ for the type to use when declaring
long double functions, and similar macros for other types.
math/Makefile uses -D_Mlong_double_=double in the case of long double
having the same ABI as double.
This originates with:
Mon Jul 8 13:37:40 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* math/math.h (_Mfloat_, _Mlong_double_): New macros, defined iff not
already defined to float, long double. Use those macros for _Mdouble_
defns when including mathcalls.h.
* math/Makefile [$(long-double-fcts) != yes] (CPPFLAGS): Append
-D_Mlong_double_=double.
However, math.h stopped declaring long double functions in the case of
long double having the same ABI as double (and thus probably stopped
actually needing the Makefile definition of _Mlong_double_) with:
1998-11-05 Ulrich Drepper <drepper@cygnus.com>
* math/math.h: Unconditionally include bits/mathdef.h. Declare
long double functions only if __NO_LONG_DOUBLE_MATH is not
defined.
* sysdeps/generic/bits/mathdef.h: Define only if __USE_ISOC9X.
Define __NO_LONG_DOUBLE_MATH.
* sysdeps/m68k/fpu/bits/mathdef.h: Define only if __USE_ISOC9X.
* sysdeps/i386/fpu/bits/mathdef.h: Likewise.
The declarations were since restored for compiling user code, but
remain absent when _LIBC is defined, which is sufficient to avoid
problems declaring function aliases of incompatible types. Thus the
indirection through the _Mlong_double_ macro is not needed (probably
since that 1998 patch), and this patch removes _Mlong_double_ and
associated macros for other types, leaving only the macro _Mdouble_
which is actually used as the type for which a given inclusion of
<bits/mathcalls.h> should declared functions.
Tested for x86_64, and tested with build-many-glibcs.py that installed
stripped shared libraries are unchanged by this patch.
* math/math.h [!_Mfloat_] (_Mfloat_): Do not define.
[!_Mlong_double_] (_Mlong_double_): Likewise.
[!_Mfloat16_] (_Mfloat16_): Likewise.
[!_Mfloat32_] (_Mfloat32_): Likewise.
[!_Mfloat64_] (_Mfloat64_): Likewise.
[!_Mfloat128_] (_Mfloat128_): Likewise.
[!_Mfloat32x_] (_Mfloat32x_): Likewise.
[!_Mfloat64x_] (_Mfloat64x_): Likewise.
[!_Mfloat128x_] (_Mfloat128x_): Likewise.
(_Mdouble_): Define without indirection through those macros.
* math/complex.h [!_Mfloat_] (_Mfloat_): Do not define.
[!_Mfloat128_] (_Mfloat128_): Likewise.
[_Mlong_double_] (_Mlong_double_): Likewise.
(_Mdouble_): Define without indirection through those macros.
* math/Makefile [$(long-double-fcts) != yes] (math-CPPFLAGS): Do
not add -D_Mlong_double_=double.
* include/math.h [_ISOMAC] (_Mlong_double_): Do not undefine.
* math/test-signgam-finite-c99.c (_Mlong_double_): Likewise.
When using compilers before GCC 7, include/float.h provides fallback
definitions of FLT128_* constants. These definitions use 'Q' constant
suffixes, which works for configurations with _Float128 ABI-distinct
from long double, but not where it has the same ABI as long double.
This patch changes the definitions to use the __f128 macro from
<bits/floatn.h>, so allowing them to work in the non-distinct
_Float128 case (where they are used in building glibc tests, not for
building glibc itself) as well.
Tested (a) with build-many-glibcs.py with GCC 6 (installed stripped
shared libraries unchanged by the patch); (b) with
build-many-glibcs.py with GCC 6 together with the main patch to enable
float128 aliases; (c) for x86_64 with both GCC 6 and GCC 7.
* include/float.h [!__GNUC_PREREQ (7, 0) && __HAVE_FLOAT128 &&
__GLIBC_USE (IEC_60559_TYPES_EXT)] (FLT128_MAX): Define using
__f128.
[!__GNUC_PREREQ (7, 0) && __HAVE_FLOAT128 && __GLIBC_USE
(IEC_60559_TYPES_EXT)] (FLT128_EPSILON): Likewise.
[!__GNUC_PREREQ (7, 0) && __HAVE_FLOAT128 && __GLIBC_USE
(IEC_60559_TYPES_EXT)] (FLT128_MIN): Likewise.
[!__GNUC_PREREQ (7, 0) && __HAVE_FLOAT128 && __GLIBC_USE
(IEC_60559_TYPES_EXT)] (FLT128_TRUE_MIN): Likewise.
This patch ensures that the C99 and C11 features required by C++ are
defined according to the value of the __cplusplus macro, and not just
because G++ always defines _GNU_SOURCE. This will allow G++ to stop
defining _GNU_SOURCE some day, without causing the C99 and C11
interfaces to disappear for C++ programs.
[BZ #21326]
* include/features.h [__cplusplus >= 201103] (__USE_ISOC99): Define.
[__cplusplus >= 201703] (__USE_ISOCXX17, __USE_ISOC11): Define.
* math/Makefile (test-math-cxx11): New test.
* math/test-math-cxx11.cc: New file.
On i386, when multi-arch is enabled, all external functions must be
called via PIC PLT in PIE, which requires setting up EBX register,
since they may be IFUNC functions.
* config.h.in (NO_HIDDEN_EXTERN_FUNC_IN_PIE): New.
* include/libc-symbols.h (__hidden_proto_hiddenattr): Add check
for PIC and NO_HIDDEN_EXTERN_FUNC_IN_PIE.
* sysdeps/i386/configure.ac (NO_HIDDEN_EXTERN_FUNC_IN_PIE): New
AC_DEFINE if multi-arch is enabled.
* sysdeps/i386/configure: Regenerated.
On the Hurd, the rtld needs to see its own dumb versions of a few functions
(defined in sysdeps/mach/hurd/dl-sysdep.c) overridden by libc's versions once
loaded. rtld should thus not have hidden attribute for these. To achieve this,
the Hurd port used to just define NO_HIDDEN, which disables it completely. For
now, this changes that to disabling it for all rtld functions, for simplicity.
See Roland's comment on https://sourceware.org/bugzilla/show_bug.cgi?id=15605#c5
The ld.so numbers remain at
8 .rel.plt 000000c8 00000c24 00000c24 00000c24 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .plt 000001a0 00000cf0 00000cf0 00000cf0 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
10 .plt.got 00000010 00000e90 00000e90 00000e90 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
18 .got.plt 00000070 0002d000 0002d000 0002c000 2**2
CONTENTS, ALLOC, LOAD, DATA
which is about 3 times as much as on Linux.
The libc.so numbers get divided by 3 (the remainings are mostly RPC stub calls)
* include/libc-symbols.h [NO_RTLD_HIDDEN] (rtld_hidden_proto,
rtld_hidden_tls_proto, rtld_hidden_def, rtld_hidden_weak,
rtld_hidden_rtld_hidden_ver, data_def, rtld_hidden_data_weak,
rtld_hidden_data_ver): Define to empty.
* include/assert.h [IS_IN(rtld) && NO_RTLD_HIDDEN] (__assert_fail,
__assert_perror_fail): Likewise.
* include/dirent.h [IS_IN(rtld) && NO_RTLD_HIDDEN]
(__rewinddir): Likewise.
* include/libc-internal.h [IS_IN(rtld) && NO_RTLD_HIDDEN]
(__profile_frequency): Likewise.
* include/setjmp.h (__sigsetjmp): Likewise.
* include/signal.h [IS_IN(rtld) && NO_RTLD_HIDDEN] (__sigaction,
__libc_sigaction): Likewise.
* include/stdlib.h [NO_RTLD_HIDDEN] (unsetenv, __strtoul_internal): Do
not set hidden attribute.
* include/string.h [IS_IN(rtld) && NO_RTLD_HIDDEN] (__stpcpy, __strdup,
__strerror_t, __strsep_g, memchr, memcmp, memcpy, memmove, memset,
rawmemchr, stpcpy, strchr, strcmp, strlen, strnlen, strsep): Likewise.
* include/sys/stat.h [IS_IN(rtld) && NO_RTLD_HIDDEN] (__fxstat,
__fxstat64, __lxstat, __lxstat64, __xstat, __xstat64,
__fxstatat64): Likewise.
* include/sys/utsname.h [IS_IN(rtld) && NO_RTLD_HIDDEN]
(__uname): Likewise.
* include/sysdeps/generic/_itoa.h [IS_IN(rtld) && NO_RTLD_HIDDEN]
(_itoa_upper_digits, _itoa_lower_digits): Likewise.
* sysdeps/mach/hurd/configure.ac (NO_HIDDEN): Do not set.
(NO_RTLD_HIDDEN): Set.
* sysdeps/mach/hurd/configure: Refresh.
* config.h.in: Refresh.
Hide internal __glob64 function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/glob.h (__glob64): Add libc_hidden_proto.
* sysdeps/unix/sysv/linux/glob64.c (__glob64): Add
libc_hidden_def.
Hide internal __init_misc function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/libc-internal.h (__init_misc): Add attribute_hidden.
Hide internal __setfpucw function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/fpu_control.h (__setfpucw): Add attribute_hidden.
Hide internal __tcgetattr function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/termios.h (__tcgetattr): Add libc_hidden_proto.
* sysdeps/unix/bsd/tcgetattr.c (__tcgetattr): Add
libc_hidden_def.
* sysdeps/unix/sysv/linux/tcgetattr.c (__tcgetattr): Likewise.
* termios/tcgetattr.c (__tcgetattr): Likewise.
Hide internal __vstrfmon_l function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/monetary.h (__vstrfmon_l): Add attribute_hidden.
Hide internal __sched_setparam function to allow direct access within
libc.so and libc.a without using GOT nor PLT.
__GI___sched_setparam is defined when sysdeps/unix/syscalls.list is
used to generate sched_setparam. Otherwise libc_hidden_def is needed
explicitly.
[BZ #18822]
* include/sched.h (__sched_setparam): Add libc_hidden_proto.
* posix/sched_setp.c (__sched_setparam): Add libc_hidden_def.
Hide internal __hasmntopt function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/mntent.h (__hasmntopt): Add libc_hidden_proto.
* misc/mntent_r.c (__hasmntopt): Add libc_hidden_def.
Hide internal __ifreq function to allow direct access within libc.so and
libc.a without using GOT nor PLT.
[BZ #18822]
* include/ifreq.h: New file.
* sysdeps/generic/ifreq.h (__if_nextreq): Removed.
(__ifreq): Likewise.
* sysdeps/mach/hurd/ifreq.h (__if_nextreq): Removed.
(__ifreq): Likewise.
Hide internal idna functions to allow direct access within libc.so and
libc.a without using GOT nor PLT.
[BZ #18822]
* include/idna.h: New file.
* inet/getnameinfo.c: Include <idna.h> instead of
<libidn/idna.h>.
(__idna_to_unicode_lzlz): Removed.
* sysdeps/posix/getaddrinfo.c: Include <idna.h> instead of
<libidn/idna.h>.
(__idna_to_ascii_lz): Removed.
(__idna_to_unicode_lzlz): Likewise.
Hide internal __gettextparse function to allow direct access within
libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/plural-exp.h: New file.
* intl/plural-exp.c: Include <plural-exp.h> instead of
"plural-exp.h".
__dl_iterate_phdr is hidden and should be accessed directly within
libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* elf/dl-iteratephdr.c (hidden_proto (__dl_iterate_phdr)): Moved
to ...
* include/link.h (hidden_proto (__dl_iterate_phdr)): Here.
Hide internal __tdestroy function to allow direct access within libc.so
and libc.a without using GOT nor PLT.
[BZ #18822]
* include/search.h (__tdestroy): Add libc_hidden_proto.
* misc/tsearch.c (__tdestroy): Add libc_hidden_def.
Hide internal __assert_fail_base function to allow direct access within
libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/assert.h (__assert_fail_base): Add attribute_hidden.
Hide internal __strsep function to allow direct access within libc.so and
libc.a without using GOT nor PLT.
[BZ #18822]
* include/string.h (__strsep): Add libc_hidden_proto.
* string/strsep.c (__strsep): Add libc_hidden_def.
Hide internal __mremap function to allow direct access within libc.so and
libc.a without using GOT nor PLT.
__GI___mremap is defined when sysdeps/unix/syscalls.list is used to
generate mremap. Otherwise libc_hidden_def is needed explicitly.
[BZ #18822]
* include/sys/mman.h (__mremap): Add libc_hidden_proto.
* sysdeps/unix/sysv/linux/m68k/mremap.S (__mremap): Add
libc_hidden_def.
Hide internal __malloc_check_init function to allow direct access within
libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/malloc.h (__malloc_check_init): Add attribute_hidden.
Hide internal __ioctl function to allow direct access within libc.so and
libc.a without using GOT nor PLT.
__GI___ioctl is defined when sysdeps/unix/syscalls.list is used to
generate ioctl. Otherwise libc_hidden_def is needed explicitly.
[BZ #18822]
* include/sys/ioctl.h (__ioctl): Add libc_hidden_proto.
* misc/ioctl.c (__ioctl): Add libc_hidden_def.
* sysdeps/mach/hurd/ioctl.c (__ioctl): Likewise.
* sysdeps/unix/sysv/linux/aarch64/ioctl.S (__ioctl): Likewise.
* sysdeps/unix/sysv/linux/mips/mips64/n64/ioctl.S (__ioctl):
Likewise.
* sysdeps/unix/sysv/linux/powerpc/ioctl.c (__ioctl): Likewise.
* sysdeps/unix/sysv/linux/tile/tilegx/ioctl.S (__ioctl): Likewise.
Mark internal rpc functions with attribute_hidden to allow direct
access within libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/rpc/rpc.h (__rpc_thread_variables): Add
attribute_hidden.
(__rpc_thread_svc_cleanup): Likewise.
(__rpc_thread_clnt_cleanup): Likewise.
(__rpc_thread_key_cleanup): Likewise.
Mark internal dirent functions with attribute_hidden to allow direct
access within libc.so and libc.a without using GOT nor PLT. __readdir64
is hidden with libc_hidden_proto and libc_hidden_def since the exported
readdir64 is an alias of __readdir64.
[BZ #18822]
* include/dirent.h (__opendir): Always add attribute_hidden.
(__fdopendir): Likewise.
(__closedir): Likewise.
(__readdir): Likewise.
(__readdir64): Add libc_hidden_proto.
* sysdeps/mach/hurd/readdir64.c (__readdir64): Add libc_hidden_def.
* sysdeps/unix/sysv/linux/i386/readdir64.c (__readdir64): Likewise.
* sysdeps/unix/sysv/linux/readdir64.c (__readdir64): Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/readdir.c (__GI___readdir64):
New alias.
Mark internal stdio functions with attribute_hidden to allow direct
access within libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/stdio.h (__fcloseall): Add attribute_hidden.
(__getline): Likewise.
(__path_search): Likewise.
(__gen_tempname): Likewise.
(__libc_message): Likewise.
(__flockfile): Likewise.
(__funlockfile): Likewise.
(__fxprintf): Likewise.
(__fxprintf_nocancel): Likewise.
Mark internal gshadow functions with attribute_hidden to allow direct
access within libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/gshadow.h (__fgetsgent_r): Add attribute_hidden.
(__sgetsgent_r): Likewise.
Mark internal time functions with attribute_hidden to allow direct
access within libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* include/time.h (__tzstring): Add attribute_hidden.
(__tzfile_read): Likewise.
(__tzfile_compute): Likewise.
(__tzfile_default): Likewise.
(__tzset_parse_tz): Likewise.
(__offtime): Likewise.
(__asctime_r): Likewise.
(__tzset): Likewise.
(__tz_convert): Likewise.
(__getdate_r): Likewise.
(__getclktck): Likewise.
Mark internal argp functions with attribute_hidden to allow direct
access to them within libc.so and libc.a without using GOT nor PLT.
[BZ #18822]
* argp/argp-fmtstream.c: Include <argp-fmtstream.h>.
* argp/argp-fs-xinl.c: Likewise.
* argp/argp-help.c: Include <argp.h> and <argp-fmtstream.h>.
* argp/argp-parse.c: Include <argp.h>.
* argp/argp-xinl.c: Likewise.
* include/argp-fmtstream.h: New file.
* include/argp.h (__argp_error): Add attribute_hidden.
(__argp_failure): Likewise.
(__argp_input): Likewise.
(__argp_state_help): Likewise.
Mark __ptsname_internal, __mktime_internal and __fopen_internal with
attribute_hidden to allow direct access to them within libc.so and
libc.a without using GOT nor PLT.
[BZ #18822]
* include/stdlib.h (__ptsname_internal): Add attribute_hidden.
* include/time.h (__mktime_internal): Likewise.
* libio/iolibio.h (__fopen_internal): Likewise.