From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14971 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Fangrui Song Newsgroups: gmane.linux.lib.musl.general Subject: Re: libc.so, Bsymbolic no longer necessary? Date: Sun, 1 Dec 2019 20:39:43 -0800 Message-ID: <20191202043943.tmevimy6aoytfrg3@gmail.com> References: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="12700"; mail-complaints-to="usenet@blaine.gmane.org" Cc: musl@lists.openwall.com To: Jon Chesterfield Original-X-From: musl-return-14987-gllmg-musl=m.gmane.org@lists.openwall.com Mon Dec 02 05:39:59 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1ibdV9-0003AZ-4U for gllmg-musl@m.gmane.org; Mon, 02 Dec 2019 05:39:59 +0100 Original-Received: (qmail 25882 invoked by uid 550); 2 Dec 2019 04:39:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 25864 invoked from network); 2 Dec 2019 04:39:56 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+ouf5VP+r9FWrSmIg5KhG+pwn/qqokI7oSUL1kJRPxg=; b=IonrzN6SoOTFqaUoXgBvwE3DjRK7MK8HLHHG7NCuUqavBrH072RZyXh/RnNYgd1g2w zFeKJ7MN0SHEzaH23iwvyL8AzFy6TE8lWb9Xa9vqk69fBHX4ydqvNSisN97RG6PTkmpa m72oXUNals7ygWktsyCXqXwNafNuYryXlEpasE5nGs4EAacqaB4qH+iAvsVdw2ylHStM wP7nflHBzyN8x+Yrgw31gQrPaB7ankfjVRcrAlKdvZR1VtRR1qIbKN8nTXgrffdEoA6M BtVe/gcYKaBuEoCzGN6m7los4rAS6Twv5QNKYmgGvEbOosL082ptnsartpRAS6NtPjtG xFPA== X-Gm-Message-State: APjAAAUFwuiidPa2pUKBGufPfgVY2j5EjfbFNzTjM0wsDAcIO+5mhZiR E3+zZ/wkYYuwsWCWGrI5f/4= X-Google-Smtp-Source: APXvYqxNmVOnIsKlcl7/eSe6EOlqg5PiMaN8+aQnoMcqzvEqEyZZu5/0fkTf8w/IX+g6BDt5/BBAcg== X-Received: by 2002:a63:e648:: with SMTP id p8mr29322025pgj.259.1575261584333; Sun, 01 Dec 2019 20:39:44 -0800 (PST) Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:14971 Archived-At: On 2019-12-02, Jon Chesterfield wrote: >Hey, > >The early design notes for musl mention linking with Bsymbolic, which seemed >reasonable. I don't see that in the current Makefile, or the equivalent >protected visibility. > >This seems to suggest that LD_PRELOAD can override calls to libc from within >libc. That seems dubious. Is there a use case for this? Or is it avoided by the >control flow in the loader itself? > >I'm thinking of building the musl loader/libc elf with protected visibility on >the exported symbols and wondered whether I'm missing something. -Bsymbolic-functions was changed to --dynamic-list in commit b9410061e2ad6fe91bb3910c3adc7d4a315b7ce9 (2018-04). The file dynamic.list lists the symbols that can be interposed. Among the list you can find allocator functions (malloc and its friends) See commit c9f415d7ea2dace5bf77f6518b6afc36bb7a5732 Some notes: An empty --dynamic-list is identical to -Bsymbolic. --dynamic-list with a list that specifies all STT_OBJECT symbols is similar to -Bsymbolic-function. Specifying STT_OBJECT symbols (e.g. stdin/stdout/environ) is to support COPY relocations. // lld/ELF/Writer.cpp static bool computeIsPreemptible(const Symbol &b) { assert(!b.isLocal()); // Only symbols that appear in dynsym can be preempted. if (!b.includeInDynsym()) return false; // Only default visibility symbols can be preempted. if (b.visibility != STV_DEFAULT) return false; // At this point copy relocations have not been created yet, so any // symbol that is not defined locally is preemptible. if (!b.isDefined()) return true; if (!config->shared) return false; // If the dynamic list is present, it specifies preemptable symbols in a DSO. if (config->hasDynamicList) return b.inDynamicList; // -Bsymbolic means that definitions are not preempted. if (config->bsymbolic || (config->bsymbolicFunctions && b.isFunc())) return false; return true; }