From owner-freebsd-hackers@freebsd.org Sat Jan 20 23:27:37 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 26833ECD2CD for ; Sat, 20 Jan 2018 23:27:37 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) Received: from sonic302-4.consmr.mail.bf2.yahoo.com (sonic302-4.consmr.mail.bf2.yahoo.com [74.6.135.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E3DEE6FD8D for ; Sat, 20 Jan 2018 23:27:36 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) X-YMail-OSG: RU4jjAIVM1kwHHpPaWj5mI469eeKAaxVMj2AY52F0cJm3BjJVb8hrE6Qsdg5aXD TVPC4j40C_tMAGYVa9E3730IGmz4_Uuch4HzpYBZheJrrWXWcTZZldkI.8kxJ2Xv0OzGf3Mx7C2Z XNVSHxoBV6oshOzyFU3a.4L_SM9rxM5G8R2WFlXpc5lKEK9etUsc_MWr05SSvs_ea1bkh_obSdmv iZXEfaSCIWvDYtXzO7y19vebuqzGfmQy2QcybTOnBlt4z19dfTS8VCbPKZ8MYXvIXZTAxLcUHUJP FQ_k6hPjdFaJ0RNmp9VokEQkJ1ysF6iPHSeXJb4Utd_XUZ1JUjEY4bgEOwT4GyofC1HJVXgthdyl ci86dWWiZCLGX5LD6CV9KtMniV_8BT5vLXK9h7hNLcEs79c4lEP3ie.T7_Zp75JIpx6z7oYlu1_C D09FZbkgOmR8LWKBopsNLBKT5yy3BK46MYtcbSZuBKXFNgNzKHMPIG4qYf1Ly4fj5Mzh2 Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Sat, 20 Jan 2018 23:27:30 +0000 Received: from smtp106.rhel.mail.bf1.yahoo.com (EHLO [192.168.1.25]) ([98.139.231.40]) by smtp404.mail.bf1.yahoo.com (JAMES SMTP Server ) with ESMTPA ID 26a397299a489e18397ec8a26c8a640a; Sat, 20 Jan 2018 23:27:25 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Attribute alloc__size use and clang 5.0.1 vs. gcc7 (e.g.): __builtin_object_size(p,1) and __builtin_object_size(p,3) disagreements result Message-Id: <1AA0993D-81E4-4DC0-BBD9-CC42B26ADB1C@yahoo.com> Date: Sat, 20 Jan 2018 15:27:23 -0800 To: Pedro Giffuni , FreeBSD Toolchain , FreeBSD Hackers X-Mailer: Apple Mail (2.3273) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jan 2018 23:27:37 -0000 [Bugzilla 225197 indirectly lead to this. Avoiding continuing there.] I decided to compare some alternate uses of __attribute__((alloc_size(. . .))) compiled and run under clang 5.0.1 and gcc7. I did not get what I expected based on prior discussion material. This is an FYI since I do not know how important the distinctions that I found are. Here is the quick program: # more alloc_size_attr_test.c=20 #include #include __attribute__((alloc_size(1,2))) void* my_calloc_alt0(size_t n, size_t s) { void* p =3D calloc(n,s); printf("calloc __builtin_object_size 0,1,2,3: %ld, %ld, %ld, %ld\n" ,(long) __builtin_object_size(p, 0) ,(long) __builtin_object_size(p, 1) ,(long) __builtin_object_size(p, 2) ,(long) __builtin_object_size(p, 3) ); return p; } __attribute__((alloc_size(1))) __attribute__((alloc_size(2))) void* my_calloc_alt1(size_t n, size_t s) { void* p =3D calloc(n,s); printf("calloc __builtin_object_size 0,1,2,3: %ld, %ld, %ld, %ld\n" ,(long) __builtin_object_size(p, 0) ,(long) __builtin_object_size(p, 1) ,(long) __builtin_object_size(p, 2) ,(long) __builtin_object_size(p, 3) ); return p; } int main() { void* p =3D my_calloc_alt0(2,7); printf("my_calloc_alt0 __builtin_object_size 0,1,2,3: %ld, %ld, %ld, = %ld\n" ,(long) __builtin_object_size(p, 0) ,(long) __builtin_object_size(p, 1) ,(long) __builtin_object_size(p, 2) ,(long) __builtin_object_size(p, 3) ); void* q =3D my_calloc_alt1(2,7); printf("my_calloc_alt0 __builtin_object_size 0,1,2,3: %ld, %ld, %ld, = %ld\n" ,(long) __builtin_object_size(q, 0) ,(long) __builtin_object_size(q, 1) ,(long) __builtin_object_size(q, 2) ,(long) __builtin_object_size(q, 3) ); } # uname -apKU FreeBSD FBSDFSSD 12.0-CURRENT FreeBSD 12.0-CURRENT r327485M amd64 = amd64 1200054 1200054 The system-clang 5.0.1 result was: # clang -O2 alloc_size_attr_test.c # ./a.out calloc __builtin_object_size 0,1,2,3: 14, 14, 14, 0 my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 calloc __builtin_object_size 0,1,2,3: 14, 14, 14, 0 my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 The lang/gcc7 result was: # gcc7 -O2 alloc_size_attr_test.c # ./a.out calloc __builtin_object_size 0,1,2,3: -1, -1, 0, 0 my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 14 calloc __builtin_object_size 0,1,2,3: -1, -1, 0, 0 my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 7, 14, 14 I'll ignore that gcc does not provide actual sizes via __builtin_object_size for calloc use. Pairing the other lines for easy comparison, with some notes mixed in: __attribute__((alloc_size(1,2))) style: my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 (system = clang) my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 14 (gcc7) __attribute__((alloc_size(1))) __attribute__((alloc_size(2))) style: my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 14, 14, 0 (system = clang) my_calloc_alt0 __builtin_object_size 0,1,2,3: 14, 7, 14, 14 (gcc7) Thus. . . For __attribute__((alloc_size(1))) __attribute__((alloc_size(2))): __builtin_object_size(p,1) is not equivalent (clang vs. gcc7) For both of the alloc_size usage styles: __builtin_object_size(p,3) is not equivalent (clang vs. gcc7) This means that the two style of alloc_size use are not equivalent across some major compilers/toolchains. But I do not know if either of the differences is a problem or not. Note: without a sufficient -O all the figures can be the mix of -1's and 0's. =3D=3D=3D Mark Millard marklmi at yahoo.com ( markmi at dsl-only.net is going away in 2018-Feb, late)