From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 901043858D28 for ; Mon, 4 Mar 2024 12:04:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 901043858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 901043858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709553900; cv=none; b=pO1s/QhW8ZAVQCtRTgjwpS3LhM/rQFXbZhGqEzUcBd0MzYUeTu+bEYyN/8zTxPKkUWgtHMKUxbOyVRgsAN+vokoxQLVq5QWRRaNH/Wx1r4wTZC7uw4l5U+ZtKfJlbDQNSGwpueEhVxST0543Xxr/n3ai39q3ryJEErlMuCrvzXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709553900; c=relaxed/simple; bh=zmyEz4AJ/HyKVFFET2zlYhhrRWz0f7yu977emMADaM0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=x6Mk8kYluzFOzZuhowDUdDoRS5aAjVCenHDTY2lYID0yG7W2ZvoU+rvvzrKXGbHfA4DUNNezc1ImUxJ4etepycdYaLX/Lgy95MaScVlGreZn3irTphJ4WhH+8MWgX25R4G8D8lsi0LR7FF7Dh2DQG74FkGNlOLPxhIaA8IumD10= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so3427338a12.0 for ; Mon, 04 Mar 2024 04:04:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709553897; x=1710158697; darn=sourceware.org; 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=6AqVoQ/x8WS4b0B0bgKzoaIznB2vmdS2SOFT8c96tnc=; b=wdPfupCqGjC7PqMnXMFH9yu5Fisi6GREVSEvYnrDx2vhaSMpKwnRAPPfIfdxjA2Bst fk5i7VbSxdJmBUooK8pVRu5m7Jah5auQzcKWUvSET3hRiwfrN0Ww/V5dhdhX1V7cYbBu MFZzRREDuDDbKyG0CxYTLN9dXe22TGgFaU319HRJdxKoGuU1Ldi+FPjS9CuJNQWFFPnI +OqOPHSikpgp8ujwPpTi3vid2Z/lX78aPb0R7kgmF84kknwnvdBXJPeYb+Xm8uL+zjWg VOeWZLx7AI28Pohmta5upu1gHxVkj+z3nRhG4Z7s08FCh5UGWXLOg3YnbO2IUcyqVlv/ TCDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709553897; x=1710158697; 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=6AqVoQ/x8WS4b0B0bgKzoaIznB2vmdS2SOFT8c96tnc=; b=DyEgzpq2Pu6iTYkuPnXgoFSua4bd6A7iLnkDXAxKChIvawAiLYod59FBjY9iPfPxgL 9LhQZGkXOCOmKL2xrWMwBsXAJUK36p+fox9KxNRsjPhDTtXnL700cbEvsSEzIM31TPMP r7VH8lezMyZNVh1JYIs2Z4s0aTP7k5hmMzb7dzUrcvO0n3qru7GF39jR3zjGN9QKAu+k G6VqTqTMoLgToTZMwXFaDYX/gOV7GzjqzDJkHqwHS62CMsp9z7ED0VucKtYF1SwI8LJu totSydqPvkjZMmzyI/DZ7lJ4oBN/glssi4NN/SsqfFUyow3pMOnaa1/v/NpcmHyy+bZg uQSg== X-Forwarded-Encrypted: i=1; AJvYcCWQEWTh1DMIVia4eMcZVk7IVlQOOMThPwzJBpE4pHHl0nHFr+bPHC7t8ilng8NS6fIz7YNmco4IRDwezv9TxTqwpQnz3jLHolI= X-Gm-Message-State: AOJu0YzM4HI8MaL017Ji5ymTGZ/JZwA4P2o4OXy5wJQKVdPUHAihUx3D FOiuWjb4y1uDc9ovEhZg7WXvjTrRKDiSosOMBUL6LIP/t280bNosCSyLQcChyrAhbvw0kQIlnlQ W X-Google-Smtp-Source: AGHT+IHGqxabmbC2IgjNqry6JEJAAKCpTCXtGeCzCnUG1F+i4Zr/28i5U8KA9SnaHVLV0i+BvHinYA== X-Received: by 2002:a17:90a:4285:b0:29a:be15:9c90 with SMTP id p5-20020a17090a428500b0029abe159c90mr7003528pjg.34.1709553897480; Mon, 04 Mar 2024 04:04:57 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c1:ec17:6807:fa0e:d54a:aeda? ([2804:1b3:a7c1:ec17:6807:fa0e:d54a:aeda]) by smtp.gmail.com with ESMTPSA id t9-20020a17090aae0900b0029b12d6b4a3sm7191926pjq.39.2024.03.04.04.04.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 04:04:56 -0800 (PST) Message-ID: Date: Mon, 4 Mar 2024 09:04:53 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Seeking advise on most portable way to detect 64-bit off_t Content-Language: en-US To: Aliaksey Kandratsenka , libc-help@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 List-Id: On 01/03/24 18:06, Aliaksey Kandratsenka via Libc-help wrote: > Hi. > > In gperftools we have the feature to hook mmap calls which works by > interposing over glibc's mmap. So it has to deal with off_t complexities. > We don't use that offset argument, other than just passing it to real mmap > implementation. I am also trying to support different Linux libc-s just for > completeness. And musl being new enough and wise enough has always had > 64-bit off_t (bionic hasn't and there is really no excuse...) > > So with that I need some means to detect 32-bit off_t that works across > multiple libcs and has the highest hope of working in the future. > > By looking around, I choose to detect 32-bit-ness of off_t by looking at > semi-obscure define _POSIX_V7_ILP32_OFF32: > https://github.com/gperftools/gperftools/blob/37b59a206e36b405dcb2ac09d502875dd629a80b/src/mmap_hook.cc#L275 > > It does seem to do the right thing across implementations I checked. Well > mostly. > > These days, Debian folk are doing a massive 64-bit time_t transition (which > also includes mass-enabling 64-bit off_t, at last) and they're rebuilding > everything with _FILE_OFFSET_BITS=64. And my "approach" fails. > https://buildd.debian.org/status/fetch.php?pkg=google-perftools&arch=armel&ver=2.15-1.1&stamp=1709166723&file=log > > Glibc doesn't adjust _POSIX_V7_ILP32_{BIGOFF,OFF32} defines based on > _FILE_OFFSET_BITS. Perhaps rightly so. But with that situation I need some > other, and hopefully more robust means to detect off_t width. > > I am thinking of 3 options: > > * Keep _POSIX_V7 thingy but also add a check for _FILE_OFFSET_BITS == 64. > And then behave as if off_t is 32-bit. > * #undef _FILE_OFFSET_BITS at the first line in mmap_hooks.cc. It will > cause glibc on those legacy 32-bit off_t systems to define 32-bit off_t and > give me right defines and my code will define mmap symbol with 32-bit > offset arg and mmap64 symbol with 64-bit offset. And thus matching glibc. > * just manually hardcode knowledge that glibc + You need to undefine _FILE_OFFSET_BITS to get the expected types for off_t and off64_t on the mmap_hook.cc TU, since the whole idea is to override the symbol. You can also try to poke on glibc internals and use __off_t and __off64_t, which would not be redefined depending the the preprocessor (but tying to internal implementation is always a bad idea). So I would recommend this option, which seems to what you did and it is what sanitizers do also [1]. > {i386,arm{el,hf},mips32,ppc32} has 32-bit off_t. But that leaves the > question of how to deal with e.g. bionic (well, I could in principle say, > bionic already being broken enough is only supported for 64-bit systems, > which is where android systems are moving anyways) > > I am looking for any comments or suggestions. Particularly I'd like my fix > to be robust w.r.t. any further glibc evolution. [1] https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp#L15