From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 23F63385E447 for ; Wed, 14 Jul 2021 08:44:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23F63385E447 Received: by mail-oi1-x234.google.com with SMTP id w127so1435749oig.12 for ; Wed, 14 Jul 2021 01:44:24 -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=bDubz1GzMZ/CV5VXnJFDod+oBhhw+IQgU3SRxSy76KQ=; b=aXiagdudrj9XBJeDU0XDnVWtMSGG6+mgbV9e16YG59M4Iac491Zvyi5rOaeoWZgI32 IfQyCB/QbDuMusele1wLOC0B/7P0Fl6hAnp3+aH2aj30jO/dXTth+Osgfm69vFCvlAQq jKNClKMQyL643D4hwc6lQc5MranXb9PReuRqIwxCGedq79mJpTeUdDobw2O6P8GAtO90 buismTEQdul8wt/Upjd18L0UqJf1SuhIhGPVvK2m1jUl6t8JdxcF/29UggCNHV2MD3qs jSALktEKFvFlxA56EGm0Uv/rTiUgRB62fB3TzYh+pSKFZSLMqvNlCO0i6HF4UT6AHGis 0h9Q== X-Gm-Message-State: AOAM533zCQMg297XLHgc0h+5LprtF7OYEQVmzgyW6aO6nGl61JOgbwJ4 HWP8j7rgZ84NDx7a1i7I7/QXxvGtJf/PI4ITz2Pe3ZsP2ANhA92l X-Google-Smtp-Source: ABdhPJyMydW9Z8JYzkvpIsN4kBMP1NftX/BazgZYYQkivJApXohF4bgZSuGA6AoWBDDGM8FsMtY7nf0EILQOiVVhuaE= X-Received: by 2002:aca:c401:: with SMTP id u1mr3570490oif.158.1626252263446; Wed, 14 Jul 2021 01:44:23 -0700 (PDT) MIME-Version: 1.0 From: Fengkai Sun Date: Wed, 14 Jul 2021 16:44:12 +0800 Message-ID: Subject: Enable preloading in dlopen-ed shared libraries? To: libc-help@sourceware.org X-Spam-Status: No, score=-1.7 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Wed, 14 Jul 2021 08:44:25 -0000 Hi list, As I dive a little deeper into the source code, I found that `_dl_map_object_deps' is called in both rtld.c and dl-open.c. The semantics of two invocations are both clear: rtld.c makes a call like this: _dl_map_object_deps (main_map, preloads, npreloads, mode == trace, 0); because ld.so needs to preload the libraries specified by LD_PRELOAD into the global scope for interposing the symbols. dl-open.c makes a call like this: _dl_map_object_deps (new, NULL, 0, 0, mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT)); because no dlopen-ed library needs to preload anything. However, I think it might be useful to allow users to preload some libraries in the local scope after the map of the dlopen-ed library, just like how ld.so treats preloaded libs in global scope. By doing so, the user can easily provide a different definition of a symbol from the one of the main executable, by enabling RTLD_DEEPBIND. This is useful under some circumstances. For example, a dlopen-ed library may want to use a separate heap from the main heap, and the user can provide another malloc implementation for that library. The auditing interface can do the similar thing, but after doing some experiments, I found that `la_symbind64' cannot catch the bindings of global variables, and it cannot hook all of the function bindings. Would it be a good idea to add an interface to enable preloading in the local scope of dlopen-ed shared libraries? Thank you in advance. -- Best, Fengkai