LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-07-2010, 05:20 PM   #1
NTxC
LQ Newbie
 
Registered: Feb 2010
Posts: 5

Rep: Reputation: 0
Segmentation fault after second dlopen() attempt


Hello!
My name's Patrick, and I'm a mod developer for a game named Jedi Knight 2: Jedi Outcast.

The game is quite old (2002!) and I'm trying to mod the old version of it (1.02a), the jk2ded server linux binary.

The game engine loads my mod's .so file which I compiled using:
Code:
gcc -shared -static -g -fPIC g_syscalls.c common.c main.c -o out/jk2mpgamei386.so
So whilst launching the server for the first time, it loads the .so file using dlopen() without problems and the output is:
Code:
Loading dll file jk2mpgame.
Sys_LoadDll(/web/web11/jk2/base/jk2mpgamei386.so)... 
Sys_LoadDll(jk2mpgame) found **vmMain** at  0xb2ed9413  
Sys_LoadDll(jk2mpgame) succeeded!
[ NT's Fix ] GAME_INIT
and then it works correctly until I try to change the map the server is on currently.
When a map changes on the server, the .so file has to be unloaded.
After unloading with dlclose() without errors, when the new map is launched the engine tries to reload the .so into the memory with dlopen() but fails:
Code:
map_restart 0
Cvar_Set2: sv_serverid 78710500
==== ShutdownGame ====
ShutdownGame:
------------------------------------------------------------
[ NT's Fix ] GAME_SHUTDOWN
Loading dll file jk2mpgame.
Sys_LoadDll(/web/web11/jk2/base/jk2mpgamei386.so)...
Speicherzugriffsfehler
...crash with a segmentation fault error.

So I used gdb to find out why it does that, but all I got is:
Code:
(gdb) bt
#0  0x081099f0 in _dl_lookup_versioned_symbol (undef_name=0xb2efd81f "strlen", undef_map=0x838fee8, ref=0xbfdd56b8, symbol_scope=0x8390084, version=0x83901a0, type_class=0,
    explicit=0) at do-lookup.h:52
#1  0x0812248b in _dl_relocate_object () at ../sysdeps/i386/dl-machine.h:348
#2  0x0810b987 in dl_open_worker (a=0xbfdd592c) at dl-open.c:294
#3  0x0810ae67 in _dl_catch_error (objname=0xbfdd5924, errstring=0xbfdd5928, operate=0x810b570 <dl_open_worker>, args=0xbfdd592c) at dl-error.c:152
#4  0x0810bac3 in _dl_open (file=0x8242ee0 "/web/web11/jk2/base/jk2mpgamei386.so", mode=-2147483646, caller=0x80b6778) at dl-open.c:407
#5  0x080dbeef in dlopen_doit (a=0xbfdd5a8c) at dlopen.c:39
#6  0x0810ae67 in _dl_catch_error (objname=0x829a3a0, errstring=0x829a3a4, operate=0x80dbed0 <dlopen_doit>, args=0xbfdd5a8c) at dl-error.c:152
#7  0x080dc132 in _dlerror_run (operate=0x80dbed0 <dlopen_doit>, args=0xbfdd5a8c) at dlerror.c:130
#8  0x080dbebd in __dlopen_check (file=0x8242ee0 "/web/web11/jk2/base/jk2mpgamei386.so", mode=2) at dlopen.c:53
#9  0x080b6778 in .B18.8 ()
#10 0x08242ee0 in fs_gamedir ()
(gdb)
Could you please tell me what could be the possible reason of why it crashes?

Kind regards
Patrick :-)
 
Old 02-07-2010, 11:16 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Can you make it unload/reload without changing maps? If so, try it out. That should tell you if it's a problem with the map change. Does the mod get uploaded to another machine, i.e. does it run from a different machine than the one it's compiled on? If not, try dropping -static, also.
Kevin Barry

PS Do nm out/jk2mpgamei386.so | grep ' U '. If you see anything, that's a problem (in this particular case; it's normal otherwise.)

Last edited by ta0kira; 02-07-2010 at 11:21 PM.
 
1 members found this post helpful.
Old 02-07-2010, 11:32 PM   #3
NTxC
LQ Newbie
 
Registered: Feb 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ta0kira View Post
Can you make it unload/reload without changing maps? If so, try it out. That should tell you if it's a problem with the map change. Does the mod get uploaded to another machine, i.e. does it run from a different machine than the one it's compiled on? If not, try dropping -static, also.
Kevin Barry

PS Do nm out/jk2mpgamei386.so | grep ' U '. If you see anything, that's a problem (in this particular case; it's normal otherwise.)
Hello Kevin,
Thanks for the reply. I'm not able to unload the .so without map change. I am compiling the jk2mpgamei386.so in Cygwin under Windows 7 and I run it at a different machine (Linux server - Debian Etch 2.6.24).

I did the command.
Here are the results:
Code:
patrickw@ulm192:~/jk2$ nm base/jk2mpgamei386.so | grep ' U '
         U strcmp@@GLIBC_2.0
         U strlen@@GLIBC_2.0
         U strstr@@GLIBC_2.0
         U vsnprintf@@GLIBC_2.0
I assume that means there are undefined symbols and it's a problem as you said, so could you give me clues on how to fix this?

I noticed one of the undefined symbols (strlen) matches frame from the gdb backtrace.

Code:
#0  0x081099f0 in _dl_lookup_versioned_symbol (undef_name=0xb2efd81f "strlen"
Could this possibly be the problem?

Thank you for the reply again,
kind regards :-)

Patrick
 
Old 02-08-2010, 10:49 AM   #4
NTxC
LQ Newbie
 
Registered: Feb 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Hello again.
I removed all references to strlen and the rest of the undefined symbols from my code so that the nm command I used doesn't print anything anymore.

Now it crashes with a reference to __deregister_frame_info_bases which is in libc.so.6.

I think I should link the libc with my .so statically. How can I achieve this?

I have the libc.a file that I want to link to my .so file but I don't know how to launch gcc so it compiles with libc statically.

Can you help me out?

Cheers,
Patrick


_______________


EDIT:

I managed to solve my problem.
I used this command to compile statically linked jk2mpgamei386.so:
Code:
gcc-linux -shared -static -static-libgcc -L. -lc -Bstatic g_syscalls.c common.c main.c -o out/jk2mpgamei386.so libc.a
This way it works without problems.

Thanks,
Patrick

Last edited by NTxC; 02-08-2010 at 01:35 PM. Reason: Fixed
 
  


Reply

Tags
debian, lenny, linux, sigsegv


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault fs11 Programming 8 05-16-2008 06:04 PM
Debugging Wine - Segmentation faults during dlopen("wined3d.dll.so"). ErV Programming 0 06-27-2007 07:39 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 10:34 AM
segmentation fault ice99 Linux - Software 1 08-19-2005 12:33 PM
segmentation fault... perdesiz Linux - Software 1 08-18-2003 02:55 AM


All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration