From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7709 invoked by alias); 30 Jun 2017 15:03:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 6519 invoked by uid 89); 30 Jun 2017 15:03:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=BAYES_00,GIT_PATCH_2,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=qualifier, compound X-HELO: mail-qt0-f178.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xeFHhLn7bNyyVQ0VZ8691u7zpWFF4qT/O/auBQwrAxw=; b=gX3GxXL2xG8Xf/mIBShieweZ07jYVTENxR+gSJGBgRIKr8H8Lk9QGjhCixJXwoQ502 auvKR6uI/s8rCmXwfVU0ZndbxmVT+4fvmnVeU5HLqPfuYt2mQedo/V24kij2u4ENVbVD rU/hGuJh52f3DOXbcikOTrrJ+E3Qn1P8P37bKxcBr2VgwBhHumYmvhJn9E3/fi9LjCR+ C7TgE+JRAJylCbodYVjJgX2PQ/KIb0DS/10LXdupT/ludWNhDm79C1on7oj0dPtegKym +2zvAw0+KxYX7G1hjl62/NM1CJu3yQ5yuKyqg7VBPKlU0pIUrkF9u3G6lfVvQeHv3zcf jNyA== X-Gm-Message-State: AKS2vOwGlFDpfXH6ADe9qPWKUFtQtx9OUtmgW1V2B0CvJPeX2q87FzVf cLMTjblteE3XNMO7Qc80NQ== X-Received: by 10.200.43.33 with SMTP id 30mr27607802qtu.202.1498835013365; Fri, 30 Jun 2017 08:03:33 -0700 (PDT) Subject: Re: [PATCH 1/5] Fix {INLINE,INTERNAL}_SYSCALL macros for x32 To: Florian Weimer Cc: libc-alpha@sourceware.org References: <1495563960-669-1-git-send-email-adhemerval.zanella@linaro.org> <1495563960-669-2-git-send-email-adhemerval.zanella@linaro.org> <4978d161-d01d-4d25-ca79-6b2e0cc27ba4@linaro.org> <721450e3-0b8f-971f-da78-12163f9d4f12@redhat.com> From: Adhemerval Zanella Message-ID: <2fdffc50-e044-bee8-0238-a85501327714@linaro.org> Date: Fri, 30 Jun 2017 15:03:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <721450e3-0b8f-971f-da78-12163f9d4f12@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2017-06/txt/msg01623.txt.bz2 On 29/06/2017 15:50, Florian Weimer wrote: > On 06/29/2017 04:15 PM, Adhemerval Zanella wrote: >> +/* Create a variable 'name' based on type 'X' to avoid explicit types. >> + This is mainly used set use 64-bits arguments in x32. */ >> +#define TYPEFY(X, name) __typeof__ ((X) - (X)) name >> +/* Explicit cast the argument to avoid integer from pointer warning on >> + x32. */ >> +#define ARGIFY(X) ((__typeof__ ((X) - (X))) (X)) > > I think cast_to_integer was added for this purpose. The 'cast_to_integer' macro was added after my initial (I based the ARGIFY macro on the mips64n32 one) and checking it by replacing ARGIGY with 'cast_to_integer' I see: --- gconv_cache.c: In function ‘__gconv_load_cache’: ../include/libc-pointer-arith.h:34:45: error: cast specifies array type __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \ ^ ../include/libc-pointer-arith.h:29:39: note: in definition of macro ‘__integer_if_pointer_type_sub’ __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \ ^ ../include/libc-pointer-arith.h:38:33: note: in expansion of macro ‘__integer_if_pointer_type’ # define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val)) ^~~~~~~~~~~~~~~~~~~~~~~~~ ../sysdeps/unix/sysv/linux/x86_64/sysdep.h:284:29: note: in expansion of macro ‘cast_to_integer’ TYPEFY (arg1, __arg1) = cast_to_integer (arg1); \ ^~~~~~~~~~~~~~~ ../sysdeps/unix/sysv/linux/x86_64/sysdep.h:230:2: note: in expansion of macro ‘internal_syscall3’ internal_syscall##nr (SYS_ify (name), err, args) ^~~~~~~~~~~~~~~~ ../sysdeps/unix/sysv/linux/x86_64/sysdep.h:196:35: note: in expansion of macro ‘INTERNAL_SYSCALL’ unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \ ^~~~~~~~~~~~~~~~ ../sysdeps/unix/sysv/linux/not-cancel.h:31:4: note: in expansion of macro ‘INLINE_SYSCALL’ INLINE_SYSCALL (open, 3, name, flags, mode) --- And I recall this was one the issue I had when creating this patch. Using compound literal on __typeof__ cast did not help due we build with -Wwrite-strings it and in turn it enables -Wdiscarded-array-qualifiers. This triggers a 'pointer to array loses qualifier', because constness type is propagate. So to actually use cast_to_integer workable on char array (and on other arrays as well) one solution is to incorporate the arithmetic promotion used on mips64n32 sysdep and also on this patch: --- /* Type cast using arithmetic promotion. It also remove l-value-constness when using char arrays on cast_to_interger (for instance cast_to_interger ("...") will not trigger a 'pointer to array loses qualifier' warning due -Wdiscarded-array-qualifiers from -Wwrite-strings. */ # define __typeof_arith_promote(T) __typeof__((T) - (T)) /* 1 if 'type' is a pointer type, 0 otherwise. */ # define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5) /* intptr_t if P is true, or T if P is false. */ # define __integer_if_pointer_type_sub(T, P) \ __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0: (void *) (P))) 0 \ : (__typeof__ (0 ? (intptr_t *) 0: (void *) (!(P)))) 0)) /* intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */ # define __integer_if_pointer_type(expr) \ __integer_if_pointer_type_sub(__typeof__ ((__typeof_arith_promote (expr)) 0), \ __pointer_type (__typeof_arith_promote (expr))) /* Cast an integer or a pointer VAL to integer with proper type. */ # define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val)) --- I am not sure how safe is the arithmetic promotion in the all the possible cases where one could use cast_to_integer, however current cases on atomic and syscall usage should be safe (make check shows no regression on x86_64{-x32} with the pread auto-generate removal applied, so they use the default Linux implementation. If you think it is worth I can resend with the libc-pointer-arith.h modification.