From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 49828385841D for ; Wed, 29 Mar 2023 18:30:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49828385841D 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-ot1-x336.google.com with SMTP id l39-20020a9d1b2a000000b006a121324abdso7120052otl.7 for ; Wed, 29 Mar 2023 11:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680114600; 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=QZshDIvuS7UPgwhSRy7Kpc1NZZ86Y+hmKU1po4X+73M=; b=FaNJhqF/0+IrqPQlcN1pQ4gvid9WdyDtaZhdZgZd5DWkLP9Sfx/UisJZm7vqyPFaOf hm61UOy0CNNSRIlL+c1h1+vJLjbtfw12K8CplXl5tHxu4auA5UWLW5FR8IuQlsi7JTjZ hPgPpqLwGw3OXMAFdtsGAk8DmQRS/3dOd08LTbjjDB4dVbS1w/i9OTNMgKlJVy/V1nhQ uhOmrHKhbMeMkXySWOxkknudpUYhdKQyhNZpEe6iCEXEgyTMIW0tW/3TPEcPCwpoNj9u fqIWB7MPqs/D6szdhORbyLR2jnf8/Pmjjosc0YVGkxh/bMQkX8cwci+mONj2uywh9QtA VxPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680114600; 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=QZshDIvuS7UPgwhSRy7Kpc1NZZ86Y+hmKU1po4X+73M=; b=UWSfGnQB2bkpI9L4PkePZAIzC8oYziQK3voAaXErijb6jFq78GAX8UUAPcM+WEEKUq Py2BKDRJgaKUewoNDYnZVuEmhqX2xTG5eXopB30K6DbdJ4a8zNLBW8Bu1PkqLC+DXKwz n3OUMMUTup7Kspb2igxOXRTx9HFRRq5rzTffXE8Iy4J4DSWHY+CD1BcbnNZ3IDiJtE44 y2CEBpVWy4FZLiC7R1ezlvN0YzlcQhcAthMOVvLwUdXbIWWrTUv4tBa7MP449/FMORaF sFhgTWmucxnc34Z3TaTK00ihOLrvrU/yaTcWCx9gjNQrL3SpKyD0Yr5CFT+Ppy5fFvkm LmGg== X-Gm-Message-State: AO0yUKUegpDiVXA+RINhb/2HZfz4SDAWhHLJAQ1kM3dvt5UpcgOvPWcv NOimFtb3PSDQE/JUf6PjOn2RGQ== X-Google-Smtp-Source: AK7set8YOLxBw7wHV3FEdl22KiwmEr8+Vvn1KpFN4IIOGeuZ8a531W7KzvojzvLi6MML+n5N9FknmQ== X-Received: by 2002:a9d:6ac9:0:b0:69f:abf3:ae8a with SMTP id m9-20020a9d6ac9000000b0069fabf3ae8amr8954540otq.3.1680114600479; Wed, 29 Mar 2023 11:30:00 -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 v1-20020a05683018c100b006a13dd5c8a2sm3759690ote.5.2023.03.29.11.29.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Mar 2023 11:29:59 -0700 (PDT) Message-ID: <0ecd46af-74d2-a1ea-cd3f-88c7c9886c21@linaro.org> Date: Wed, 29 Mar 2023 15:29:57 -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> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: 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:00, stsp wrote: > > 29.03.2023 22:01, Adhemerval Zanella Netto пишет: >> glibc code guidelines [1] suggest to explicit define the types, so >> 'unsigned int' here. > > Fixed locally this and a few other > similar instances. Queued to v10. > > >> [1] https://sourceware.org/glibc/wiki/Style_and_Conventions >> >>> + >>> +#ifdef MAP_DENYWRITE >>> +  /* Tell mmap() that we are mapping solib. This flag enables things >>> +     like LD_PREFER_MAP_32BIT_EXEC. */ >>> +  map_flags |= MAP_DENYWRITE; >>> +#endif >> Why do you need o add MAP_DENYWRITE? They are complete ignored by Linux, > > 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? > > >> 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 >> 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. > >> So I am not seeing any advantage of this refactor: it slight increase the >> number of syscalls for library loading and changes the 'debuggability' of >> resulting shared library maps. > > This is not a "pure refactor", but a preparation > to dlmem(). dlmem() allows the user to pre-map > the memory area (optionally), so in the subsequent > patches I first call the user's callback, and if its > not there or doesn't want to pre-map, then I call > _dl_load_segment() for doing the same thing as > a fall-back. > > Do you want me to squash also that patch > into the one that actually needs it? > No need, this patch as-is is nack. This patch has only cons: it increases runtime cost for generic case, increase the minimum number of mmap segment a shared library required, and decrease debuggability.