From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8113 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: Re: Making a shared library that intercepts call to main work with musl compiled binary Date: Mon, 6 Jul 2015 23:34:49 +0300 (MSK) Message-ID: References: <20150706173259.GX1173@brightrain.aerifal.cx> <20150706190651.GY1173@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: ger.gmane.org 1436214907 6972 80.91.229.3 (6 Jul 2015 20:35:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Jul 2015 20:35:07 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8126-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 06 22:35:06 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZCD6U-0007EV-1I for gllmg-musl@m.gmane.org; Mon, 06 Jul 2015 22:35:02 +0200 Original-Received: (qmail 28230 invoked by uid 550); 6 Jul 2015 20:35:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 28212 invoked from network); 6 Jul 2015 20:35:00 -0000 In-Reply-To: <20150706190651.GY1173@brightrain.aerifal.cx> User-Agent: Alpine 2.11 (LNX 23 2013-08-11) Xref: news.gmane.org gmane.linux.lib.musl.general:8113 Archived-At: > > Furthermore, even with dynamic linking you cannot interpose 'main' in the > > executable via LD_PRELOAD. Even more baffling is that the linked code > > interposes __libc_start_main; I'm lost for words that it happens to work with > > glibc. > > Presumably it interposes __libc_start_main because it can't interpose > main. As far as I can tell the only reason it does this is to inject > fake argv. I'm skeptical as to whether it works correctly. I was wrong about interposition on __libc_start_main being somehow surprising -- I missed that it's called from the main executable's startup routine, not from the dynamic linker (thanks to Rich for explaining that on IRC!). So as a result I expect that original code should usually work in practice. Alexander