Librgx and g++ apps segfault under Linux

Librgx and g++ apps segfault under Linux

Post by Ed Doolitt » Sun, 04 Aug 1996 04:00:00



I've been writing some basic graphics programs under Linux 2.0 using
g++ and libgrx (the Linux port of the djgpp graphics library). I get
random segmentation faults with my programs. Sometimes they segfault
when they exit, sometimes the segfault when they start. The behaviour
is consistent for any particular program, but if I change it around a
little (add debugging cout << lines, for example), the behaviour can
change.

I haven't noticed such problems when I build applications without
libgrx, so that seems likely to be the problem. Furthermore, the example
program cliptest from the Grx package compiled with gcc works fine, but
when compiled with g++ it segfaults on exit, which leads me to believe
that there is a problem in the interaction between libgrx and g++.

Does anyone have any ideas on how I can track down the problem and fix
it?  Here are the details of my setup:

Linux 2.0.7
libc 5.3.12
libg++ 27.1.4
gcc 2.7.2
ld.so 1.7.14
libgrx 1.0.4 from sunsite

Thanks,
Ed

--
--

 "Being on time is like being on fire."

 
 
 

Librgx and g++ apps segfault under Linux

Post by Vladislav Grinchenk » Mon, 05 Aug 1996 04:00:00


Folks,
    I'm trying to understand this puzzle:
    Below is c++ program that will fail with `Memory fault'
----------------------------------------------------------------------
extern "C" {
#include <netdb.h>

Quote:}

#include <iostream.h>

extern int h_errno;

main()
{
    struct hostent *hp;
    char *host="darkstar";

    hp = gethostbyname(host);
    cout << "official host name: "; // << hp->h_name << endl;

Quote:}

----------------------------------------------------------------------
And here is C counterpart, that will report correct answer:
----------------------------------------------------------------------
#include <netdb.h>
extern int h_errno;

main()
{
    struct hostent *hp;
    char *host="darkstar";

    hp = gethostbyname(host);
    printf("host name: %s\n", hp->h_name);

Quote:}

----------------------------------------------------------------------

System
------
Linux darkstar 1.3.79 #1 Mon May 20 21:42:05 GMT 1996 i586
gcc version 2.7.0
libg++.so.2.7.0
libstdc++.so.2.7.0
libc.so.5.0.9
libm.so.5.0.0

    I've just start using C++, so, please, if anyone can point
    out my mistake, I will appreciate it. If possible, reply by
    mail.



 
 
 

Librgx and g++ apps segfault under Linux

Post by Hans-Bernhard Broek » Tue, 06 Aug 1996 04:00:00



> I've been writing some basic graphics programs under Linux 2.0 using
> g++ and libgrx (the Linux port of the djgpp graphics library).
[...]
> Furthermore, the example program cliptest from the Grx package
> compiled with gcc works fine, but when compiled with g++ it
> segfaults on exit, which leads me to believe that there is a problem
> in the interaction between libgrx and g++.

Could well be that bad, but well known bug of g++ (and only g++, not
gcc) not correctly handling packed structures. To get closer to it,
could you (Ed Doolittle, that is) please debug the programs at least
to that extent that you find out what kind of instructions are
actually crashing?

Hans-Bernhard Broeker (Aachen, Germany)

 
 
 

Librgx and g++ apps segfault under Linux

Post by Ed Doolitt » Wed, 07 Aug 1996 04:00:00


On 5 Aug 1996 12:44:38 GMT, Hans-Bernhard Broeker
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


>> Furthermore, the example program cliptest from the Grx package
>> compiled with gcc works fine, but when compiled with g++ it
>> segfaults on exit, which leads me to believe that there is a problem
>> in the interaction between libgrx and g++.
> Could well be that bad, but well known bug of g++ (and only g++, not
> gcc) not correctly handling packed structures. To get closer to it,
> could you (Ed Doolittle, that is) please debug the programs at least
> to that extent that you find out what kind of instructions are
> actually crashing?

I'm having some trouble running gdb on the graphics programs -- when I
single step through the program, some of the arguments become garbage
(e.g. GrSetMode(9,800,600,256) becomes GrSetMode(0,-10327363,...).
Perhaps it can't handle switching between graphics and text mode. I've
tried redirecting output to another console without any luck. I hope I
can eventually find a way to do it.

However, if I just let the program run under gdb, the segfaults always
occur in __libc_free. The Linux libc 5.3.12 free() is quite demanding;
many programs broke because they would malloc, modify the pointer
returned, and free the modified pointer, which was acceptable under libc
5.2 and earlier. Perhaps that is the problem.

I've been trying to track down all the free()s in libgrx to see if any
of them free modified pointers, but it's quite time consuming work.
Hopefully I'll have more information in a few days. In the meantime,
other suggestions are most welcome.

Ed

--

 "Being on time is like being on fire."

 
 
 

Librgx and g++ apps segfault under Linux

Post by Wolfram Gloge » Wed, 07 Aug 1996 04:00:00



> However, if I just let the program run under gdb, the segfaults always
> occur in __libc_free. The Linux libc 5.3.12 free() is quite demanding;
> many programs broke because they would malloc, modify the pointer
> returned, and free the modified pointer, which was acceptable under libc
> 5.2 and earlier. Perhaps that is the problem.

Yes, this is not improbable.  However, please note that it wasn't
`acceptable' under the earlier libc version either; the program would
just crash somewhat later...

Quote:> I've been trying to track down all the free()s in libgrx to see if any
> of them free modified pointers, but it's quite time consuming work.
> Hopefully I'll have more information in a few days. In the meantime,
> other suggestions are most welcome.

If you have the gdb backtrace ending in __libc_free, first check where
the free(x) call came from, and whether the pointer x is valid.  If it
is, it could be that another malloc()ed region has been stomped over
by the grx code.  You could try to compile from libc sources

% gcc -DDEBUG -c /usr/src/libc/dl-malloc.c

and then link dl-malloc.o statically into your application.  This way
you have a much better chance of spotting the problem where it
actually occurs.

There are other more heavy-weight methods to find these problems,
like ElectricFence and Checker.

Regards,
Wolfram.

 
 
 

Librgx and g++ apps segfault under Linux

Post by Mike Robinso » Mon, 19 Aug 1996 04:00:00


Hi all,

gcc 2.7.2 has a bug where __attribute__ ((packed)) is not
correctly handled in x.cc code (g++), but is correctly handled in
x.c (gcc) code. This used to work in 2.7.0 g++, where we developed
a bunch of c++ code using this attribute.

I'd really like to upgrade the compiler to 2.7.2, mainly because I
want to use libc >= 5.2.18. I believe that use of these later
libraries requires use of 2.7.2 (library release doco says
something along these lines). Does anyone know of a way to get the
packed attribute to work, without completely re-writing all code
accessing these packed structures to use access methods written in
c? Alternatively, can anyone tell me whether I can safely use the
later libraries with gcc 2.7.0 (the release notes suggest not)?

Am I asking for the impossible?

Mike

 
 
 

1. all apps I compile using svgalib segfault

I have been having a problem with all svgalib-based apps that I
compile myself (most stuff). The program immediately seg-faults. I am
using kernel 1.1.94, svgalib 1.24, gcc 2.6.3, binutils-2.5.2,
libc 4.6.27, and ld.so 1.53. The latest program that this happened
with was povray. The X and standard binaries worked fine, but the
svgalib one exhibits this problem. However, precompiled binaries,
such as luxman, svgafft, linuxsdoom :), and sasteroids work fine.
Has anybody else had this problem? If so, how did you solve it?
                        Simon
--
*******************************************************************************

*  flames to /dev/null                    Linux: choice of the GNU generation *
*  #include <disclaimer.h>                            I don't speak for NCSSM *
*******************************************************************************

2. Problem getting chat to display output under pppd

3. apps run as root, segfault as user?

4. screen (and k2.2.16)

5. Any GTK app causes X to segfault--?

6. newsgroup thru masq

7. Matrox Mystique ands X.

8. Taskbar in kde 3

9. NTeX under Linux---dvips segfaults, & ghostview not using right fonts

10. Help: acroread segfault on Linux 2.0.34 (redhat 5.1)

11. Odd error, segfault, and Linux protection fault

12. Segfaults: gcc & find under Linux 1.2.1 on P5-100.

13. libg++-2.7.0a linkage under linux segfaults