public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org, Paul Eggert <eggert@cs.ucla.edu>,
	bug-gnulib@gnu.org
Subject: [PATCH 0/8] Remove alloca usage from glob
Date: Tue,  5 Jan 2021 15:58:12 -0300	[thread overview]
Message-ID: <20210105185820.3796657-1-adhemerval.zanella@linaro.org> (raw)

This is a respin on an old patchset [1] which is no longer on patchwork.
The main change is just a rebase against master since glibc version is
now on sync with gnulib.

I am sending it also to gnulib to get feedback from the project,
specifically for the part not specific for the system support by glibc
and extra requirements.

The idea of removing the alloca allows a slight better code generation,
simplifies the boilerplate code to avoid the unbounded alloca usage,
and it plays better with security compiler mitigation tools (such as the
ones for stack clash).

On x86_64 with gcc 9.2.1 build glob for shared object, the total stack
usage went from:

glob.c:261:1:next_brace_sub     8       static
glob.c:1205:1:prefix_array      96      static
glob.c:1185:1:collated_compare  8       static
glob.c:250:1:is_dir.isra.0      160     static
glob.c:1259:1:glob_in_dir       864     dynamic
glob.c:297:1:__glob     1360    dynamic

to

glob.c:231:1:next_brace_sub     8       static
dynarray-skeleton.c:203:1:globnames_array_free  32      static
glob.c:1131:1:prefix_array      96      static
glob.c:1111:1:collated_compare  8       static
dynarray-skeleton.c:275:1:globnames_array_add__ 48      static
dynarray-skeleton.c:373:1:char_array_resize.part.0      48      static
char_array-skeleton.c:274:1:char_array_replace_str_pos  48      static
char_array-skeleton.c:204:1:char_array_crop     32      static
char_array-skeleton.c:240:1:char_array_append_str       48      static
char_array-skeleton.c:118:1:char_array_set_str_size     32      static
char_array-skeleton.c:161:1:char_array_init_str 32      static
glob.c:220:1:is_dir.isra.0      160     static
glob.c:1200:1:glob_in_dir       1088    static
glob.c:267:1:__glob     1824    static

(it was obtained with -fstack-usage gcc option).

It is a slight increase and due GNU extension where glob might be called
recursivelly internally the total stack usage might be still slight
larger than current implementation.  But I still think it is a worth
tradeoff.

[1] https://sourceware.org/pipermail/libc-alpha/2018-February/091326.html

Adhemerval Zanella (8):
  malloc: Add specialized dynarray for C strings
  posix: Use char_array for internal glob dirname
  posix: Remove alloca usage for GLOB_BRACE on glob
  posix: Remove alloca usage on glob dirname
  posix: Use dynarray for globname in glob
  posix: Remove alloca usage on glob user_name
  posix: Use char_array for home_dir in glob
  posix: Remove all alloca usage in glob

 malloc/Makefile                    |   4 +-
 malloc/Versions                    |   7 +
 malloc/char_array-impl.c           |  57 +++
 malloc/char_array-skeleton.c       | 288 +++++++++++++
 malloc/char_array.h                |  53 +++
 malloc/dynarray.h                  |   9 +
 malloc/dynarray_overflow_failure.c |  31 ++
 malloc/malloc-internal.h           |  14 +
 malloc/tst-char_array.c            | 112 ++++++
 posix/glob.c                       | 622 +++++++++++------------------
 10 files changed, 817 insertions(+), 380 deletions(-)
 create mode 100644 malloc/char_array-impl.c
 create mode 100644 malloc/char_array-skeleton.c
 create mode 100644 malloc/char_array.h
 create mode 100644 malloc/dynarray_overflow_failure.c
 create mode 100644 malloc/tst-char_array.c

-- 
2.25.1


             reply	other threads:[~2021-01-05 18:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-05 18:58 Adhemerval Zanella [this message]
2021-01-05 18:58 ` [PATCH 1/8] malloc: Add specialized dynarray for C strings Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 2/8] posix: Use char_array for internal glob dirname Adhemerval Zanella
2021-03-23 16:08   ` Arjun Shankar
2021-03-24 17:39     ` Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 3/8] posix: Remove alloca usage for GLOB_BRACE on glob Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 4/8] posix: Remove alloca usage on glob dirname Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 5/8] posix: Use dynarray for globname in glob Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 6/8] posix: Remove alloca usage on glob user_name Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 7/8] posix: Use char_array for home_dir in glob Adhemerval Zanella
2021-01-05 18:58 ` [PATCH 8/8] posix: Remove all alloca usage " Adhemerval Zanella
2021-01-13 19:36 ` [PATCH 0/8] Remove alloca usage from glob Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210105185820.3796657-1-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).