From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id B47B03858D1E for ; Wed, 29 Mar 2023 19:18:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B47B03858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x22e.google.com with SMTP id w13so1047003oik.2 for ; Wed, 29 Mar 2023 12:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680117482; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=11A4esBGqL+gA4Q5xHdFERCxU6Wj/AL15L4pNFQeeNM=; b=NCHLzSQ3FgTiJm6E5KugZH5JPdkRlyXDylOJG6K7KMWldUfvAtnW4hTVPISg9Kvuxa s6PnOcmhiKXXnEQ8jWC8l2+jjZbcIMfGsLnE/zPYyCUxO6fDGuHjB1qO242d1mtAADkn Kl/ckAq9nERpSad6Tztkge5B+O5K4ohZieX7RnDvjUXMMpLu4FLCFKf1g6iWeAHWRRFm RGdZVXbJTo/l9bodGhL98zuJejFPbUPo7OBR8hPdGs11IlS7vvT81nxjUHdaghZwckzS 1ekfQyTPFYeGgIF8/wrBeyDv5iMmLnyOnL4AgjWl+Gh41dFKKkJr8GspG4+deIzFrd7X y6Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680117482; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=11A4esBGqL+gA4Q5xHdFERCxU6Wj/AL15L4pNFQeeNM=; b=yRs1rePizW83cD+hq4Y3JB4XlakCvfmxuIscAp0efjQlistljpx64D27yNPxV0JvjJ WG2gGx1SUdIMMLbAGEqdGwKKCMx/vXzWc9yjxfWSQoBGv9GsdVRn8D+FXN9p4Dn2tvd7 dZwyBzlMAqk7h88e25CvP9rgr9zVs6IvDxH+dRMjxC9FzsqwQb9CZ1U5LVKcUeL8O5fR nJ0ZOR4RZBwfnr1q1y3EoaFO+719yQyWb3WjFGLv4s2oNxucOiM21Rbs3szFU0d6F83+ Csc6hPYLoG2RrAfS+CAHglq09/+0MOw9bfOKylzO5j0ake2KBxFWlFB+TE67oapbq06+ VS4g== X-Gm-Message-State: AAQBX9eMiWbmyrzXpBgIfDIslJU8tI7CcqO0uLY8wnGKV7RPL74Ynf/C 1O2jMPpOr9FKygKv3wBMi3/rG75iXJigXl4xTZb1fA== X-Google-Smtp-Source: AKy350aVgyVVLj9/BFwb0Wr6WBeLh/7ydPURdUCgfj6N79dQcMMG+PJ53G8nhtgvO20kDneZJn7ULw== X-Received: by 2002:a54:4817:0:b0:389:76fe:6cfd with SMTP id j23-20020a544817000000b0038976fe6cfdmr37611oij.16.1680117481894; Wed, 29 Mar 2023 12:18:01 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:60f9:1426:1d2d:d6b:1761? ([2804:1b3:a7c1:60f9:1426:1d2d:d6b:1761]) by smtp.gmail.com with ESMTPSA id o187-20020acaf0c4000000b0038476262f65sm13940235oih.33.2023.03.29.12.18.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Mar 2023 12:18:01 -0700 (PDT) Message-ID: Date: Wed, 29 Mar 2023 16:17:58 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH 02/13] elf: switch _dl_map_segment() to anonymous mapping Content-Language: en-US To: stsp , libc-alpha@sourceware.org References: <20230318165110.3672749-1-stsp2@yandex.ru> <20230318165110.3672749-3-stsp2@yandex.ru> <0ecd46af-74d2-a1ea-cd3f-88c7c9886c21@linaro.org> <7c3c1d76-578b-4e9d-65fe-f53220fe0640@yandex.ru> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <7c3c1d76-578b-4e9d-65fe-f53220fe0640@yandex.ru> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 29/03/23 15:46, stsp wrote: > > 29.03.2023 23:29, Adhemerval Zanella Netto пишет: >> On 29/03/23 15:00, stsp wrote: >>> But its not ignored in glibc, see >>> >>> sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h >>> >>> Without that flag PREFER_MAP_32BIT_EXEC >>> test fails. >> Because elf/dl-load.h already defines MAP_COPY that handles it, so why >> not use it instead? > > Would MAP_COPY be a good choice for > explicitly anonymous mapping? If so - > can change. It avoid code duplication. > >>>> So basically it would add another mmap on program loading.  For instance, loading >>>> a simple empty main programs: >>> Yes, that's true. >>> Is this a problem? >>> >>> >> Yes, Linux limits a maximum mmap both per process [1].  This code increase both >> the total mapping requires and runtime cost to setup a new shared library. >> >> [1] https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysctl/vm.rst#max_map_count > > This talks about the map areas. > I don't think map areas number changed. > Extra syscall - yes. Extra map area - no. > So I don't think my patch is a subject of > the aforementioned system limit. In fact I think this is gdb limitation, accessing the procfs directly there is no extra mapping and all the segments are indeed mapped by associated shared libraries. > >>>> And it also slight change the mapping, using the same program: >>>> >>>> * Before: >>>> >>>>         0x7ffff7dc2000     0x7ffff7de8000    0x26000        0x0  r--p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7de8000     0x7ffff7f54000   0x16c000    0x26000  r-xp   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7f54000     0x7ffff7faa000    0x56000   0x192000  r--p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7faa000     0x7ffff7fab000     0x1000   0x1e8000  ---p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7fab000     0x7ffff7faf000     0x4000   0x1e8000  r--p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7faf000     0x7ffff7fb1000     0x2000   0x1ec000  rw-p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>> >>>> * With this patch: >>>> >>>>         0x7ffff7dc1000     0x7ffff7de7000    0x26000        0x0  r--p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7de7000     0x7ffff7f53000   0x16c000    0x26000  r-xp   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7f53000     0x7ffff7fa9000    0x56000   0x192000  r--p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7fa9000     0x7ffff7faa000     0x1000        0x0  ---p >>>>         0x7ffff7faa000     0x7ffff7fae000     0x4000   0x1e8000  r--p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>>>         0x7ffff7fae000     0x7ffff7fb0000     0x2000   0x1ec000  rw-p   /home/azanella/Projects/glibc/build/x86_64-linux-gnu/libc.so >>> Mm, was staring on this for a while, >>> and file offsets and perms looks the >>> same. What differences do you mean >>> exactly? >> The PROT_NONE mapping now does not have a file associated: >> >>    0x7ffff7fa9000     0x7ffff7faa000     0x1000        0x0  ---p >> >> This is not a problem itself, but again this change decrease the information >> that some tools might use to analyze the memory mapping. > > Ah, that seems to be a "hole" are > between segments. I actually think > my handling is much better. Without > my patch, such holes are filled with > actually the _random_ page from the > original file mapping. Just whatever > page happened to have that offset. > Do you think the random page from > the file is a good idea for tooling/debugging? It seems to be a gdb limitation that is showing some wrong information. But again, I really don't see *why* this change is needed: the current algorithms already maps the ELF segments correctly and have random data on the hole does not really matter (it would be mapped as PROT_NONE).