[PATCH 0/8] Remove alloca usage from glob
Paul Eggert
eggert@cs.ucla.edu
Wed Jan 13 19:36:31 GMT 2021
On 1/5/21 10:58 AM, Adhemerval Zanella wrote:
> 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).
Instead of complicating dynarray by adding char_array stuff, I suggest
adding any primitives just to glob for now, as it's not clear that
they're generally useful.
I do see a problem with the proposed patch set, in that it creates
several different dynarrays when glob really needs only one or two. The
existing code is full of memory-allocation gotchas and would be
simplified if it treated the memory it allocates as a first-class part
of the problem rather than as some sort of cranky subsidiary that needs
to be babied and its diaper changed at random intervals.
Attached is a draft set of patches against Gnulib commit
6a00fdb4bb105697aa27ba97ef7ec33287790ad3 which gives a hint about the
sort of thing that I mean here. This patch set is not complete (it does
only the equivalent of the first four of the patches you proposed) and
it's not exactly the form that I want, so I haven't installed it into
Gnulib. However, I hope it shows the sort of thing I have in mind. So
far, it's needed only one scratch buffer.
In this patch set, glob.c continues to use scratch_buffer.h because
scratch buffers are good enough for all the changes needed so far. I
suppose dynarrays will be helpful for later patches and that we can
switch to them as needed, but I wanted to focus on the actual problem
first rather than worrying about scratch buffers vs dynarrays.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-glob-use-scratch_buffer-for-internal-glob-dirname.patch
Type: text/x-patch
Size: 29012 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20210113/e3f34e3b/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-glob-use-scratch_buffer-for-GLOB_BRACE.patch
Type: text/x-patch
Size: 5360 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20210113/e3f34e3b/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-glob-use-scratch_buffer-for-glob_in_dir-GLOBPAT_NONE.patch
Type: text/x-patch
Size: 5368 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20210113/e3f34e3b/attachment-0005.bin>
More information about the Libc-alpha
mailing list