From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 010663857808 for ; Sun, 27 Jun 2021 14:29:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 010663857808 Received: by mail-lj1-x22d.google.com with SMTP id k8so20808766lja.4 for ; Sun, 27 Jun 2021 07:29:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=AXJ6v2/10/j2tlJf5kln69u+RNaZtHiQ6wSp1tgJ2fg=; b=o8XGj1iTfauTAnHTVz9fdmpJb5j5tXMSizCnx/wX1fBW+2jVBzqWp+3OBdzMeRlZgi W17/y5MjokSAvMJtlVDXSJ2XwpoB0KLH/2JslGG8LktykZDYNEj1eJorlbsi4QtmLJO3 46GxrSEjjFRecV3q/3iH2PLP/Nl4f70pANMn/9hFEwpOewjJ2FSRTfQjn/yPfec29wCF 79paDTm1pBhmuhLGPzvg/YrdJ4E/AIRvgFVSGDkjTguWop5z5JZeBsUBl+hn/zBIXtrA 8ReyNadrR7L7fLpV2Udp98hPUKQEqCdzpYp7k7OaXFWX6JT0USEJ7Zh0Eny/kF3U2UFJ 4sRA== X-Gm-Message-State: AOAM532+1AY6GcV/be7z4y6u+9C86MpMdKzzsZ05yDfvQwLID9qRI3bN NjvvrDbqQhtV/BmQLWvM/OE2pHiCatd4AKuv+vpBy2BmsVY= X-Google-Smtp-Source: ABdhPJw783dWiOkeklVV1EnCLmhXJr5tVD9zx8aTgXeJGxdtnqh3J/bL+Zop5B3jI6J+yu/V2CKj7SdnGg79t8Lpxy8= X-Received: by 2002:a05:651c:507:: with SMTP id o7mr7412946ljp.246.1624804191661; Sun, 27 Jun 2021 07:29:51 -0700 (PDT) MIME-Version: 1.0 From: Fengkai Sun Date: Sun, 27 Jun 2021 22:29:40 +0800 Message-ID: Subject: Why does dynamic linker search global scope before local scope? To: libc-help@sourceware.org X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Jun 2021 14:29:54 -0000 Hi list, After reading some LD_DEBUG messages, I've found that the dynamic linker searches the global scope before the local scope, and the flag RTLD_DEEPBIND can change this behavior. I'm really curious about the reason why the dynamic linker won't search the local scope first by default. To me, the static linker finds out the dependencies of a DSO, and there is a very high probability that they are defined in one of the DT_NEEDED entries. One can use the symbols in the global scope to do interposition, but that is quite rare, so always searching in the global scope seems tedious. Currently, LD_PRELOAD is in the global scope, after the main executable. Though the use of RTLD_DEEPBIND may invalidate the preload semantics, it's just a design choice. The dynamic linker can search local scope first, and add LD_PRELOAD somewhere in the local scope. So I'm wondering why the dynamic linker is designed like this in the first place. Thanks for your time. Best Fengkai