Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 48797 - glibc-2.3.3 bug in strpbrk() in bits/string2.h causes compile failures with gcc-3.4
Summary: glibc-2.3.3 bug in strpbrk() in bits/string2.h causes compile failures with g...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Please assign to toolchain
URL: http://sources.redhat.com/bugzilla/sh...
Whiteboard:
Keywords:
Depends on:
Blocks: 48798
  Show dependency tree
 
Reported: 2004-04-23 10:22 UTC by Ed Catmur
Modified: 2004-07-11 15:45 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Catmur 2004-04-23 10:22:50 UTC
Reported upstream, including test case and patch. 

Patch is suitable for adding to gentoo.org glibc ebuild.
Comment 1 Travis Tilley (RETIRED) gentoo-dev 2004-04-23 11:07:13 UTC
would you mind providing a little more information here? this is a pretty sparse bug report.

of course, we should really roll out a new snapshot anyways.
Comment 2 Ed Catmur 2004-04-23 11:41:13 UTC
Sorry. Upstream URL is http://sources.redhat.com/bugzilla/show_bug.cgi?id=130

Copy of bug:

=============================================

>  $ cat foo.c
>  #include <string.h>
>  int main(int argc, char *argv[]) {
>          return (int) ((strpbrk("string", "n")) - "string");
>  }
>  $ /usr/i686-pc-linux-gnu/gcc-bin/3.4/gcc -O foo.c
>  foo.c: In function `main':
>  foo.c:3: error: invalid operands to binary -

-O is necessary to make gcc include the optimising macro definition of strpbrk()
in bits/string2.h:

#  define strpbrk(s, accept) \
  __extension__								      \
  ({ char __a0, __a1, __a2;						      \
     (__builtin_constant_p (accept) && __string2_1bptr_p (accept)	      \
      ? ((__a0 = ((__const char  *) (accept))[0], __a0 == '\0')		      \
	 ? ((void) (s), NULL)						      \
	 : ((__a1 = ((__const char *) (accept))[1], __a1 == '\0')	      \
	    ? strchr (s, __a0)						      \
	    : ((__a2 = ((__const char *) (accept))[2], __a2 == '\0')	      \
	       ? __strpbrk_c2 (s, __a0, __a1)				      \
	       : (((__const char *) (accept))[3] == '\0'		      \
		  ? __strpbrk_c3 (s, __a0, __a1, __a2)			      \
		  : strpbrk (s, accept)))))				      \
      : strpbrk (s, accept)); })
# endif

Offending line is:
	 ? ((void) (s), NULL)						      \

This is not detected as a bug when compiling with gcc 3.3.

Test case and patch attached.

==========================================

I have checked the glibc ViewCVS and the bug is in the current CVS head, so a new snapshot will not help with this bug (not yet, anyway).
Comment 3 Ed Catmur 2004-04-23 11:58:51 UTC
To be perfectly clear:

This is a bug in bits/string2.h in glibc: the macro definition of strpbrk() expands to a ?: expression which can have a type of (char *) or NULL, which in Linux is of type (void *). This is a bug as one cannot use (void *) everywhere (char *) is allowable, in this instance on the LHS of the - operator.

It manifests itself with gcc 3.4, when compiling with -O{,1,2,3}: gcc 3.4 as gcc 3.3 is lax and does not detect the bug (possibly an implicit cast is performed, but what do I know) and -O{,1,2,3} as -Os and (no -O flag) prevent the macro form of strpbrk() being used.

This needs to be fixed upstream, but in the meantime can be fixed within gentoo.org. 

It will show up as bugs compiling packages with gcc 3.4, e.g. bug 48798.
Comment 4 Ed Catmur 2004-04-30 08:42:09 UTC
Upstream:

>  ------- Additional Comment #3 From Jakub Jelinek  2004-04-30 08:52  [reply] -------
> 
> Fix commited to glibc CVS on 2004-04-29.

Will close when new glibc is packaged from cvs.
Comment 6 Joshua Kinard gentoo-dev 2004-05-01 17:20:19 UTC
I'm testing a glibc compile that includes a patch for this bug and a sparc bug (taken from their CVS).  If it works out okay, I'll make a -r1 ebuild with them.
Comment 7 Travis Tilley (RETIRED) gentoo-dev 2004-07-11 14:27:59 UTC
well, this should work if using a snapshot later than 2004-04-29 like amd64 does... anyone object to adding this patch to 20040420 so that x86 gets the fix?

i'll poke at morfic too, since he's working on getting gcc 3.4 up to par on x86.
Comment 8 Travis Tilley (RETIRED) gentoo-dev 2004-07-11 15:06:47 UTC
<morfic> and when i make x86-gcc-3.4 profile ill make 0605 glibc part of it
Comment 9 Disenchanted (RETIRED) gentoo-dev 2004-07-11 15:45:19 UTC
i plan on making a x86-gcc3.4 profile based on sys-libs/glibc-2.3.4.20040605

upstream fixes like this show exactly why it makes sense to stick to this version that has worked for me (x86) for the last 36 days w/o a hitch, all i have come across was lousy sources needing fixing, so far nothing relating to glibc

Travis: stop causing mid air collisions!