Author Topic: simple SDL app crashing under linux using ati drivers  (Read 5903 times)

0 Members and 1 Guest are viewing this topic.

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Hello, i've got a 64bit gentoo installed, a 9700 radeon, 8.39.4 drivers.

The problem is that if i call SDL_SetVideoMode with SDL_OPENGL enabled, the program crashes. backtracing showed that the crash occurs at ati drivers calling sprintf.

I compile the file using gcc -O2 -c small.c -fomit-frame-pointer -fno-exceptions -ffast-math

ld -dynamic-linker /lib/ld-linux-x86-64.so.2 small.o /usr/lib/libGL.so /usr/lib/libSDL.so small

edit : uh sorry for the bad board.

If i compile normaly :

gcc -O2 small.c -fomit-frame-pointer -fno-excpetions -ffast-math

the problem doesn't occur but obviously the executable is MUCH bigger.
If i enable xorg-x11 drivers the problems doesn'y occur.

Any ideas how to solve that? ( am i forgetting something simple? )
The small.c file just setups SDL and finishes.
« Last Edit: September 20, 2007 by frea »
Nananan.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: simple SDL app crashing under linux using ati drivers
« Reply #1 on: September 20, 2007 »
I'm no SDL expert but the program compiles ok with no warnings?

I am sure that someone here will be able to help you get to the solution soon anyway, and welcome to the forum.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #2 on: September 20, 2007 »
( sorry for bad board, this should've been in the c++ section, right? )

The only warning is that it has a problem with locating _start(), but the linker uses it's "default" place and it seems it is correct.

Is there anyone willing to test this code : http://www.int21.de/linux4k/ ? You might possibly want to change the -dynamic-linker option.
Nananan.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #3 on: September 21, 2007 »
Since you don't have a C runtime library in there, I'm not really surprised sprintf doesn't work.  How does it link?  I know Linux is dynamic linking, so where does sprintf symbol come from?  I guess the other drivers avoid calling sprintf.
Am I barking up the wrong tree?  I'm mostly a Windows programmer.

Jim
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #4 on: September 21, 2007 »
I think you are correct. Anyone has gotten an idea of how to get rid of that problem? writing my own sprintf and linking it somehow?

the best would be an solution that would be only in my code ;). I wouldn't like to make people do some hacks in their OS in order to run my demo :P. ( especialy people using linux ;) )

Just compiling the usual way after striping & gziping adds around 600-700 bytes, so thats quite much for a 4k.
Nananan.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: simple SDL app crashing under linux using ati drivers
« Reply #5 on: September 21, 2007 »
Hmm... If it's 4kb's that you are going to be writing, I haven't heard of any that use SDL (please point me to some if they are out there!).

You could do worse than look at this topic;

http://dbfinteractive.com/index.php?topic=2310.0

The framework developed by auld and rbraz is very good.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #6 on: September 21, 2007 »
->Shockwave - the problem with Linux is it's more complicated to get the display going, and although Auld/Rbraz's stuff is very small it doesn't solve that specific problem because it's meant for Windows.
The problem here is really Linux specific, at least, I think it is, I'm still not sure I'm right because the way Linux loads programs and links them is very different to Windows.

->frea - try adding a sprintf function to your main.c, something like
Code: [Select]
int sprintf(char *buffer, const char *fmt, ...)
{
   ...
}
Then try a breakpoint inside sprintf to see how much of it you might need to write, based on what fmt is set to.  At least that might show you the problem - either the linker will complain you have 2 sprintf functions defined, or you'll find something else :)  Under Linux, is there really any benefit from removing the C runtime from your program, seeing as it can always be dynamically linked?

Another question - how do you know you can get rid of SDL_init()? 

Jim
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #7 on: September 22, 2007 »
Hmm... If it's 4kb's that you are going to be writing, I haven't heard of any that use SDL (please point me to some if they are out there!).
The only alternative would be using glut, which gave me bigger size, but it seems that if i'll be unable to get rid of that problem with SDL/ati i'll need to use it. To tell you the thruth i didn't try to run any of the demos, mostly becouse i've got a 64 bit machine and most of them probably wouldn't run ;).


Then try a breakpoint inside sprintf to see how much of it you might need to write, based on what fmt is set to. At least that might show you the problem - either the linker will complain you have 2 sprintf functions defined, or you'll find something else :) Under Linux, is there really any benefit from removing the C runtime from your program, seeing as it can always be dynamically linked?

Another question - how do you know you can get rid of SDL_init()?

Jim
As i said there is a benefit of about 600-700 bytes. There are added few things to _start() by the compiler, for example setting up standart in/output, enabling the use of new / delete, although this applies only for c++.

As for SDL_init(); i currently use it, but it seems that this line is reduntant for 4k demos. Adding it or takeing it away doesn't change the crash problem.

I'll try to write my own sprintf ( or even just copy-paste it ).

edit : adding my own sprintf makes ati drivers call my own sprintf so it's great ;). Although this means i'll need to write my own rand() too ;/.
« Last Edit: September 22, 2007 by frea »
Nananan.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #8 on: September 22, 2007 »
You can get the source for SDL to see what SDL_init might do on your platform.  http://www.libsdl.org/

If the ATI driver calls sprintf for debug logging, then it might just be sufficient to do
Code: [Select]
buffer[0]='\0';
If it uses it to make file names then it might be tougher ;)

The C standard has the source for rand() in it.
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf
Code: [Select]
static unsigned int next = 1;
int rand(void) // RAND_MAX assumed to be 32767
{
  next = next * 1103515245 + 12345;
  return (unsigned int)(next/65536) % 32768;
}
void srand(unsigned int seed)
{
  next = seed;
}

Jim
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: simple SDL app crashing under linux using ati drivers
« Reply #9 on: September 22, 2007 »
Thanks for the rand code :).
The sprintf function is used for nondebuging purpouses. It setups somekind of id or something. I'll dig it a little bit more :). When i'll find the solution i'll post it here.

Anyone got an explanation of using this kind of functions? :
Code: [Select]
int something( int n, int a, ... );
This function has minimum 2 parameters, and allows adding as many as we wish. ( without overloading )

edit : got it. just google variadic functions.
« Last Edit: September 22, 2007 by frea »
Nananan.