Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 06-10-2009, 08:17 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default Patches for 64bit linux

I'll be posting patches to improve compatibility with 64bit linux compiles in this thread.

First up, makefile changes to allow it to begin compiling.

Code:
Index: eqlaunch/makefile
===================================================================
--- eqlaunch/makefile   (revision 1)
+++ eqlaunch/makefile   (revision 2)
@@ -10,11 +10,11 @@
 LINKOUT=-o
 NOLINK=-c
 LINKER=gcc
-MYSQL_FLAGS=-I/usr/include/mysql
-MYSQL_LIB=-L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files -lnss_dns -lresolv
+MYSQL_FLAGS=$(shell mysql_config --cflags)
+MYSQL_LIB=$(shell mysql_config --libs)
 DFLAGS=-DEQDEBUG=5
 WFLAGS=-Wall -Wuninitialized -Wwrite-strings -Wcast-qual -Wno-deprecated  -Wcomment -Wcast-align
-COPTS=$(WFLAGS) -O -g -march=i686 -pthread -pipe -DEQLAUNCH $(DFLAGS) $(MYSQL_FLAGS)
+COPTS=$(WFLAGS) -O -g -pthread -pipe -DEQLAUNCH $(DFLAGS) $(MYSQL_FLAGS)
 LINKOPTS=$(COPTS) -rdynamic -L. -lstdc++ -ldl $(MYSQL_LIB)

 all: eqlaunch
Index: chatserver/makefile
===================================================================
--- chatserver/makefile (revision 1)
+++ chatserver/makefile (revision 2)
@@ -21,7 +21,7 @@
 MYSQL_FLAGS=$(shell mysql_config --cflags)
 MYSQL_LIB=$(shell mysql_config --libs)

-COPTS=$(WFLAGS) -g -march=i686 -pthread -pipe -I../common/SocketLib \
+COPTS=$(WFLAGS) -g -pthread -pipe -I../common/SocketLib \
   -DFX -D_GNU_SOURCE -DINVERSEXY $(DFLAGS) $(MYSQL_FLAGS) $(PERL_FLAGS)
 LINKOPTS=$(COPTS) -rdynamic -L. -lstdc++ -lm -lz -ldl \
   $(MYSQL_LIB) $(PERL_LIB)
Index: world/makefile
===================================================================
--- world/makefile      (revision 1)
+++ world/makefile      (revision 2)
@@ -21,7 +21,7 @@
 MYSQL_FLAGS=$(shell mysql_config --cflags)
 MYSQL_LIB=$(shell mysql_config --libs)

-COPTS=$(WFLAGS) -g -march=i686 -O -pthread -pipe -I../common/SocketLib \
+COPTS=$(WFLAGS) -g -O -pthread -pipe -I../common/SocketLib \
   -DFX -D_GNU_SOURCE -DINVERSEXY -DWORLD $(DFLAGS) $(MYSQL_FLAGS) $(PERL_FLAGS)
 LINKOPTS=$(COPTS) -rdynamic -L. -lstdc++ -lm -lz -ldl \
   $(MYSQL_LIB) $(PERL_LIB)
Index: mailserver/makefile
===================================================================
--- mailserver/makefile (revision 1)
+++ mailserver/makefile (revision 2)
@@ -21,7 +21,7 @@
 MYSQL_FLAGS=$(shell mysql_config --cflags)
 MYSQL_LIB=$(shell mysql_config --libs)

-COPTS=$(WFLAGS) -g -march=i686 -pthread -pipe -I../common/SocketLib \
+COPTS=$(WFLAGS) -g -pthread -pipe -I../common/SocketLib \
   -DFX -D_GNU_SOURCE -DINVERSEXY $(DFLAGS) $(MYSQL_FLAGS) $(PERL_FLAGS)
 LINKOPTS=$(COPTS) -rdynamic -L. -lstdc++ -lm -lz -ldl \
   $(MYSQL_LIB) $(PERL_LIB)
Index: zone/makefile
===================================================================
--- zone/makefile       (revision 1)
+++ zone/makefile       (revision 2)
@@ -10,15 +10,15 @@
 LINKOUT=-o
 NOLINK=-c
 LINKER=gcc
-MYSQL_FLAGS=-I/usr/include/mysql
-MYSQL_LIB=-L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv -lc -lnss_files -lnss_dns -lresolv
+MYSQL_FLAGS=$(shell mysql_config --cflags)
+MYSQL_LIB=$(shell mysql_config --libs)
 DFLAGS=-DEQDEBUG=5 -DCATCH_CRASH -DNO_PIDLOG -DSHAREMEM -DFIELD_ITEMS -DCOMBINED -DAPP_OPCODE_SIZE=2 -Di386
 #try commenting out the following three lines to disable embedded perl
 PERL_FLAGS=perl -MExtUtils::Embed -e ccopts
 PERL_LIB=perl -MExtUtils::Embed -e ldopts
 DFLAGS+=-DEMBPERL -DEMBPERL_PLUGIN -DHAS_UNION_SEMUN
 WFLAGS=-fpermissive -Wall -Wuninitialized -Wwrite-strings -Wcast-qual -Wno-deprecated  -Wcomment -Wcast-align
-COPTS=$(WFLAGS) -O -g -march=i686 -pthread -pipe -D_GNU_SOURCE -DINVERSEXY -DFX -DZONE $(DFLAGS) $(MYSQL_FLAGS) `$(PERL_FLAGS)`
+COPTS=$(WFLAGS) -O -g -pthread -pipe -D_GNU_SOURCE -DINVERSEXY -DFX -DZONE $(DFLAGS) $(MYSQL_FLAGS) `$(PERL_FLAGS)`
 LINKOPTS=$(COPTS) -rdynamic -L. -lstdc++ -ldl $(MYSQL_LIB) `$(PERL_LIB)`

 all: zone
Index: ucs/makefile
===================================================================
--- ucs/makefile        (revision 30)
+++ ucs/makefile        (revision 31)
@@ -21,7 +21,7 @@
 MYSQL_FLAGS=$(shell mysql_config --cflags)
 MYSQL_LIB=$(shell mysql_config --libs)

-COPTS=$(WFLAGS) -g -march=i686 -pthread -pipe -I../common/SocketLib \
+COPTS=$(WFLAGS) -g -pthread -pipe -I../common/SocketLib \
   -DFX -D_GNU_SOURCE -DINVERSEXY $(DFLAGS) $(MYSQL_FLAGS) $(PERL_FLAGS)
 LINKOPTS=$(COPTS) -rdynamic -L. -lstdc++ -lm -lz -ldl \
   $(MYSQL_LIB) $(PERL_LIB)
This patch merely removes the -march=i686 to allow the compiler to dynamically set arch and in two makefiles it changes the mysql flags from hardcoded to dynamically generated.

If desired, I could create patches so the makefile will selectively add the -march=i686 for 32 bit machines.
Reply With Quote
  #2  
Old 06-10-2009, 08:20 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

Type cast in common/TCPConnection.cpp to fix compile error under 64bit.

Code:
Index: common/TCPConnection.cpp
===================================================================
--- common/TCPConnection.cpp    (revision 2)
+++ common/TCPConnection.cpp    (revision 3)
@@ -145,7 +145,7 @@
 #endif
 #endif
        addrlen=sizeof(struct sockaddr_in);
-       if (!getsockname(connection_socket,(struct sockaddr *)&local,&addrlen)) {
+       if (!getsockname(connection_socket,(struct sockaddr *)&local,(socklen_t *)&addrlen)) {
                unsigned long ip=local.sin_addr.s_addr;
                sprintf(host,"%d.%d.%d.%d",
                        *(unsigned char *)&ip,
Reply With Quote
  #3  
Old 06-10-2009, 08:23 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

Apparently va_lists are not preserved in (most) 64bit linux libraries after vprintf (and variations) calls. This causes segfaults under 64bit when a va_list is reused. This patch avoids reusing va_lists.

Code:
Index: common/MiscFunctions.cpp
===================================================================
--- common/MiscFunctions.cpp    (revision 3)
+++ common/MiscFunctions.cpp    (revision 4)
@@ -148,7 +148,6 @@
        int buf_len = 128;
     int chars = -1;
        va_list argptr;
-       va_start(argptr, format);
        while (chars == -1 || chars >= buf_len) {
                safe_delete_array(*ret);
                if (chars == -1)
@@ -156,9 +155,10 @@
                else
                        buf_len = chars + 1;
                *ret = new char[buf_len];
+               va_start(argptr, format);
                chars = vsnprintf(*ret, buf_len, format, argptr);
+               va_end(argptr);
        }
-       va_end(argptr);
        return chars;
 }

@@ -170,7 +170,6 @@
     int chars = -1;
        char* oldret = 0;
        va_list argptr;
-       va_start(argptr, format);
        while (chars == -1 || chars >= (sint32)(*bufsize-*strlen)) {
                if (chars == -1)
                        *bufsize += 256;
@@ -183,7 +182,9 @@
                                memcpy(*ret, oldret, *strlen);
                        safe_delete_array(oldret);
                }
+               va_start(argptr, format);
                chars = vsnprintf(&(*ret)[*strlen], (*bufsize-*strlen), format, argptr);
+               va_end(argptr);
        }
        va_end(argptr);
        *strlen += chars;
Index: common/debug.cpp
===================================================================
--- common/debug.cpp    (revision 3)
+++ common/debug.cpp    (revision 4)
@@ -144,11 +144,16 @@

        va_list argptr;
        va_start(argptr, fmt);
-    if (dofile)
+    if (dofile) {
                vfprintf( fp[id], fmt, argptr );
+               va_end(argptr);
+               va_start(argptr, fmt);
+       }
        if(logCallbackFmt[id]) {
                msgCallbackFmt p = logCallbackFmt[id];
                p(id, fmt, argptr );
+               va_end(argptr);
+               va_start(argptr, fmt);
        }
     if (pLogStatus[id] & 2) {
                if (pLogStatus[id] & 8) {
@@ -202,17 +207,21 @@
     time( &aclock );                 /* Get time in seconds */
     newtime = localtime( &aclock );  /* Convert time to struct */

+    va_list tmpargptr;
+
     if (dofile) {
 #ifndef NO_PIDLOG
                fprintf(fp[id], "[%02d.%02d. - %02d:%02d:%02d] %s", newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec, prefix);
 #else
                fprintf(fp[id], "%04i [%02d.%02d. - %02d:%02d:%02d] %s", getpid(), newtime->tm_mon+1, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec, prefix);
 #endif
-               vfprintf( fp[id], fmt, argptr );
+               va_copy(tmpargptr, argptr);
+               vfprintf( fp[id], fmt, tmpargptr );
     }
        if(logCallbackPva[id]) {
                msgCallbackPva p = logCallbackPva[id];
-               p(id, prefix, fmt, argptr );
+               va_copy(tmpargptr, argptr);
+               p(id, prefix, fmt, tmpargptr );
        }
     if (pLogStatus[id] & 2) {
                if (pLogStatus[id] & 8) {
@@ -295,8 +304,11 @@
 bool EQEMuLog::writeNTS(LogIDs id, bool dofile, const char *fmt, ...) {
        va_list argptr;
        va_start(argptr, fmt);
-       if (dofile)
+       if (dofile) {
                vfprintf( fp[id], fmt, argptr );
+               va_end(argptr);
+               va_start(argptr, fmt);
+       }
     if (pLogStatus[id] & 2) {
                if (pLogStatus[id] & 8)
                        vfprintf( stderr, fmt, argptr );
Reply With Quote
  #4  
Old 06-10-2009, 08:28 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

This patch fixes disappearing augments and no drop flags seemingly randomly toggling on items in inventory with 64bit linux compiles.

Code:
Index: common/shareddb.cpp
===================================================================
--- common/shareddb.cpp (revision 6)
+++ common/shareddb.cpp (revision 7)
@@ -254,8 +254,8 @@
                                "       augslot1,augslot2,augslot3,augslot4,augslot5)"
                                " VALUES(%lu,%lu,%lu,%lu,"
                                "       %lu,%lu,%lu,%lu,%lu)",
-                               account_id, slot_id, inst->GetItem()->ID, charges ,
-                               augslot[0],augslot[1],augslot[2],augslot[3],augslot[4]);
+                               (unsigned long)account_id, (unsigned long)slot_id, (unsigned long)inst->GetItem()->ID, (unsigned long)charges ,
+                               (unsigned long)augslot[0],(unsigned long)augslot[1],(unsigned long)augslot[2],(unsigned long)augslot[3],(unsigned long)augslot[4]);


                        ret = RunQuery(query, len_query, errbuf);
@@ -290,8 +290,8 @@
                                "       augslot1,augslot2,augslot3,augslot4,augslot5)"
                                " VALUES(%lu,%lu,%lu,%lu,%lu,%lu,"
                                "       %lu,%lu,%lu,%lu,%lu)",
-                               char_id, slot_id, inst->GetItem()->ID, charges, inst->IsInstNoDrop() ? 1:0,inst->GetColor(),
-                               augslot[0],augslot[1],augslot[2],augslot[3],augslot[4] );
+                               (unsigned long)char_id, (unsigned long)slot_id, (unsigned long)inst->GetItem()->ID, (unsigned long)charges, (unsigned long)(inst->IsInstNoDrop() ? 1:0),(unsigned long)inst->GetColor(),
+                               (unsigned long)augslot[0],(unsigned long)augslot[1],(unsigned long)augslot[2],(unsigned long)augslot[3],(unsigned long)augslot[4] );

                        ret = RunQuery(query, len_query, errbuf);
                }
Reply With Quote
  #5  
Old 06-10-2009, 08:35 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

This patch fixes assembler errors on some 64bit systems.

Code:
Index: common/crc32.cpp
===================================================================
--- common/crc32.cpp    (revision 1)
+++ common/crc32.cpp    (working copy)
@@ -112,6 +112,14 @@
 #undef i386    //darwin seems to think we are generating PIC, and we clobber ebx
 #endif

+/* Some 64bit systems do not like the i386 assembly code below. However, some 64bit
+   systems do work with the assembly code below. We #undef i386 to be on the safe
+   side if we are compiling 64bit. */
+
+#ifdef __x86_64__
+#undef i386
+#endif
+
 uint32 CRC32::Update(const int8* buf, uint32 bufsize, uint32 crc32) {
 #if defined(WIN32)
        // Register use:
Reply With Quote
  #6  
Old 06-10-2009, 08:42 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

I did a whole pile of type casts where MakeAnyLenString was being used with %lu in the format string. This patch is over 400 lines long so rather than post it here, it can be retrieved at:
Code:
svn diff -c 8 https://www.tsahosting.net/svn/eqemu64/trunk/
Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 12:36 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3