On Thu, Dec 22, 2016 at 12:33 PM, Joerg Sonnenberger <jo...@bec.de> wrote: > On Thu, Dec 22, 2016 at 05:47:05PM +0100, Christian Weisgerber wrote: >> Building ld.so with clang on amd64 fails with undefined references >> to memset and memcpy. That is odd, since neither function appears >> in the source. Apparently clang optimizes the _dl_memset and >> _dl_bcopy functions into calls to memset and memcpy, respectively. >> >> I tentatively propose to add -fno-builtin to fix this. >> (Builds, runs, and passes regress with gcc on amd64 and i386.) > > You are lucky if it fixes the problem, infact, -fno-builtin has quite a > chance to make the problem worse. Clang assumes the same set of basic > functions to be present even for -ffreestanding environments and can > lower e.g. initialisation of local variables to memset/memcpy.
Yeah. I suspect the better answer is to a) convert _dl_bcopy() to _dl_memcpy() (it's misnamed anyway, as it doesn't behave like bcopy), and b) in a header that's #included everywhere in ld.so, use the gcc asm names extension to redirect memcpy and memset to _dl_memcpy and _dl_memset (and as long as you're doing that, mark them hidden...) I'm assuming clang handles asm names like gcc, such that declaring void *memcpy(void *__restrict, const void *__restrict, __size_t) __dso_hidden __asm("_dl_memcpy"); will make even internally generated calls go to _dl_memcpy instead. Philip Guenther