This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

[PATCH 00/25] Remove extend_alloca [BZ #18023]


This series of patches removes extend_alloca.

I tried to split up the patches by subsystems, and separate patches
which address different coding patterns.

Most extend_alloca uses were converted to a set of helper functions
around the new type struct scratch_buffer.  This facility uses a
fixed-size stack allocation with malloc fallback if the requested buffer
size exceeds the stack allocation.

The vfprintf changes depend on the previous series I posted.

In some cases, I had to use VLAs.  A few cases now use direct allocation
with malloc.

Tested on x86_64-redhat-linux-gnu, with no regressions.  I also tested
nscd manually, to the best of my abilities.

2015-03-02  Florian Weimer  <fweimer@redhat.com>

	[BZ #18023]
	* include/alloca.h (stackinfo_alloca_round, extend_alloca,
	extend_alloca_account): Remove.
	* include/scratch_buffer.h: New file.
	* malloc/scratch_buffer_grow.c: Likewise.
	* malloc/scratch_buffer_grow_preserve.c: Likewise.
	* malloc/scratch_buffer_set_array_size.c: Likewise.
	* malloc/tst-scratch_buffer.c: Likewise.
	* malloc/Makefile (routines): Add scratch_buffer_grow.
	(tests): Add test case.
	* misc/Versions (GLIBC_2.22): Export __libc_scratch_buffer_grow.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add GLIBC_2.22,
	__libc_scratch_buffer_grow, __libc_scratch_buffer_grow_preserve,
	__libc_scratch_buffer_set_array_size.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* elf/dl-deps.c (_dl_map_object_deps): Rewrite to use struct
	scratch_buffer instead of extend_alloca.
	* elf/dl-fini.c (_dl_fini): Rewrite to use variable-length array
	instead of extend_alloca.  Change control flow to avoid a goto.
	Remove assert which is trivially always true.
	* elf/pldd.c (main): Rewrite to use struct
	scratch_buffer instead of extend_alloca.
	* elf/pldd-xx.c (find_maps): Likewise.
	* grp/initgroups.c: Include <scratch_buffer.h> instead of
	<alloca.h>.
	* grp/compat-initgroups.c (compat_call): Rewrite to use struct
	scratch_buffer instead of extend_alloca.
	* nscd/initgrcache.c: Include <scratch_buffer.h>, now needed by
	grp/compat-initgroups.c.
	* inet/getnameinfo.c (nrl_domainname): Rewrite to use struct
	scratch_buffer instead of extend_alloca.
	(getnameinfo): Likewise.
	* nis/nss_compat/compat-initgroups.c (getgrent_next_nss): Fall
	back to malloc directly, without stack allocations.
	(internal_getgrent_r): Rewrite to use struct scratch_buffer
	instead of extend_alloca.
	* nis/nss_nis/nis-initgroups.c (get_uid,
	_nss_nis_initgroups_dyn): Likewise.
	* nscd/aicache.c (addhstaiX): Likewise.
	* nscd/connections.c (read_cmdline): New function.
	(restart): Use it.  Update comment.
	* nscd/grpcache.c (addgrbyX): Likewise.
	* nscd/hstcache.c (addhstbyX): Likewise.
	* nscd/nscd_getgr_r.c (nscd_getgr_r): Likewise.
	* nscd/pwdcache.c (addpwbyX): Likewise.
	* nscd/servicescache.c (addservbyX): Likewise.
	* nss/getent.c (initgroups_keys): Likewise.
	* nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r):
	Likewise.
	* nss/nss_files/files-initgroups.c (_nss_files_initgroups_dyn):
	Likewise.
	* posix/glob.c (glob): Likewise.
	* posix/wordexp.c (parse_tilde): Likewise.
	* stdio-common/vfscanf.c (MEMCPY): Remove macro.
	(struct char_buffer): New type.
	(char_buffer_start, char_buffer_size, char_buffer_error,
	char_buffer_rewind, char_buffer_add): New functions.
	(ADDW): Remove macro, replaced by the char_buffer_add function.
	(_IO_vfscanf_internal): Rewrite using struct char_buffer instead
	of extend_alloca.  Make control flow more explicit.
	* stdio-common/vfprintf.c (printf_positional): Rewrite to use
	struct scratch_buffer instead of extend_alloca.
	* sysdeps/posix/getaddrinfo.c (gaih_inet_serv, gethosts,
	gaih_inet): Likewise.
	* sysdeps/unix/sysv/linux/gethostid.c (gethostid): Likewise.
	* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
	Likewise.
	* sysdeps/unix/sysv/linux/pthread_setaffinity.c
	(__determine_cpumask_size): Replace extend_alloca with a
	variable-length array.
	* sysdeps/unix/sysv/linux/sched_setaffinity.c
	(__sched_setaffinity_new): Likewise.

Florian Weimer (25):
  _dl_fini: Rewrite to use VLA instead of extend_alloca
  pthread_setaffinity (Linux variant): Rewrite to use VLA instead of
    alloca
  nscd restart: Use malloc instead of extend_alloca
  sched_setaffinity (Linux variant): Rewrite to use VLA instead of
    alloca
  getgrent_next_nss (compat-initgroups): Remove alloca fallback
  Add struct scratch_buffer and its internal helper functions
  _dl_map_object_deps: Use struct scratch_buffer instead of
    extend_alloca
  pldd: Use struct scratch_buffer instead of extend_alloca
  grp: Rewrite to use struct scratch_buffer instead of extend_alloca
  getnameinfo: Use struct scratch_buffer instead of extend_alloca
  _nss_compat_initgroups_dyn: Use struct scratch_buffer instead of
    extend_alloca
  _nss_nis_initgroups_dyn: Use struct scratch_buffer instead of
    extend_alloca
  nscd_getgr_r: Use struct scratch_buffer instead of extend_alloca
  nscd: Use struct scratch_buffer instead of extend_alloca in most
    caches
  nscd: Switch to struct scratch_buffer in adhstaiX
  getent: Switch to struct scratch_buffer in initgroups_keys
  nss_files: Use struct scratch_buffer instead of extend_alloca
  gethostid (Linux variant): Switch to struct scratch_buffer
  getlogin_r (Linux variant): Switch to struct scratch_buffer
  getaddrinfo: Use struct scratch_buffer instead of extend_alloca
  wordexp: Rewrite parse_tilde to use struct scratch_buffer
  glob: Rewrite to use struct scratch_buffer instead of extend_alloca
  vfprintf: Rewrite printf_positional to use struct scratch_buffer
  vfscanf: Use struct scratch_buffer instead of extend_alloca
  Remove macros extend_alloca, extend_alloca_account [BZ #18023]

 elf/dl-deps.c                                      |  28 +-
 elf/dl-fini.c                                      | 193 ++++++-----
 elf/pldd-xx.c                                      |  32 +-
 elf/pldd.c                                         |  24 +-
 grp/compat-initgroups.c                            |  26 +-
 grp/initgroups.c                                   |   2 +-
 include/alloca.h                                   |  40 ---
 include/scratch_buffer.h                           | 133 ++++++++
 inet/getnameinfo.c                                 |  85 +++--
 malloc/Makefile                                    |   6 +-
 malloc/Versions                                    |   5 +
 malloc/scratch_buffer_grow.c                       |  52 +++
 malloc/scratch_buffer_grow_preserve.c              |  65 ++++
 malloc/scratch_buffer_set_array_size.c             |  61 ++++
 malloc/tst-scratch_buffer.c                        | 155 +++++++++
 nis/nss_compat/compat-initgroups.c                 |  75 ++---
 nis/nss_nis/nis-initgroups.c                       |  27 +-
 nscd/aicache.c                                     |  79 +++--
 nscd/connections.c                                 |  99 +++---
 nscd/grpcache.c                                    |  57 ++--
 nscd/hstcache.c                                    |  58 ++--
 nscd/initgrcache.c                                 |   1 +
 nscd/nscd_getgr_r.c                                |  18 +-
 nscd/pwdcache.c                                    |  56 ++--
 nscd/servicescache.c                               |  56 ++--
 nss/getent.c                                       |  21 +-
 nss/nss_files/files-hosts.c                        |  64 +---
 nss/nss_files/files-initgroups.c                   |  32 +-
 posix/glob.c                                       | 147 ++-------
 posix/wordexp.c                                    |  46 ++-
 stdio-common/vfprintf.c                            |  48 +--
 stdio-common/vfscanf.c                             | 356 +++++++++++++--------
 sysdeps/posix/getaddrinfo.c                        | 126 +++-----
 sysdeps/unix/sysv/linux/aarch64/libc.abilist       |   5 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist         |   5 +
 sysdeps/unix/sysv/linux/arm/libc.abilist           |   5 +
 sysdeps/unix/sysv/linux/gethostid.c                |  22 +-
 sysdeps/unix/sysv/linux/getlogin_r.c               |  28 +-
 sysdeps/unix/sysv/linux/hppa/libc.abilist          |   5 +
 sysdeps/unix/sysv/linux/i386/libc.abilist          |   5 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist          |   5 +
 sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist |   5 +
 sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist   |   5 +
 sysdeps/unix/sysv/linux/microblaze/libc.abilist    |   5 +
 .../unix/sysv/linux/mips/mips32/fpu/libc.abilist   |   5 +
 .../unix/sysv/linux/mips/mips32/nofpu/libc.abilist |   5 +
 .../unix/sysv/linux/mips/mips64/n32/libc.abilist   |   5 +
 .../unix/sysv/linux/mips/mips64/n64/libc.abilist   |   5 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist         |   5 +
 .../sysv/linux/powerpc/powerpc32/fpu/libc.abilist  |   5 +
 .../linux/powerpc/powerpc32/nofpu/libc.abilist     |   5 +
 .../unix/sysv/linux/powerpc/powerpc64/libc.abilist |   5 +
 sysdeps/unix/sysv/linux/pthread_setaffinity.c      |  37 +--
 sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist  |   5 +
 sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist  |   5 +
 sysdeps/unix/sysv/linux/sched_setaffinity.c        |  37 ++-
 sysdeps/unix/sysv/linux/sh/libc.abilist            |   5 +
 sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist |   5 +
 sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist |   5 +
 .../sysv/linux/tile/tilegx/tilegx32/libc.abilist   |   5 +
 .../sysv/linux/tile/tilegx/tilegx64/libc.abilist   |   5 +
 sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist  |   5 +
 sysdeps/unix/sysv/linux/x86_64/64/libc.abilist     |   5 +
 sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist    |   5 +
 64 files changed, 1490 insertions(+), 1042 deletions(-)
 create mode 100644 include/scratch_buffer.h
 create mode 100644 malloc/scratch_buffer_grow.c
 create mode 100644 malloc/scratch_buffer_grow_preserve.c
 create mode 100644 malloc/scratch_buffer_set_array_size.c
 create mode 100644 malloc/tst-scratch_buffer.c

-- 
2.1.0


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