This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Gcc builtin functions used by glibc not available on mips



Hi HJ,

May I also add my voice to the throng pointing out that:

The __builtin form of a GCC function should never be used where it
is unsafe to call the equivalent standard C library function directly.

[This is actually middle-end PR 3474, for which I intend to submit a
documentation fix, i.e. you also can't call __builtin_sqrtf on platforms
that don't have a C library sqrtf!]


The compiler assumes that it is always free to call the library function
and evaluates a real call as a possible alternative to inlining.
The decision to inline __builtin_memset is made based upon whether
the arguments are constant and their values, whether the destination
has a suitable alignment, processor settings, optimization settings
etc...

Unfortunately, the previously suggested test for __builtin_memset via
autoconf is not particularly useful, as changing any of these factors
that affect whether an intrinsic is inlined, can change the behaviour.
For example, changing command line options for different multilibs, or
from -O2 to -Os, or adding -ffast-math can often change when intrinisics
are inlined.  It is not unreasonable that the compiler might inline the
simple example call to __builtin_memset in the configure tests, but still
(occasionally) call library memset explicitly for the __builtin_memset
in _dl_start.

May I strongly recommend the safe (but completely untested) option:


2002-02-07  Roger Sayle  <roger@eyesopen.com>
	* elf/rtld.c (_dl_start): __builtin_memset can implicitly call
	the library memset, so initialize arrays explicitly.


*** libc/elf/rtld.c	Thu Feb  7 20:41:56 2002
--- patch/elf/rtld.c	Thu Feb  7 20:47:06 2002
*************** _dl_start (void *arg)
*** 130,138 ****
  {
    struct link_map bootstrap_map;
    hp_timing_t start_time;
- #ifndef HAVE_BUILTIN_MEMSET
    size_t cnt;
- #endif

    /* This #define produces dynamic linking inline functions for
       bootstrap relocation instead of general-purpose relocation.  */
--- 130,136 ----
*************** _dl_start (void *arg)
*** 147,163 ****
      HP_TIMING_NOW (start_time);

    /* Partly clean the `bootstrap_map' structure up.  Don't use
!      `memset' since it might not be built in or inlined and we cannot
!      make function calls at this point.  Use '__builtin_memset' if we
!      know it is available.  */
! #ifdef HAVE_BUILTIN_MEMSET
!   __builtin_memset (bootstrap_map.l_info, '\0', sizeof (bootstrap_map.l_info));
! #else
    for (cnt = 0;
         cnt < sizeof (bootstrap_map.l_info) / sizeof (bootstrap_map.l_info[0]);
         ++cnt)
      bootstrap_map.l_info[cnt] = 0;
- #endif

    /* Figure out the run-time load address of the dynamic linker itself.  */
    bootstrap_map.l_addr = elf_machine_load_address ();
--- 145,156 ----
      HP_TIMING_NOW (start_time);

    /* Partly clean the `bootstrap_map' structure up.  Don't use
!      `memset' or `__builtin_memset' since it might not be built in or
!      inlined and we cannot make function calls at this point.  */
    for (cnt = 0;
         cnt < sizeof (bootstrap_map.l_info) / sizeof (bootstrap_map.l_info[0]);
         ++cnt)
      bootstrap_map.l_info[cnt] = 0;

    /* Figure out the run-time load address of the dynamic linker itself.  */
    bootstrap_map.l_addr = elf_machine_load_address ();


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]