This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about the highly optimized aspects of libc implementation


Mr. Weimer,

Thank you for your response and forgive me for not responding more
quickly. I just had a few follow-ups that I've sprinkled below!

On Thu, Nov 30, 2017 at 3:36 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 11/30/2017 07:47 AM, Will Hawkins wrote:
>>
>> I've been digging through the glibc implementation and looking for
>> examples of where compiler directives or hand-written assembly have
>> been used to improve performance at the "expense" of standards or
>> conventions.
>
>
> The fcntl implementation calls va_arg on a variadic argument which might not
> actually exist.  The syscall function does something similar (but it is
> actually implemented in machine code, so it's less of a problem).

Are you referring to

...
int
__libc_fcntl (int fd, int cmd, ...)
{
  va_list ap;
  void *arg;

  va_start (ap, cmd);
  arg = va_arg (ap, void *);
  va_end (ap);
...

from sysdeps/unix/sysv/linux/fcntl.c?


>
> The NSS internals in general and getaddrinfo in particular call functions
> through a mis-matching function pointer (with an additional argument added,
> or with a void * argument where the function is defined with a concrete
> function pointer).

Are you referring to, for example,

      if (fct != NULL)
        {
          if (req->ai_family == AF_INET6
        || req->ai_family == AF_UNSPEC)
      {
        gethosts (AF_INET6, struct in6_addr);
        no_inet6_data = no_data;
        inet6_status = status;
      }

from sysdeps/posix/getaddrinfo.c where gethosts uses DL_CALL_FCT to
invoke fct as if it were a function that returned void* and with an
additional void* parameter as a result of the call through
_dl_mcount_wrapper_check?

>
> Calling functions such as getpwuid_r with a pointer which has not been
> allocated on the heap (or reusing an existing allocation for a second call)
> is probably not quite valid C due to aliasing violations.
>
> A lot of the code which manipulates struct sockaddr/sockaddr_in/sockaddr_in6
> objects does not make the additional copies which are needed to avoid
> aliasing violations.
>
> Do you need more?  I can probably go on for quite some time.

What you've given me is great! However, if there are other interesting
ones, I'd love to hear them! I love seeing the /expert/ uses of the C
language for learning. You are all amazing craftpersons -- it's great
to watch you work.

Are there any places where, I know this sounds crazy, but functions
are invoked with push/jump (or straight jumps) because, for instance
they are tail calls or somehow the return address is known statically?

Again, thank you so much for taking the time to respond! I really appreciate it!

Will

>
> Thanks,
> Florian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]