mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-10 07:10:06 +00:00
9dd346ff43
This mostly automatically-generated patch converts 113 function definitions in glibc from old-style K&R to prototype-style. Following my other recent such patches, this one deals with the case of function definitions in files that either contain assertions or where grep suggested they might contain assertions - and thus where it isn't possible to use a simple object code comparison as a sanity check on the correctness of the patch, because line numbers are changed. A few such automatically-generated changes needed to be supplemented by manual changes for the result to compile. openat64 had a prototype declaration with "..." but an old-style definition in sysdeps/unix/sysv/linux/dl-openat64.c, and "..." needed adding to the generated prototype in the definition (I've filed <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68024> for diagnosing such cases in GCC; the old state was undefined behavior not requiring a diagnostic, but one seems a good idea). In addition, as Florian has noted regparm attribute mismatches between declaration and definition are only diagnosed for prototype definitions, and five functions needed internal_function added to their definitions (in the case of __pthread_mutex_cond_lock, via the macro definition of __pthread_mutex_lock) to compile on i386. After this patch is in, remaining old-style definitions are probably most readily fixed manually before we can turn on -Wold-style-definition for all builds. Tested for x86_64 and x86 (testsuite). * crypt/md5-crypt.c (__md5_crypt_r): Convert to prototype-style function definition. * crypt/sha256-crypt.c (__sha256_crypt_r): Likewise. * crypt/sha512-crypt.c (__sha512_crypt_r): Likewise. * debug/backtracesyms.c (__backtrace_symbols): Likewise. * elf/dl-minimal.c (_itoa): Likewise. * hurd/hurdmalloc.c (malloc): Likewise. (free): Likewise. (realloc): Likewise. * inet/inet6_option.c (inet6_option_space): Likewise. (inet6_option_init): Likewise. (inet6_option_append): Likewise. (inet6_option_alloc): Likewise. (inet6_option_next): Likewise. (inet6_option_find): Likewise. * io/ftw.c (FTW_NAME): Likewise. (NFTW_NAME): Likewise. (NFTW_NEW_NAME): Likewise. (NFTW_OLD_NAME): Likewise. * libio/iofwide.c (_IO_fwide): Likewise. * libio/strops.c (_IO_str_init_static_internal): Likewise. (_IO_str_init_static): Likewise. (_IO_str_init_readonly): Likewise. (_IO_str_overflow): Likewise. (_IO_str_underflow): Likewise. (_IO_str_count): Likewise. (_IO_str_seekoff): Likewise. (_IO_str_pbackfail): Likewise. (_IO_str_finish): Likewise. * libio/wstrops.c (_IO_wstr_init_static): Likewise. (_IO_wstr_overflow): Likewise. (_IO_wstr_underflow): Likewise. (_IO_wstr_count): Likewise. (_IO_wstr_seekoff): Likewise. (_IO_wstr_pbackfail): Likewise. (_IO_wstr_finish): Likewise. * locale/programs/localedef.c (normalize_codeset): Likewise. * locale/programs/locarchive.c (add_locale_to_archive): Likewise. (add_locales_to_archive): Likewise. (delete_locales_from_archive): Likewise. * malloc/malloc.c (__libc_mallinfo): Likewise. * math/gen-auto-libm-tests.c (init_fp_formats): Likewise. * misc/tsearch.c (__tfind): Likewise. * nptl/pthread_attr_destroy.c (__pthread_attr_destroy): Likewise. * nptl/pthread_attr_getdetachstate.c (__pthread_attr_getdetachstate): Likewise. * nptl/pthread_attr_getguardsize.c (pthread_attr_getguardsize): Likewise. * nptl/pthread_attr_getinheritsched.c (__pthread_attr_getinheritsched): Likewise. * nptl/pthread_attr_getschedparam.c (__pthread_attr_getschedparam): Likewise. * nptl/pthread_attr_getschedpolicy.c (__pthread_attr_getschedpolicy): Likewise. * nptl/pthread_attr_getscope.c (__pthread_attr_getscope): Likewise. * nptl/pthread_attr_getstack.c (__pthread_attr_getstack): Likewise. * nptl/pthread_attr_getstackaddr.c (__pthread_attr_getstackaddr): Likewise. * nptl/pthread_attr_getstacksize.c (__pthread_attr_getstacksize): Likewise. * nptl/pthread_attr_init.c (__pthread_attr_init_2_1): Likewise. (__pthread_attr_init_2_0): Likewise. * nptl/pthread_attr_setdetachstate.c (__pthread_attr_setdetachstate): Likewise. * nptl/pthread_attr_setguardsize.c (pthread_attr_setguardsize): Likewise. * nptl/pthread_attr_setinheritsched.c (__pthread_attr_setinheritsched): Likewise. * nptl/pthread_attr_setschedparam.c (__pthread_attr_setschedparam): Likewise. * nptl/pthread_attr_setschedpolicy.c (__pthread_attr_setschedpolicy): Likewise. * nptl/pthread_attr_setscope.c (__pthread_attr_setscope): Likewise. * nptl/pthread_attr_setstack.c (__pthread_attr_setstack): Likewise. * nptl/pthread_attr_setstackaddr.c (__pthread_attr_setstackaddr): Likewise. * nptl/pthread_attr_setstacksize.c (__pthread_attr_setstacksize): Likewise. * nptl/pthread_condattr_setclock.c (pthread_condattr_setclock): Likewise. * nptl/pthread_create.c (__find_in_stack_list): Likewise. * nptl/pthread_getattr_np.c (pthread_getattr_np): Likewise. * nptl/pthread_mutex_cond_lock.c (__pthread_mutex_lock): Define to use internal_function. * nptl/pthread_mutex_init.c (__pthread_mutex_init): Convert to prototype-style function definition. * nptl/pthread_mutex_lock.c (__pthread_mutex_lock): Likewise. (__pthread_mutex_cond_lock_adjust): Likewise. Use internal_function. * nptl/pthread_mutex_timedlock.c (pthread_mutex_timedlock): Convert to prototype-style function definition. * nptl/pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise. * nptl/pthread_mutex_unlock.c (__pthread_mutex_unlock_usercnt): Likewise. (__pthread_mutex_unlock): Likewise. * nptl_db/td_ta_clear_event.c (td_ta_clear_event): Likewise. * nptl_db/td_ta_set_event.c (td_ta_set_event): Likewise. * nptl_db/td_thr_clear_event.c (td_thr_clear_event): Likewise. * nptl_db/td_thr_event_enable.c (td_thr_event_enable): Likewise. * nptl_db/td_thr_set_event.c (td_thr_set_event): Likewise. * nss/makedb.c (process_input): Likewise. * posix/fnmatch.c (__strchrnul): Likewise. (__wcschrnul): Likewise. (fnmatch): Likewise. * posix/fnmatch_loop.c (FCT): Likewise. * posix/glob.c (globfree): Likewise. (__glob_pattern_type): Likewise. (__glob_pattern_p): Likewise. * posix/regcomp.c (re_compile_pattern): Likewise. (re_set_syntax): Likewise. (re_compile_fastmap): Likewise. (regcomp): Likewise. (regerror): Likewise. (regfree): Likewise. * posix/regexec.c (regexec): Likewise. (re_match): Likewise. (re_search): Likewise. (re_match_2): Likewise. (re_search_2): Likewise. (re_search_stub): Likewise. Use internal_function (re_copy_regs): Likewise. (re_set_registers): Convert to prototype-style function definition. (prune_impossible_nodes): Likewise. Use internal_function. * resolv/inet_net_pton.c (inet_net_pton): Convert to prototype-style function definition. (inet_net_pton_ipv4): Likewise. * stdlib/strtod_l.c (____STRTOF_INTERNAL): Likewise. * sysdeps/pthread/aio_cancel.c (aio_cancel): Likewise. * sysdeps/pthread/aio_suspend.c (aio_suspend): Likewise. * sysdeps/pthread/timer_delete.c (timer_delete): Likewise. * sysdeps/unix/sysv/linux/dl-openat64.c (openat64): Likewise. Make variadic. * time/strptime_l.c (localtime_r): Convert to prototype-style function definition. * wcsmbs/mbsnrtowcs.c (__mbsnrtowcs): Likewise. * wcsmbs/mbsrtowcs_l.c (__mbsrtowcs_l): Likewise. * wcsmbs/wcsnrtombs.c (__wcsnrtombs): Likewise. * wcsmbs/wcsrtombs.c (__wcsrtombs): Likewise.
386 lines
9.3 KiB
C
386 lines
9.3 KiB
C
/* Minimal replacements for basic facilities used in the dynamic linker.
|
||
Copyright (C) 1995-2015 Free Software Foundation, Inc.
|
||
This file is part of the GNU C Library.
|
||
|
||
The GNU C Library is free software; you can redistribute it and/or
|
||
modify it under the terms of the GNU Lesser General Public
|
||
License as published by the Free Software Foundation; either
|
||
version 2.1 of the License, or (at your option) any later version.
|
||
|
||
The GNU C Library is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
Lesser General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public
|
||
License along with the GNU C Library; if not, see
|
||
<http://www.gnu.org/licenses/>. */
|
||
|
||
#include <errno.h>
|
||
#include <limits.h>
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <tls.h>
|
||
#include <unistd.h>
|
||
#include <sys/mman.h>
|
||
#include <sys/param.h>
|
||
#include <sys/types.h>
|
||
#include <ldsodefs.h>
|
||
#include <_itoa.h>
|
||
|
||
#include <assert.h>
|
||
|
||
/* Minimal `malloc' allocator for use while loading shared libraries.
|
||
No block is ever freed. */
|
||
|
||
static void *alloc_ptr, *alloc_end, *alloc_last_block;
|
||
|
||
/* Declarations of global functions. */
|
||
extern void weak_function free (void *ptr);
|
||
extern void * weak_function realloc (void *ptr, size_t n);
|
||
extern unsigned long int weak_function __strtoul_internal (const char *nptr,
|
||
char **endptr,
|
||
int base,
|
||
int group);
|
||
extern unsigned long int weak_function strtoul (const char *nptr,
|
||
char **endptr, int base);
|
||
|
||
|
||
/* Allocate an aligned memory block. */
|
||
void * weak_function
|
||
__libc_memalign (size_t align, size_t n)
|
||
{
|
||
if (alloc_end == 0)
|
||
{
|
||
/* Consume any unused space in the last page of our data segment. */
|
||
extern int _end attribute_hidden;
|
||
alloc_ptr = &_end;
|
||
alloc_end = (void *) 0 + (((alloc_ptr - (void *) 0)
|
||
+ GLRO(dl_pagesize) - 1)
|
||
& ~(GLRO(dl_pagesize) - 1));
|
||
}
|
||
|
||
/* Make sure the allocation pointer is ideally aligned. */
|
||
alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + align - 1)
|
||
& ~(align - 1));
|
||
|
||
if (alloc_ptr + n >= alloc_end || n >= -(uintptr_t) alloc_ptr)
|
||
{
|
||
/* Insufficient space left; allocate another page. */
|
||
caddr_t page;
|
||
size_t nup = (n + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
|
||
if (__glibc_unlikely (nup == 0))
|
||
{
|
||
if (n)
|
||
return NULL;
|
||
nup = GLRO(dl_pagesize);
|
||
}
|
||
page = __mmap (0, nup, PROT_READ|PROT_WRITE,
|
||
MAP_ANON|MAP_PRIVATE, -1, 0);
|
||
if (page == MAP_FAILED)
|
||
return NULL;
|
||
if (page != alloc_end)
|
||
alloc_ptr = page;
|
||
alloc_end = page + nup;
|
||
}
|
||
|
||
alloc_last_block = (void *) alloc_ptr;
|
||
alloc_ptr += n;
|
||
return alloc_last_block;
|
||
}
|
||
|
||
void * weak_function
|
||
malloc (size_t n)
|
||
{
|
||
return __libc_memalign (sizeof (double), n);
|
||
}
|
||
|
||
/* We use this function occasionally since the real implementation may
|
||
be optimized when it can assume the memory it returns already is
|
||
set to NUL. */
|
||
void * weak_function
|
||
calloc (size_t nmemb, size_t size)
|
||
{
|
||
/* New memory from the trivial malloc above is always already cleared.
|
||
(We make sure that's true in the rare occasion it might not be,
|
||
by clearing memory in free, below.) */
|
||
size_t bytes = nmemb * size;
|
||
|
||
#define HALF_SIZE_T (((size_t) 1) << (8 * sizeof (size_t) / 2))
|
||
if (__builtin_expect ((nmemb | size) >= HALF_SIZE_T, 0)
|
||
&& size != 0 && bytes / size != nmemb)
|
||
return NULL;
|
||
|
||
return malloc (bytes);
|
||
}
|
||
|
||
/* This will rarely be called. */
|
||
void weak_function
|
||
free (void *ptr)
|
||
{
|
||
/* We can free only the last block allocated. */
|
||
if (ptr == alloc_last_block)
|
||
{
|
||
/* Since this is rare, we clear the freed block here
|
||
so that calloc can presume malloc returns cleared memory. */
|
||
memset (alloc_last_block, '\0', alloc_ptr - alloc_last_block);
|
||
alloc_ptr = alloc_last_block;
|
||
}
|
||
}
|
||
|
||
/* This is only called with the most recent block returned by malloc. */
|
||
void * weak_function
|
||
realloc (void *ptr, size_t n)
|
||
{
|
||
if (ptr == NULL)
|
||
return malloc (n);
|
||
assert (ptr == alloc_last_block);
|
||
size_t old_size = alloc_ptr - alloc_last_block;
|
||
alloc_ptr = alloc_last_block;
|
||
void *new = malloc (n);
|
||
return new != ptr ? memcpy (new, ptr, old_size) : new;
|
||
}
|
||
|
||
/* Avoid signal frobnication in setjmp/longjmp. Keeps things smaller. */
|
||
|
||
#include <setjmp.h>
|
||
|
||
int weak_function
|
||
__sigjmp_save (sigjmp_buf env, int savemask __attribute__ ((unused)))
|
||
{
|
||
env[0].__mask_was_saved = 0;
|
||
return 0;
|
||
}
|
||
|
||
/* Define our own version of the internal function used by strerror. We
|
||
only provide the messages for some common errors. This avoids pulling
|
||
in the whole error list. */
|
||
|
||
char * weak_function
|
||
__strerror_r (int errnum, char *buf, size_t buflen)
|
||
{
|
||
char *msg;
|
||
|
||
switch (errnum)
|
||
{
|
||
case ENOMEM:
|
||
msg = (char *) "Cannot allocate memory";
|
||
break;
|
||
case EINVAL:
|
||
msg = (char *) "Invalid argument";
|
||
break;
|
||
case ENOENT:
|
||
msg = (char *) "No such file or directory";
|
||
break;
|
||
case EPERM:
|
||
msg = (char *) "Operation not permitted";
|
||
break;
|
||
case EIO:
|
||
msg = (char *) "Input/output error";
|
||
break;
|
||
case EACCES:
|
||
msg = (char *) "Permission denied";
|
||
break;
|
||
default:
|
||
/* No need to check buffer size, all calls in the dynamic linker
|
||
provide enough space. */
|
||
buf[buflen - 1] = '\0';
|
||
msg = _itoa (errnum, buf + buflen - 1, 10, 0);
|
||
msg = memcpy (msg - (sizeof ("Error ") - 1), "Error ",
|
||
sizeof ("Error ") - 1);
|
||
break;
|
||
}
|
||
|
||
return msg;
|
||
}
|
||
|
||
void
|
||
__libc_fatal (const char *message)
|
||
{
|
||
_dl_fatal_printf ("%s", message);
|
||
}
|
||
rtld_hidden_def (__libc_fatal)
|
||
|
||
void
|
||
__attribute__ ((noreturn))
|
||
__chk_fail (void)
|
||
{
|
||
_exit (127);
|
||
}
|
||
rtld_hidden_def (__chk_fail)
|
||
|
||
#ifndef NDEBUG
|
||
/* Define (weakly) our own assert failure function which doesn't use stdio.
|
||
If we are linked into the user program (-ldl), the normal __assert_fail
|
||
defn can override this one. */
|
||
|
||
void weak_function
|
||
__assert_fail (const char *assertion,
|
||
const char *file, unsigned int line, const char *function)
|
||
{
|
||
_dl_fatal_printf ("\
|
||
Inconsistency detected by ld.so: %s: %u: %s%sAssertion `%s' failed!\n",
|
||
file, line, function ?: "", function ? ": " : "",
|
||
assertion);
|
||
|
||
}
|
||
rtld_hidden_weak (__assert_fail)
|
||
|
||
void weak_function
|
||
__assert_perror_fail (int errnum,
|
||
const char *file, unsigned int line,
|
||
const char *function)
|
||
{
|
||
char errbuf[400];
|
||
_dl_fatal_printf ("\
|
||
Inconsistency detected by ld.so: %s: %u: %s%sUnexpected error: %s.\n",
|
||
file, line, function ?: "", function ? ": " : "",
|
||
__strerror_r (errnum, errbuf, sizeof errbuf));
|
||
|
||
}
|
||
rtld_hidden_weak (__assert_perror_fail)
|
||
#endif
|
||
|
||
unsigned long int weak_function
|
||
__strtoul_internal (const char *nptr, char **endptr, int base, int group)
|
||
{
|
||
unsigned long int result = 0;
|
||
long int sign = 1;
|
||
unsigned max_digit;
|
||
|
||
while (*nptr == ' ' || *nptr == '\t')
|
||
++nptr;
|
||
|
||
if (*nptr == '-')
|
||
{
|
||
sign = -1;
|
||
++nptr;
|
||
}
|
||
else if (*nptr == '+')
|
||
++nptr;
|
||
|
||
if (*nptr < '0' || *nptr > '9')
|
||
{
|
||
if (endptr != NULL)
|
||
*endptr = (char *) nptr;
|
||
return 0UL;
|
||
}
|
||
|
||
assert (base == 0);
|
||
base = 10;
|
||
max_digit = 9;
|
||
if (*nptr == '0')
|
||
{
|
||
if (nptr[1] == 'x' || nptr[1] == 'X')
|
||
{
|
||
base = 16;
|
||
nptr += 2;
|
||
}
|
||
else
|
||
{
|
||
base = 8;
|
||
max_digit = 7;
|
||
}
|
||
}
|
||
|
||
while (1)
|
||
{
|
||
unsigned long int digval;
|
||
if (*nptr >= '0' && *nptr <= '0' + max_digit)
|
||
digval = *nptr - '0';
|
||
else if (base == 16)
|
||
{
|
||
if (*nptr >= 'a' && *nptr <= 'f')
|
||
digval = *nptr - 'a' + 10;
|
||
else if (*nptr >= 'A' && *nptr <= 'F')
|
||
digval = *nptr - 'A' + 10;
|
||
else
|
||
break;
|
||
}
|
||
else
|
||
break;
|
||
|
||
if (result > ULONG_MAX / base
|
||
|| (result == ULONG_MAX / base && digval > ULONG_MAX % base))
|
||
{
|
||
errno = ERANGE;
|
||
if (endptr != NULL)
|
||
*endptr = (char *) nptr;
|
||
return ULONG_MAX;
|
||
}
|
||
result *= base;
|
||
result += digval;
|
||
++nptr;
|
||
}
|
||
|
||
if (endptr != NULL)
|
||
*endptr = (char *) nptr;
|
||
return result * sign;
|
||
}
|
||
|
||
|
||
#undef _itoa
|
||
/* We always use _itoa instead of _itoa_word in ld.so since the former
|
||
also has to be present and it is never about speed when these
|
||
functions are used. */
|
||
char *
|
||
_itoa (unsigned long long int value, char *buflim, unsigned int base,
|
||
int upper_case)
|
||
{
|
||
assert (! upper_case);
|
||
|
||
do
|
||
*--buflim = _itoa_lower_digits[value % base];
|
||
while ((value /= base) != 0);
|
||
|
||
return buflim;
|
||
}
|
||
|
||
/* The '_itoa_lower_digits' variable in libc.so is able to handle bases
|
||
up to 36. We don't need this here. */
|
||
const char _itoa_lower_digits[16] = "0123456789abcdef";
|
||
rtld_hidden_data_def (_itoa_lower_digits)
|
||
|
||
/* The following is not a complete strsep implementation. It cannot
|
||
handle empty delimiter strings. But this isn't necessary for the
|
||
execution of ld.so. */
|
||
#undef strsep
|
||
#undef __strsep
|
||
char *
|
||
__strsep (char **stringp, const char *delim)
|
||
{
|
||
char *begin;
|
||
|
||
assert (delim[0] != '\0');
|
||
|
||
begin = *stringp;
|
||
if (begin != NULL)
|
||
{
|
||
char *end = begin;
|
||
|
||
while (*end != '\0' || (end = NULL))
|
||
{
|
||
const char *dp = delim;
|
||
|
||
do
|
||
if (*dp == *end)
|
||
break;
|
||
while (*++dp != '\0');
|
||
|
||
if (*dp != '\0')
|
||
{
|
||
*end++ = '\0';
|
||
break;
|
||
}
|
||
|
||
++end;
|
||
}
|
||
|
||
*stringp = end;
|
||
}
|
||
|
||
return begin;
|
||
}
|
||
weak_alias (__strsep, strsep)
|
||
strong_alias (__strsep, __strsep_g)
|