From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119238 invoked by alias); 4 Dec 2017 01:15:49 -0000 Mailing-List: contact libc-help-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: libc-help-owner@sourceware.org Received: (qmail 119222 invoked by uid 89); 4 Dec 2017 01:15:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=respond!, getaddrinfo, them!, fct X-HELO: mail-qt0-f175.google.com Received: from mail-qt0-f175.google.com (HELO mail-qt0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Dec 2017 01:15:47 +0000 Received: by mail-qt0-f175.google.com with SMTP id r39so19311661qtr.13 for ; Sun, 03 Dec 2017 17:15:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=b6Gre4nCtLfaXfsOgf9etDSqiGN5pzmnbnPq9RTPMvQ=; b=RzMbX4YRYJ8IseSBMw5nLO0RlEEAqb7sNN4LhKUkvIpRxlbIWpfKfrxviZnapqsT6v Tq9MI0X4XAoEoLeNb6c6e+lWVQw+FaJKkSAh3rVNVajfbxs1pog79PCc/jPGi2/6owu9 u7ukfK9MHbyk9JGyCzjnZsXTjy+p0/qhB+EvOK6NjjyQP2EevCFEce5mw72Esw1C9K9k 53d+nOJnkMqx2WnW8jsTcAxWjYxeAqZnk3VZcxW0dG5NMxtPwSvEeRSCcVsmpY2HKLsS vJi5SRbkT8A2WeH6WjX+EZ0TaEaS2zzTyMOMIi9iO8hUCKGXKt6x6C/NG2x6sN89ou9b 9Hvw== X-Gm-Message-State: AKGB3mI1yMdcZOnSQOQNeJIXEu0eUuDLGq6hkXhxHazMwRXgjyC26JnZ GiWlLimeKvdBnPUbqyS04bL8FZgYd7oEj/OAUURY0+r+ X-Google-Smtp-Source: AGs4zMY48ibfKrduRZaAfQThv/iCHOCWEfMZkK/jS6YjBlGVeghNZCa/mpgSsEa+v5ERByHheyt6XziDC19Y8e/llN0= X-Received: by 10.200.56.34 with SMTP id q31mr19841986qtb.64.1512350145089; Sun, 03 Dec 2017 17:15:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.56.215 with HTTP; Sun, 3 Dec 2017 17:15:44 -0800 (PST) In-Reply-To: References: From: Will Hawkins Date: Mon, 04 Dec 2017 01:15:00 -0000 Message-ID: Subject: Re: Question about the highly optimized aspects of libc implementation To: Florian Weimer Cc: libc-help@sourceware.org Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00003.txt.bz2 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 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