From patchwork Fri Apr 14 19:04:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 67760 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 920643858416 for ; Fri, 14 Apr 2023 19:05:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 920643858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681499122; bh=289bs1ot0OfgP4wKqvRo9KbKBfCzLNq1MlkU8GB3638=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ef8dME6CeN9X2TFTLH7zZNg4fhbc1CcjkzzY+Y593VjqfSlKLjdxn1f74V+CqjL5G 2+igVDW2quUFuQzVYLaVCLnGTXcCYQ+FFgZLTH8B1/cGHpJxvAJs2QEFqnZBP1FEwU 5rL2TIteHig4vyUchdi0c/ZQy8lO5cMsbgPwlmOI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from forward502c.mail.yandex.net (forward502c.mail.yandex.net [178.154.239.210]) by sourceware.org (Postfix) with ESMTPS id AEEB03858C54 for ; Fri, 14 Apr 2023 19:04:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEEB03858C54 Received: from mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net [IPv6:2a02:6b8:c14:4293:0:640:63a5:0]) by forward502c.mail.yandex.net (Yandex) with ESMTP id 9D2EB5EDB3; Fri, 14 Apr 2023 22:04:55 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-63.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id q4esLRJW18c0-gKZWDHiB; Fri, 14 Apr 2023 22:04:54 +0300 X-Yandex-Fwd: 1 Message-ID: <3f636504-818d-6520-6cf3-484503a8703c@yandex.ru> Date: Sat, 15 Apr 2023 00:04:52 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: proof for dlmem() (Re: [PATCH v9 0/13] implement dlmem() function) Content-Language: en-US To: Adhemerval Zanella Netto , Szabolcs Nagy , Rich Felker Cc: libc-alpha@sourceware.org, janderson@rice.edu, Carlos O'Donell , Zack Weinberg References: <298b04a6-3055-b89b-59c1-4cfbe955848e@yandex.ru> <81749d04-8cdb-de0b-b88e-24347ed535ba@yandex.ru> <729710b5-6dae-d5f2-99ee-6923be5e627d@yandex.ru> <20230412182043.GI3298@brightrain.aerifal.cx> <08d9ca95-112c-d85e-8e82-7a595ef4d051@yandex.ru> <78b5b5dc-5657-4bf8-24c6-6c00afb1cc40@yandex.ru> <83ee7b42-7a50-e8d1-e9ca-58ec2a12a995@linaro.org> <59862084-0fe3-7642-d3b3-01bb87eef7db@yandex.ru> <52d0b5e8-2c81-66e6-60dc-771d01b26fd6@linaro.org> In-Reply-To: <52d0b5e8-2c81-66e6-60dc-771d01b26fd6@linaro.org> X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: stsp via Libc-alpha From: stsp Reply-To: stsp Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Hello, 14.04.2023 01:02, Adhemerval Zanella Netto пишет: > "It would be possible to require the caller to arrange all of > these things, but that's basically offloading A LOT of the ELF > loading process onto the calling program and I don't think that > makes for a reasonable public interface for glibc to provide." OK, in this case I am going to provide a very detailed, reproducible and undisputable proof that the above quote is false. Attached is the small patch that can be applied on top of my v10 patch-set to verify the demo I present here. The demo I present here, shows the "trace" of the dlmem() usage, by sampling the /proc/self/maps at needed points. Namely, before dlmem(), immediately after dlmem(), and after the fdlopen-over-dlmem finished. That demo clearly and unambiguously demonstrates how dlmem() transforms the raw solib image into the "loaded" image, i.e. where all the PT_LOAD sections are correctly laid out. The output of that demo will be located in a path: /dlfcn/tst-dlmem-extfns.out Everyone can apply the v10+attached patch and verify my results on his build. And here it is: $ cat tst-dlmem-extfns.out before dlmem 7f5210ca8000-7f5210cad000 r--p 00000000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so after dlmem 7f5210ca3000-7f5210ca4000 r--p 00000000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca4000-7f5210ca5000 r-xp 00001000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca5000-7f5210ca6000 r--p 00002000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca6000-7f5210ca7000 r--p 00002000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca7000-7f5210ca8000 rw-p 00003000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca8000-7f5210cad000 r--p 00000000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so post fdlopen 7f5210ca3000-7f5210ca4000 r--p 00000000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca4000-7f5210ca5000 r-xp 00001000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca5000-7f5210ca6000 r--p 00002000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca6000-7f5210ca7000 r--p 00002000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so 7f5210ca7000-7f5210ca8000 rw-p 00003000 00:29 18840304 /home/stas/src/glibc-dlmem/build/dlfcn/glreflib1.so PS: yes, I realize nothing can be changed. But I need to make sure the best possible and the most obvious proof is publically available, so that its not to look as if I've given up to this "wonderful argument that was brought to me so many times". You got all the proves, and also more than once. diff --git a/dlfcn/tst-dlmem-extfns.c b/dlfcn/tst-dlmem-extfns.c index 3b98a6e859..e35bdcaeb1 100644 --- a/dlfcn/tst-dlmem-extfns.c +++ b/dlfcn/tst-dlmem-extfns.c @@ -36,13 +36,20 @@ fdlopen (int fd, int flags) off_t len; void *addr; void *handle; + char cmd[256]; len = lseek (fd, 0, SEEK_END); lseek (fd, 0, SEEK_SET); addr = mmap (NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) return NULL; + printf ("\nbefore dlmem\n"); + snprintf (cmd, sizeof(cmd), "grep glreflib1.so /proc/%i/maps", getpid()); + system (cmd); handle = dlmem (addr, len, flags, NULL); + printf ("\nafter dlmem\n"); + snprintf (cmd, sizeof(cmd), "grep glreflib1.so /proc/%i/maps", getpid()); + system (cmd); munmap (addr, len); return handle; } @@ -111,8 +118,8 @@ do_test (void) handle = dlmem (unaligned_buf, 4096, RTLD_NOW, NULL); TEST_VERIFY (handle == NULL); /* errno is set by dlerror() so needs to print something. */ - printf ("unaligned buf gives %s\n", dlerror ()); - TEST_COMPARE (errno, EINVAL); +// printf ("unaligned buf gives %s\n", dlerror ()); +// TEST_COMPARE (errno, EINVAL); fd = open (BUILDDIR "glreflib1.so", O_RDONLY); if (fd == -1) @@ -128,10 +135,11 @@ do_test (void) /* Check that the lib is properly mmap()ed, rather than memcpy()ed. This may fail on linux kernels <5.13. */ + printf ("\npost fdlopen\n"); snprintf (cmd, sizeof(cmd), "grep glreflib1.so /proc/%i/maps", getpid()); rc = system (cmd); TEST_COMPARE (rc, 0); - +return 0; sym = dlsym (handle, "ref1"); if (sym == NULL) error (EXIT_FAILURE, 0, "dlsym failed");