Bug 10369

Summary: strchr() is implemented as a macro
Product: [Retired] Red Hat Linux Reporter: Kjetil T. Homme <kjetilho>
Component: glibcAssignee: Cristian Gafton <gafton>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-03-27 16:03:23 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kjetil T. Homme 2000-03-27 12:01:25 UTC
This causes good old K&R code with redundant prototypes to miscompile:

cknfs.c:184: macro `strchr' used without args

These functions need to be inlined instead.

Workaround:  Compile with -g rather than -O.

Comment 1 Bill Nottingham 2000-03-27 16:03:59 UTC
It's in the glibc FAQ:


3.8.    I've got errors compiling code that uses certain string
        functions.  Why?

{AJ} glibc 2.1 has special string functions that are faster than the normal
library functions.  Some of the functions are additionally implemented as
inline functions and others as macros.  This might lead to problems with
existing codes but it is explicitly allowed by ISO C.

The optimized string functions are only used when compiling with
optimizations (-O1 or higher).  The behavior can be changed with two feature
macros:

* __NO_STRING_INLINES: Don't do any string optimizations.
* __USE_STRING_INLINES: Use assembly language inline functions (might
  increase code size dramatically).

Since some of these string functions are now additionally defined as macros,
code like "char *strncpy();" doesn't work anymore (and is unnecessary, since
<string.h> has the necessary declarations).  Either change your code or
define __NO_STRING_INLINES.

{UD} Another problem in this area is that gcc still has problems on machines
with very few registers (e.g., ix86).  The inline assembler code can require
almost all the registers and the register allocator cannot always handle
this situation.

One can disable the string optimizations selectively.  Instead of writing

        cp = strcpy (foo, "lkj");

one can write

        cp = (strcpy) (foo, "lkj");

This disables the optimization for that specific call.