From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id A15D3385780F for ; Wed, 26 May 2021 03:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A15D3385780F Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CD84F340E10; Wed, 26 May 2021 03:47:13 +0000 (UTC) Date: Tue, 25 May 2021 23:47:12 -0400 From: Mike Frysinger To: =?utf-8?B?6IKW6bmP?= Cc: libc-help@sourceware.org Subject: Re: Re: glibc interception problems Message-ID: Mail-Followup-To: =?utf-8?B?6IKW6bmP?= , libc-help@sourceware.org References: <4f73c540.6a6.179a6344524.Coremail.xiaopeng_phy@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4f73c540.6a6.179a6344524.Coremail.xiaopeng_phy@163.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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, 26 May 2021 03:47:17 -0000 On 26 May 2021 09:05, 肖鹏 wrote: > Thank you for your immediate response. > I'm developping an open source distributed file system (https://github.com/chubaofs/chubaofs). Yes, we are currently using FUSE. > But FUSE is slow, because of kernel context switch and data copy. We are developping a kernel bypass implementation, which increase QPS by 70%-100% in our test. > The use of LD_PRELOAD has been carefully assessed, and is limited to our own servers. > Maintaining a custom version of glibc makes the server environment complicated and less maintainable. I worry that other applications would be affected, because glibc is too fundamental. > So, I'm wondering if there is other ways. there is no way to intercept the symbols glibc calls internally by design. it speeds glibc up and is not part of glibc's ABI guarantees. even if you could, it wouldn't help with static programs, or with programs that make the syscall directly (while not common, it's not unheard of). if you really need to capture specific syscalls, your choices are basically: * FUSE * ptrace * in-kernel implementation of the FS you might be able to optimize the ptrace implementation via seccomp filters. libseccomp can help create those filters. -mike > At 2021-05-25 11:10:35, "Mike Frysinger" wrote: > >On 25 May 2021 10:30, 肖鹏 via Libc-help wrote: > >> I'm developping a library for a distributed file system, using LD_PRELOAD to intercept file related calls to glibc. > >> Programs directly using unbuffered IO (close/open/read/write) work well with my library. But programs using buffered IO (fclose/fopen/fread/fwrite) will call unbuffered functions of glibc instead of my library. > >> The reason is that in glibc, buffered IO depend on internal symbols, which cannot be intercepted. > >> I can see two ways to work around this: > >> 1. Implement buffered IO in my library. > >> 2. Modify glibc buffered IO to use public symbols, and maintain a custom version of glibc. > >> Both ways have drawbacks. Do you have any suggestions about this? > > > >what is your end goal ? > > > >is this a research project ? > >are you developing an open source project that you want to share with others ? > >something else ? > > > >if it's a short-term project (e.g. for research), (2) might be your best bet. > >it's hacky, but if it gathers the info you need, it's not that bad. > > > >if it's a long-term project you want to share with others, i'd recommend not > >using LD_PRELOAD at all. maybe FUSE would be better. > >-mike