From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 825381F880 for ; Thu, 9 Jan 2020 18:29:26 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=FGhKncQeL0sHWq+ttAnCcM7w1Neg5 HOQ6d6mq23gU6k+pLWKrrMOZcx4Qml1JjSxCRwySdC15FKIROn/gID+Gr5e999F2 PO1tP4DcBLVElJwQYfJHj/9ZNcqHYGQaDUshXhrcEQlCXZIhCNM6uJbcNFA/q7DW /KbYFXskHexw8U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=ohF4HeP2h8njZJXklpZM3CL/gak=; b=jXG hjr8N+mRusNYc6aU7aEpqs0VCg93E7ocv/EK35ocQwg2KGN7W36pGPCscWCox3PK iaJ7SkAheKAEAo3ngKORodGbiwFegtfGx4C5zWgFqyvp7CLJ4+FZAhvK72N4YWaK AeYtjV04z/WQCmjhDaTSOAtf+IwnimXt9/a4YKB8= Received: (qmail 64518 invoked by alias); 9 Jan 2020 18:29:24 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 64508 invoked by uid 89); 9 Jan 2020 18:29:23 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mailbackend.panix.com MIME-Version: 1.0 From: Zack Weinberg Date: Thu, 9 Jan 2020 13:29:08 -0500 Message-ID: Subject: Are ifuncs intended to be allowed to resolve to symbols in another DSO? To: GNU C Library Content-Type: text/plain; charset="UTF-8" Suppose I have two major versions of the same shared library (libfoo.so.1 and libfoo.so.2) and the only difference is that libfoo.so.2 drops a whole bunch of compatibility aliases. For instance, libfoo.so.1 defines two names, `blurf` and `xblurf`, for the same function, but libfoo.so.2 defines only the `blurf` name. Any program that winds up loading both shared libraries (via transitive dependencies) is going to have two copies of the actual code for `blurf` in memory. I could eliminate this duplication by having libfoo.so.1 be a thin wrapper around libfoo.so.2, providing only a definition for `xblurf` that calls `blurf`. Good so far, but now old applications are making two jumps through the PLT whenever they call `xblurf`. It occurred to me to wonder whether I could eliminate the extra indirection (on the second and subsequent calls) by making xblurf an ifunc: extern int blurf(char *arg1, int arg2); // defined in libfoo.so.2 static int (*resolve_xblurf(void))(char *, int) { return blurf; } int xblurf(char *, int) __attribute__((ifunc("resolve_xblurf"))); GCC 9.2 is perfectly happy to compile this and link it against a test shared library containing an almost-trivial definition of 'blurf' (all it does is call strlen and do some arithmetic), and a test program that calls 'xblurf' will also compile, link, and even run to completion correctly (using the dynamic loader from glibc 2.29). However, reading https://sourceware.org/glibc/wiki/GNU_IFUNC gives me the impression that this is probably *intended* to work but isn't reliable in the current implementation, for reasons which I don't follow. So, my actual questions are: Is this intended to work? If so, is this actually reliable with current versions of the dynamic loader? If so, what is the oldest version of glibc where it's reliable? Does it make any difference if one or both of the libraries are linked with -z now? zw