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]

p9732.C wierdness, wwas: patch to improve g++ test results on openserver


>   > I suspect the ASM_OUTPUT_ALIGNED_BSS thing is a placebo,
> Most likely.
> 
> Let me guess -- you're seeing unaligned sections after the .bss
> section?

Actually, it wasn't anything so scientific.   I built a Linux
cross assembler (Linux allegedly passed the test in question) 
and compared the -S output of it to that of the native egcs.

I then tried to bring sco5.h into sync with linux.h until the
test passed on my target, too. :-)

> However, defining ASM_OUTPUT_ALIGNED_BSS is a good thing since it
> reduces wasted space in the .bss section.

I couldn't tell that it made a functional difference on the test 
in question and it didn't seem to introduce any additional failures.   

> My only concern is that the native sco assembler wouldn't handle it,
> can you check that for me?

Currently, the SCO-provided assembler is the only one supported
by egcs.

>   > if you don't like it, drop it.   The ATEXIT thing is the 
>   > important one here.
> Can you elaborate a little more here -- if it's causing problems on
> sco, then I'd like to know if we need to make a similar change for
> other platforms.

Sure, becuase I don't feel really comfortable with this anyway.
My change makes the test pass, but it also changes the behaviour
of the test.

Let's start with g++.mike/p9732b.C and throw some printfs in it.
This file will hereafter be called "/tmp/p.C"


// prms-id: 9732

int count;
int bail = 0;

struct base {
   base () { printf("++count\n"); ++count; }
   ~base () { printf("--count\n"); --count; }
  base(const base&o) {printf("Base\n");  ++count; }
};

class D {
public:
  ~D() {
    if (bail++)
      {
printf("Linux test. Bail %d\n", bail);
	// On some Linux boxes, we run the dtor for d twice,
	// once before exit, and once after!
printf("Linux test. Calling abort %d\n", bail);
	abort ();
      }
    else
      {
	if (count != 0)
{
printf("count %d\n", count);
	  exit (1);
}
	exit (0);
      }
  }
} d;

base base_object;

base base_returning_function ();

const base& base_ref = base_returning_function ();

int main () {
}

base base_returning_function () {
  base local_base_object;
  return local_base_object;
}


In COFF mode, we see count get decremented three times:

$ ./negcs -mcoff -O -fno-exceptions /tmp/p.C && ./a.out && echo $?
/tmp/p.C: In method `base::base()':
/tmp/p.C:7: warning: implicit declaration of function `int printf(...)'
++count
++count
Base
--count
--count
--count
0


ELF mode used to dump core sometime after exit() was called.    


Starting program: /home/play/ss/a.out
++count
++count
Base
--count
--count
--count

Breakpoint 1, 0x8003ded9 in abort ()
(gdb) where
#0  0x8003ded9 in abort ()
#1  0x8001d46f in _exithandle ()
#2  0x800196d6 in exit ()
#3  0x80485a6 in __do_global_dtors_aux ()
#4  0x8049019 in .text ()
#5  0x800196d6 in exit ()
(gdb) print __DTOR_LIST__[0]
Cannot access memory at address 0xffffffff.
(gdb) print __DTOR_LIST__[1]
$4 = 0
(gdb) print __DTOR_LIST__[2]
$5 = 0

If I disassemble the startup code, I see atexit() being called
three times.
	the call to _cleanup()
	the call to _DYNAMIC
	the call to .fini 

Now, if I set breakpoints on each of those, the first one that
gets called is .fini().   We call do_global_dtors_aux().

Breakpoint 7, 0x80485a6 in __do_global_dtors_aux ()
(gdb) step
Single stepping until exit from function __do_global_dtors_aux,
which has no line number information.
global destructors keyed to bail () at /tmp/p.C:8
8          ~base () { printf("--count\n"); --count; }
(gdb)
--count
--count
15          if (bail++)
(gdb)
25              if (count != 0)
(gdb)
30              exit (0);
(gdb)

Breakpoint 1, 0x8003ded9 in abort ()
(gdb)

(gdb) print __DTOR_LIST__[0]
Cannot access memory at address 0xffffffff.
(gdb) print __DTOR_LIST__[1[
A syntax error in expression, near `'.
(gdb) print __DTOR_LIST__[1]
$2 = 0



Removing the HAVE_ATEXIT makes it no longer dumps core, but 
count is decremented only once instead of three times.


$ ./negcs -melf -O -fno-exceptions /tmp/p.C && ./a.out && echo $?
/tmp/p.C: In method `base::base()':
/tmp/p.C:7: warning: implicit declaration of function `int printf(...)'
++count
++count
Base
--count
0




You know, after explaining it like this, I think you're right
to question this.    I've done something bad in covering this
up, haven't I?    Certainly the coff and elf versions should do
the same thing.   It would be nice if they did the same *correct*
thing. :-)

I don't know C++ well enough to know which is the correct behaviour.
I also don't understand why, if I've bozoed the traversing of 
__DTOR_LIST__[] why this is the only test that fails when there
are explicit ctor and dtor tests in the suite.   

Should the destructor for D perhaps be calling _exit() instead 
of exit()?

Guidance appreciated.

RJL


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