Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-18 Thread Joe Perches
On Tue, 2020-08-18 at 08:24 +, David Laight wrote: > From: Nick Desaulniers > > Sent: 17 August 2020 19:37 > .. > > That said, this libcall optimization/transformation (sprintf->stpcpy) > > does look useful to me. > > I'd rather get a cow if I ask for a cow... > > Maybe checkpatch (etc)

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-17 Thread Nick Desaulniers
On Mon, Aug 17, 2020 at 1:13 PM Arvind Sankar wrote: > > On Mon, Aug 17, 2020 at 11:36:49AM -0700, Nick Desaulniers wrote: > > > > Though I don't understand the original issue, with -ffreestanding, > > > > sprintf shouldn't have been turned into strcpy in the first place. > > > > Huh? The

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-17 Thread Arvind Sankar
On Mon, Aug 17, 2020 at 11:36:49AM -0700, Nick Desaulniers wrote: > > > Though I don't understand the original issue, with -ffreestanding, > > > sprintf shouldn't have been turned into strcpy in the first place. > > Huh? The original issue for this thread is because `-ffreestanding` > *isn't*

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-17 Thread Kees Cook
On Mon, Aug 17, 2020 at 10:14:43AM -0700, Sami Tolvanen wrote: > I just confirmed that adding -fno-builtin-stpcpy to KBUILD_CFLAGS does > work with LTO as well. Oh, I read this out of order; sorry! Yes, if -fno-builtin-stpcpy works, let's use that instead. Doesn't that solve it too? -- Kees

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-17 Thread Kees Cook
On Mon, Aug 17, 2020 at 11:36:49AM -0700, Nick Desaulniers wrote: > That said, this libcall optimization/transformation (sprintf->stpcpy) > does look useful to me. Kees, do you have thoughts on me providing > the implementation without exposing it in a header vs using > -fno-builtin-stpcpy? (I

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-17 Thread Nick Desaulniers
On Mon, Aug 17, 2020 at 10:14 AM Sami Tolvanen wrote: > > On Sun, Aug 16, 2020 at 8:02 AM Arvind Sankar wrote: > > > > On Sun, Aug 16, 2020 at 07:22:35AM +0200, Sedat Dilek wrote: > > > On Sun, Aug 16, 2020 at 2:19 AM 'Fangrui Song' via Clang Built Linux > > > wrote: > > > > > > > > Adding a

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-17 Thread Sami Tolvanen
On Sun, Aug 16, 2020 at 8:02 AM Arvind Sankar wrote: > > On Sun, Aug 16, 2020 at 07:22:35AM +0200, Sedat Dilek wrote: > > On Sun, Aug 16, 2020 at 2:19 AM 'Fangrui Song' via Clang Built Linux > > wrote: > > > > > > Adding a definition without a declaration for stpcpy looks good. > > > Clang LTO

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-16 Thread Arvind Sankar
On Sun, Aug 16, 2020 at 07:22:35AM +0200, Sedat Dilek wrote: > On Sun, Aug 16, 2020 at 2:19 AM 'Fangrui Song' via Clang Built Linux > wrote: > > > > Adding a definition without a declaration for stpcpy looks good. > > Clang LTO will work. > > > > (If the kernel does not want to provide these

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Sedat Dilek
On Sun, Aug 16, 2020 at 2:19 AM 'Fangrui Song' via Clang Built Linux wrote: > > On 2020-08-15, 'Nick Desaulniers' via Clang Built Linux wrote: > >On Sat, Aug 15, 2020 at 2:31 PM Joe Perches wrote: > >> > >> On Sat, 2020-08-15 at 14:28 -0700, Nick Desaulniers wrote: > >> > On Sat, Aug 15, 2020 at

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Fangrui Song
On 2020-08-15, 'Nick Desaulniers' via Clang Built Linux wrote: On Sat, Aug 15, 2020 at 2:31 PM Joe Perches wrote: On Sat, 2020-08-15 at 14:28 -0700, Nick Desaulniers wrote: > On Sat, Aug 15, 2020 at 2:24 PM Joe Perches wrote: > > On Sat, 2020-08-15 at 13:47 -0700, Nick Desaulniers wrote: > >

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Joe Perches
On Fri, 2020-08-14 at 19:09 -0700, Nick Desaulniers wrote: > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format strings.

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Nick Desaulniers
On Sat, Aug 15, 2020 at 2:31 PM Joe Perches wrote: > > On Sat, 2020-08-15 at 14:28 -0700, Nick Desaulniers wrote: > > On Sat, Aug 15, 2020 at 2:24 PM Joe Perches wrote: > > > On Sat, 2020-08-15 at 13:47 -0700, Nick Desaulniers wrote: > > > > On Sat, Aug 15, 2020 at 9:34 AM Kees Cook wrote: > >

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Arvind Sankar
On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers wrote: > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Nick Desaulniers
On Sat, Aug 15, 2020 at 9:34 AM Kees Cook wrote: > > On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers wrote: > > LLVM implemented a recent "libcall optimization" that lowers calls to > > `sprintf(dest, "%s", str)` where the return value is used to > > `stpcpy(dest, str) - dest`. This

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Dávid Bolvanský
Yeah, sprintf calls should be replaced with something safer. > Dňa 15. 8. 2020 o 18:34 užívateľ Kees Cook napísal: > > On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers wrote: >> LLVM implemented a recent "libcall optimization" that lowers calls to >> `sprintf(dest, "%s", str)` where

[PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Nick Desaulniers
LLVM implemented a recent "libcall optimization" that lowers calls to `sprintf(dest, "%s", str)` where the return value is used to `stpcpy(dest, str) - dest`. This generally avoids the machinery involved in parsing format strings. Calling `sprintf` with overlapping arguments was clarified in ISO

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Kees Cook
On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers wrote: > LLVM implemented a recent "libcall optimization" that lowers calls to > `sprintf(dest, "%s", str)` where the return value is used to > `stpcpy(dest, str) - dest`. This generally avoids the machinery involved > in parsing format

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Nick Desaulniers
On Sat, Aug 15, 2020 at 2:24 PM Joe Perches wrote: > > On Sat, 2020-08-15 at 13:47 -0700, Nick Desaulniers wrote: > > On Sat, Aug 15, 2020 at 9:34 AM Kees Cook wrote: > > > On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers wrote: > > > > LLVM implemented a recent "libcall optimization"

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Dávid Bolvanský
-fno-builtin-stpcpy can be used to disable stpcpy but Nick at llvm bugzilla wrote that these flags are broken with LTO. > Dňa 15. 8. 2020 o 23:24 užívateľ Joe Perches napísal: > > On Sat, 2020-08-15 at 13:47 -0700, Nick Desaulniers wrote: >>> On Sat, Aug 15, 2020 at 9:34 AM Kees Cook wrote:

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Joe Perches
On Sat, 2020-08-15 at 13:47 -0700, Nick Desaulniers wrote: > On Sat, Aug 15, 2020 at 9:34 AM Kees Cook wrote: > > On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers wrote: > > > LLVM implemented a recent "libcall optimization" that lowers calls to > > > `sprintf(dest, "%s", str)` where

Re: [PATCH v2] lib/string.c: implement stpcpy

2020-08-15 Thread Joe Perches
On Sat, 2020-08-15 at 14:28 -0700, Nick Desaulniers wrote: > On Sat, Aug 15, 2020 at 2:24 PM Joe Perches wrote: > > On Sat, 2020-08-15 at 13:47 -0700, Nick Desaulniers wrote: > > > On Sat, Aug 15, 2020 at 9:34 AM Kees Cook wrote: > > > > On Fri, Aug 14, 2020 at 07:09:44PM -0700, Nick Desaulniers