RE: objtool warning "uses BP as a scratch register" with clang-9

From: David Laight
Date: Fri Aug 30 2019 - 12:42:35 EST


From: Linus Torvalds
> Sent: 30 August 2019 17:01
> On Fri, Aug 30, 2019 at 8:55 AM David Laight <David.Laight@xxxxxxxxxx> wrote:
...
> But yeah, in general it's just not obviously safe to turn individual
> accesses into memset/memcpy. In contrast, the reverse is obviously
> fine (and _required_ for any kind of half-way good performance when
> you do small constant-sized memory copies, which is actually a common
> pattern partly because the insane C aliasing rules have taught people
> that it's the _only_ safe pattern in some situations).

I wonder where the actual cutoff is for converting a sequence of writes
of zero into a call to memset()?

If you assume either:
1) cold cache (for memset).
2) branch predictor not set for zeroing a small number of words.
I suspect that it is considerable.

> This is why I think "-ffreestanding" and "-fno-builtin-memcpy" are
> completely broken as-is: they are an all-or-nothing thing, they don't
> understand that it's directional.

Yep, and some of the conversions are a just a PITA.
eg printf("%s", string) => puts(string).

I was also trying to get around the memcpy@GLIBC4 fubar so I could
compile code that would run on an old system.
I managed everything except the memcpy() calls that gcc emits for
structure copies (it might even do that even for 'freestanding').
It really ought to emit a call to a different symbol that would normally
be aliased to memcpy() (or better a memcpy_words() function).

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)