This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: Possible g++ bug


> 
> 
> On 17-Apr-99 H.J. Lu wrote:
> >> 
> >> 
> >> 
> >>   H.J.,
> >> 
> >>        I don't have sufficient authority on any
> >>   alphaev56-unknown-linux-gnu system to be able
> >>   to swear this this bug is not due to the local
> >>   environment.  I would be grateful if you would
> >>   make a test for me.
> >> 
> >>   Break the text below into two files, say BugTest.cc
> >>   and BugTestLib.cc
> >> 
> >>   g++ -o BugTest -O0 BugTest.cc BugTestLib.cc
> >> 
> >>   Everything is fine on ix86 and powerpc (32 bits),
> >>   but with egcs-1.1.2, binutils-2.9.1.0.23 and
> >>   libc-2.0.7pre6, on our Linux-Alpha's  => memory leak.
> >>   Current egcs-CVS-mainline does the same thing.
> >> 
> > 
> > Could you please tell me which one you think has
> > memory leak, the compiler or the resulting binary?
> 
>   The resulting binary.
>   ====================
> 
> //---------------------------------------------------------------
> //  BugTestLib.cpp:
> #include <string>
> 
> std::string upcase(const std::string& s)
> {
>    std::string s2(s);
> 
>    for(unsigned int ii = 0; ii < s2.length(); ii++)
>       s2[ii] = toupper(s2[ii]);
> 
>    return s2;
> }
> //---------------------------------------------------------------
> 
>   The s2 handle is not being cleaned up after s2 is processed
>   by the calling routine.
> 
>   The has been some debate about the legality of the code.
>   The opinion of our local "language lawers" is that while
>   returning a pointer would be illegal, we need to return
>   a string.  That should be okay.
> 
>   Still, the difference between Alpha and (ix86 & powerpc)
>   execution is very evident.  When the compiler is able to
>   see both code segments, the is no problem on Alpha either.
> 
>   Thank you for your time.
> 
> 

Hi,

It turned to be an ELF/alpha linker bug. It is in both binutils
2.9.1.0.23 and the gas snapshot 990410. The problem is when there are
2 identical weak symbols in 2 .o files, the ELF/alpha linker doesn't
get rid of one of them. You wind up with 2 symbols referenced from 2 .o
files, instead of one symbol shared by 2 .o files. The ELF/x86 linker
is ok. I hope some will fix the ELF/alpha linker since that bug affects
most if not all C++ codes.

Ian, Richard, I thought the ELF weak symbol handling was not CPU
dependent. I guess I was wrong.

Thanks.


H.J.
----
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-04-18 12:48 PDT by <hjl@ocean.lucon.org>.
# Source directory was `/home/hjl/bugs/bfd/alpha2'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    439 -rw-r--r-- Makefile
#    114 -rw-r--r-- x.cc
#     75 -rw-r--r-- xlib.cc
#    586 -rw-r--r-- x.h
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh29181; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= Makefile ==============
if test -f 'Makefile' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Makefile' '(file already exists)'
else
  $echo 'x -' extracting 'Makefile' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CC=gcc 
CFLAGS=-O0 -g
ARCH=$(shell arch)
X
PROGS=x.$(ARCH)
SRCS=$(PROGS:=.cc)
SRCS=x.cc xlib.cc
ASMS=$(SRCS:.cc=.s)
X
all: $(PROGS)
X	for f in $(PROGS); do echo "Running: $$f"; $$f; \
X	  if [ $$? != 0 ]; then echo Failed; fi; done
X
asm: $(ASMS)
X
X.cc.s:
X	$(CC) -S $(CFLAGS) $<
X
$(PROGS): $(SRCS)
X	$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
X
clean:
X	$(RM) -f *.s *.ii.* *.cc.* *.c.* $(PROGS) *.o core a.out
X
shar:
X	shar Makefile $(SRCS) x.h > shar.out
SHAR_EOF
  $shar_touch -am 0418124899 'Makefile' &&
  chmod 0644 'Makefile' ||
  $echo 'restore of' 'Makefile' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Makefile:' 'MD5 check failed'
4c1615325f8f2eaa6ea361f6db3e5348  Makefile
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
    test 439 -eq "$shar_count" ||
    $echo 'Makefile:' 'original size' '439,' 'current size' "$shar_count!"
  fi
fi
# ============= x.cc ==============
if test -f 'x.cc' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'x.cc' '(file already exists)'
else
  $echo 'x -' extracting 'x.cc' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'x.cc' &&
#include "x.h"
X
extern void *xlib ();
X
main ()
{
X  alloc x;
X
X  if (x.get_free_list () != xlib ())
X    abort ();
}
SHAR_EOF
  $shar_touch -am 0418124699 'x.cc' &&
  chmod 0644 'x.cc' ||
  $echo 'restore of' 'x.cc' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'x.cc:' 'MD5 check failed'
a34201d7566dd0f03c664d8c08a70dec  x.cc
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'x.cc'`"
    test 114 -eq "$shar_count" ||
    $echo 'x.cc:' 'original size' '114,' 'current size' "$shar_count!"
  fi
fi
# ============= xlib.cc ==============
if test -f 'xlib.cc' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'xlib.cc' '(file already exists)'
else
  $echo 'x -' extracting 'xlib.cc' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'xlib.cc' &&
#include "x.h"
X
void *xlib ()
{
X  alloc x;
X
X  return x.get_free_list ();
}
SHAR_EOF
  $shar_touch -am 0418124799 'xlib.cc' &&
  chmod 0644 'xlib.cc' ||
  $echo 'restore of' 'xlib.cc' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'xlib.cc:' 'MD5 check failed'
41b7b13172487f909c7942933bdc1865  xlib.cc
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'xlib.cc'`"
    test 75 -eq "$shar_count" ||
    $echo 'xlib.cc:' 'original size' '75,' 'current size' "$shar_count!"
  fi
fi
# ============= x.h ==============
if test -f 'x.h' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'x.h' '(file already exists)'
else
  $echo 'x -' extracting 'x.h' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'x.h' &&
#include <stdio.h>
X
template <bool threads>
class __default_alloc_template
{
public:
X  enum {__ALIGN = 8};
X  enum {__MAX_BYTES = 128};
X  enum {__NFREELISTS = __MAX_BYTES/__ALIGN};
X  union obj
X  {
X    union obj * free_list_link;
X    char client_data[1];
X  };
X
X  static obj * free_list[__NFREELISTS];
X  void * get_free_list ()
X  {
X     return free_list;
X  }
};
X
template <bool threads>
__default_alloc_template<threads>::obj * 
__default_alloc_template<threads>::free_list[__NFREELISTS]
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
X
typedef __default_alloc_template<true> alloc;
SHAR_EOF
  $shar_touch -am 0418124699 'x.h' &&
  chmod 0644 'x.h' ||
  $echo 'restore of' 'x.h' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'x.h:' 'MD5 check failed'
a2aa59b45e35ae1d829761bd8aab9570  x.h
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'x.h'`"
    test 586 -eq "$shar_count" ||
    $echo 'x.h:' 'original size' '586,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh29181
exit 0


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