nostdlib causes segmentation fault within SDL
When I compile the following code with gcc -nostartfiles or -nostdlib, running the resulting Program causes a crash deep within the Audio system, when SDL_OpenAudio() is called. Without this call everything works fine and even other Librarys work. When compiled without -nostartfiles/-nostdlib (and renaming _start to main and commenting the assembly exit call) It works fine.
My Question: What causes this dependency on the gcc startup code and how can I fix it without removing -nostartfiles / -nostdlib?
I'm compiling for linux 64 Bit on x86_64 with gcc 4.7.2
void _start()
{
SDL_AudioSpec fmt;
fmt.freq = 44100;
fmt.format = AUDIO_S16;
fmt.channels = 1;
fmt.samples = 4096;
fmt.callback = mixaudio;
fmt.userdata = NULL;
if ( SDL_OpenAudio(&fmt, NULL) < 0 ) SDL_Quit();
SDL_PauseAudio(0);
while(1){SDL_Delay(20);}
asm("xorq %rax, %rax n movq 42, %ebx n int 0x80");
}
链接地址: http://www.djcxy.com/p/79928.html
上一篇: 运行C程序复制的二进制文件时出现分段错误
下一篇: nostdlib在SDL中导致分段错误