Debian Bug report logs - #530949
gcc-4.4: warns about idiomatic use of Berkeley sockets

version graph

Package: gcc-4.4; Maintainer for gcc-4.4 is Debian GCC Maintainers <debian-gcc@lists.debian.org>; Source for gcc-4.4 is src:gcc-4.4.

Reported by: "brian m. carlson" <sandals@crustytoothpaste.net>

Date: Thu, 28 May 2009 22:30:07 UTC

Severity: wishlist

Found in version gcc-4.4/4.4.0-5

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Thu, 28 May 2009 22:30:10 GMT) Full text and rfc822 format available.

Acknowledgement sent to "brian m. carlson" <sandals@crustytoothpaste.ath.cx>:
New Bug report received and forwarded. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Thu, 28 May 2009 22:30:10 GMT) Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Thu, 28 May 2009 22:24:48 +0000
[Message part 1 (text/plain, inline)]
Package: gcc-4.4
Version: 4.4.0-5
Severity: wishlist

With the attached C file, gcc-4.4 warns:

  lakeview ok % gcc-4.4 -O2 -Wall socket.c
  socket.c: In function ‘main’:
  socket.c:20: warning: dereferencing pointer ‘sin’ does break strict-aliasing rules
  socket.c:21: warning: dereferencing pointer ‘sin’ does break strict-aliasing rules
  socket.c:19: warning: dereferencing pointer ‘sin’ does break strict-aliasing rules
  socket.c:12: note: initialized from here
  socket.c:23: warning: dereferencing pointer ‘sa’ does break strict-aliasing rules
  socket.c:11: note: initialized from here

This is a standard and idiomatic usage of Berkeley sockets.  AFAIK,
there is no other way to work with the sockets interface, and even if
there were, this method is extremely common, not to mention sanctioned
by POSIX.

gcc-4.4 should not warn with -Wall, which is supposed to be a sane
default with useful warnings.  I don't mind if gcc-4.4 warns with some
esoteric option, but warning about sockets-using code with -O2 -Wall is
silly.

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.30-rc5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages gcc-4.4 depends on:
ii  binutils                      2.19.1-1   The GNU assembler, linker and bina
ii  cpp-4.4                       4.4.0-5    The GNU C preprocessor
ii  gcc-4.4-base                  4.4.0-5    The GNU Compiler Collection (base 
ii  libc6                         2.9-13     GNU C Library: Shared libraries
ii  libgcc1                       1:4.4.0-5  GCC support library
ii  libgomp1                      4.4.0-5    GCC OpenMP (GOMP) support library

Versions of packages gcc-4.4 recommends:
ii  libc6-dev                     2.9-13     GNU C Library: Development Librari

Versions of packages gcc-4.4 suggests:
pn  gcc-4.4-doc                   <none>     (no description available)
pn  gcc-4.4-locales               <none>     (no description available)
ii  gcc-4.4-multilib              4.4.0-5    The GNU C compiler (multilib files
pn  libgcc1-dbg                   <none>     (no description available)
pn  libgomp1-dbg                  <none>     (no description available)
pn  libmudflap0-4.4-dev           <none>     (no description available)
pn  libmudflap0-dbg               <none>     (no description available)

-- no debconf information

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
[socket.c (text/x-csrc, attachment)]
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Fri, 29 May 2009 19:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Martin <philip@codematters.co.uk>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Fri, 29 May 2009 19:12:02 GMT) Full text and rfc822 format available.

Message #10 received at 530949@bugs.debian.org (full text, mbox):

From: Philip Martin <philip@codematters.co.uk>
To: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
Cc: 530949@bugs.debian.org
Subject: Re: Bug#530949: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Fri, 29 May 2009 20:07:34 +0100
"brian m. carlson" <sandals@crustytoothpaste.ath.cx> writes:

> This is a standard and idiomatic usage of Berkeley sockets.  AFAIK,
> there is no other way to work with the sockets interface, and even if
> there were, this method is extremely common, not to mention sanctioned
> by POSIX.

It may be idiomatic but it's not strictly valid and the warning
appears to be correct.  For example see:

https://bugzilla.redhat.com/show_bug.cgi?id=448743

which shows that the generated code may not be what you want, and also
suugests how to modify the source code to be valid.




Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Fri, 29 May 2009 21:33:08 GMT) Full text and rfc822 format available.

Acknowledgement sent to "brian m. carlson" <sandals@crustytoothpaste.ath.cx>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Fri, 29 May 2009 21:33:08 GMT) Full text and rfc822 format available.

Message #15 received at 530949@bugs.debian.org (full text, mbox):

From: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
To: Philip Martin <philip@codematters.co.uk>
Cc: 530949@bugs.debian.org
Subject: Re: Bug#530949: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Fri, 29 May 2009 21:11:34 +0000
[Message part 1 (text/plain, inline)]
On Fri, May 29, 2009 at 08:07:34PM +0100, Philip Martin wrote:
> It may be idiomatic but it's not strictly valid and the warning
> appears to be correct.  For example see:
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=448743
> 
> which shows that the generated code may not be what you want, and also
> suugests how to modify the source code to be valid.

It's still my opinion that this is an acceptable usage that is permitted
by POSIX, even if not by ISO C [0]:

  The <sys/socket.h> header shall define the sockaddr_storage structure.
  This structure shall be:
  
  	* Large enough to accommodate all supported protocol-specific
  	  address structures
  	* Aligned at an appropriate boundary so that pointers to it can be
  	  cast as pointers to protocol-specific address structures and used
  	  to access the fields of those structures without alignment
  	  problems

Please note: "pointers to [sockaddr_storage] can be cast as pointers to
protocol-specific address structures and used to access the fields of
those structures".

Also [0]:

  When a sockaddr_storage structure is cast as a sockaddr structure, the
  ss_family field of the sockaddr_storage structure shall map onto the
  sa_family field of the sockaddr structure. When a sockaddr_storage
  structure is cast as a protocol-specific address structure, the
  ss_family field shall map onto a field of that structure that is of
  type sa_family_t and that identifies the protocol's address family.

Obviously, POSIX intends code similar to the code I provided.

I expect that when used on a POSIX system (at least in strict POSIX mode
or when invoked as "c99"), gcc-4.4 neither warns nor generates code
contrary to POSIX with -O2 -Wall.  It may happen that the proper place
to fix this may be glibc; I believe there's a way to indicate to GCC
that a type may alias any other type, which may solve this problem.  If
that's the case, feel free to reassign this bug there.

If you believe POSIX is in error, please keep the bug and I in the loop
with respect to the defect report.

[0] http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/socket.h.html

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Fri, 29 May 2009 22:42:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Martin <philip@codematters.co.uk>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Fri, 29 May 2009 22:42:02 GMT) Full text and rfc822 format available.

Message #20 received at 530949@bugs.debian.org (full text, mbox):

From: Philip Martin <philip@codematters.co.uk>
To: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
Cc: 530949@bugs.debian.org
Subject: Re: Bug#530949: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Fri, 29 May 2009 23:35:28 +0100
"brian m. carlson" <sandals@crustytoothpaste.ath.cx> writes:

> I expect that when used on a POSIX system (at least in strict POSIX mode
> or when invoked as "c99"), gcc-4.4 neither warns nor generates code
> contrary to POSIX with -O2 -Wall.

You can add -fno-strict-aliasing which will disable the optimisation
and thus prevent the warning.  -O2 is documented to include
-fstrict-aliasing which is the optimisation that causes the warning.




Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Fri, 29 May 2009 22:51:07 GMT) Full text and rfc822 format available.

Acknowledgement sent to "brian m. carlson" <sandals@crustytoothpaste.ath.cx>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Fri, 29 May 2009 22:51:07 GMT) Full text and rfc822 format available.

Message #25 received at 530949@bugs.debian.org (full text, mbox):

From: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
To: Philip Martin <philip@codematters.co.uk>
Cc: 530949@bugs.debian.org
Subject: Re: Bug#530949: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Fri, 29 May 2009 22:46:58 +0000
[Message part 1 (text/plain, inline)]
On Fri, May 29, 2009 at 11:35:28PM +0100, Philip Martin wrote:
> "brian m. carlson" <sandals@crustytoothpaste.ath.cx> writes:
> 
> > I expect that when used on a POSIX system (at least in strict POSIX mode
> > or when invoked as "c99"), gcc-4.4 neither warns nor generates code
> > contrary to POSIX with -O2 -Wall.
> 
> You can add -fno-strict-aliasing which will disable the optimisation
> and thus prevent the warning.  -O2 is documented to include
> -fstrict-aliasing which is the optimisation that causes the warning.

I'm aware of that.  My opinion remains the same: GCC should generate
POSIX-conformant code without warnings with -O2 -Wall.  That can be
achieved by disabling -fstrict-aliasing at -O2, by patching glibc to
allow aliasing of the relevant types, by special-casing these types on a
POSIX system, or by something else altogether.  How it is achieved is
mostly irrelevant to me, as long as it stops breaking code that is
explicitly documented by POSIX to work (and has worked for longer than
I've been alive).

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Fri, 29 May 2009 23:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Philip Martin <philip@codematters.co.uk>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Fri, 29 May 2009 23:18:02 GMT) Full text and rfc822 format available.

Message #30 received at 530949@bugs.debian.org (full text, mbox):

From: Philip Martin <philip@codematters.co.uk>
To: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
Cc: 530949@bugs.debian.org
Subject: Re: Bug#530949: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Sat, 30 May 2009 00:15:17 +0100
"brian m. carlson" <sandals@crustytoothpaste.ath.cx> writes:

> I'm aware of that.  My opinion remains the same: GCC should generate
> POSIX-conformant code without warnings with -O2 -Wall.  That can be
> achieved by disabling -fstrict-aliasing at -O2, by patching glibc to
> allow aliasing of the relevant types, by special-casing these types on a
> POSIX system, or by something else altogether.  How it is achieved is
> mostly irrelevant to me, as long as it stops breaking code that is
> explicitly documented by POSIX to work (and has worked for longer than
> I've been alive).

The definition of c99 from your earlier POSIX reference

http://www.opengroup.org/onlinepubs/000095399/utilities/c99.html

states that the compiler should accept code conforming to the ISO C
standard.  The code you are trying to compile doesn't conform.




Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#530949; Package gcc-4.4. (Sat, 30 May 2009 00:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "brian m. carlson" <sandals@crustytoothpaste.ath.cx>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. (Sat, 30 May 2009 00:21:02 GMT) Full text and rfc822 format available.

Message #35 received at 530949@bugs.debian.org (full text, mbox):

From: "brian m. carlson" <sandals@crustytoothpaste.ath.cx>
To: Philip Martin <philip@codematters.co.uk>
Cc: 530949@bugs.debian.org
Subject: Re: Bug#530949: gcc-4.4: warns about idiomatic use of Berkeley sockets
Date: Sat, 30 May 2009 00:18:58 +0000
[Message part 1 (text/plain, inline)]
On Sat, May 30, 2009 at 12:15:17AM +0100, Philip Martin wrote:
> The definition of c99 from your earlier POSIX reference
> 
> http://www.opengroup.org/onlinepubs/000095399/utilities/c99.html
> 
> states that the compiler should accept code conforming to the ISO C
> standard.  The code you are trying to compile doesn't conform.

POSIX (and XSI) specify certain extensions.  For example, (a draft
of[0]) the C standard states:

  All identifiers that begin with an underscore and either an uppercase
  letter or another underscore are always reserved for any use.

Yet POSIX states:

  A POSIX-conforming application should ensure that the feature test
  macro _POSIX_C_SOURCE is defined before inclusion of any header.

According to ISO C, that POSIX-mandated behavior is not allowed.
dlsym(3) contains another example in its Rationale section, except for
XSI instead of all POSIX systems.

[0] I don't really care to purchase the actual standard, but it's
probably nearly identical.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
[signature.asc (application/pgp-signature, inline)]

Changed Bug submitter to '"brian m. carlson" <sandals@crustytoothpaste.net>' from '"brian m. carlson" <sandals@crustytoothpaste.ath.cx>' Request was from "brian m. carlson" <sandals@crustytoothpaste.net> to control@bugs.debian.org. (Thu, 03 Feb 2011 20:51:41 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Mon Apr 21 16:22:17 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.