Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Help compiling xrolodex?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Silent-Hunter
Apprentice
Apprentice


Joined: 07 Jul 2013
Posts: 166

PostPosted: Fri Oct 17, 2014 5:18 am    Post subject: Help compiling xrolodex? Reply with quote

I saw this software posted online called xrolodex, and while it builds, it will not run. It outputs nothing but "Segmentation Fault".

Here's the compilation warnings:
Code:
make -f xrolo.make
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o xrolo.o xrolo.c
xrolo.c: In function ‘main’:
xrolo.c:301:3: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
xrolo.c:308:3: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
xrolo.c: In function ‘create_dialogs’:
xrolo.c:610:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
xrolo.c:622:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
xrolo.c:628:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
xrolo.c: In function ‘FileSelectionOK’:
xrolo.c:1035:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c:1037:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c: In function ‘SaveUnsavedChanges’:
xrolo.c:1085:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c:1089:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c: In function ‘DiscardUnsavedChanges’:
xrolo.c:1114:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c:1118:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c: In function ‘CancelUnsavedChanges’:
xrolo.c:1143:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c:1145:11: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c: In function ‘Sort’:
xrolo.c:1479:16: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
xrolo.c: In function ‘cleanup_and_exit’:
xrolo.c:2052:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o xrolo.db.o xrolo.db.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o xrolo.index.o xrolo.index.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o help.o help.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o streamdb.o streamdb.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o ctrlpanel.o ctrlpanel.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o editor.o editor.c
editor.c: In function ‘ClearText’:
editor.c:816:4: warning: passing argument 8 of ‘XmClipboardCopy’ from incompatible pointer type [enabled by default]
In file included from editor.h:59:0,
                 from editor.c:62:
/usr/include/Xm/CutPaste.h:88:12: note: expected ‘long int *’ but argument is of type ‘int *’
editor.c: In function ‘selection_to_clipboard’:
editor.c:1022:4: warning: passing argument 8 of ‘XmClipboardCopy’ from incompatible pointer type [enabled by default]
In file included from editor.h:59:0,
                 from editor.c:62:
/usr/include/Xm/CutPaste.h:88:12: note: expected ‘long int *’ but argument is of type ‘int *’
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o listshell.o listshell.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o dialog.o dialog.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o strstr.o strstr.c
gcc -I/usr/include/Xm -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS     -c -o motif.o motif.c
gcc  -o xrolodex xrolo.o xrolo.db.o xrolo.index.o \
      help.o streamdb.o ctrlpanel.o editor.o \
      listshell.o dialog.o strstr.o motif.o -lXm   \
      -lXt -lX11


And here's the makefile:

Code:
#### xrolo.make ####    #### formatted with 4-column tabs ####
####
#### This is a manually-pick-what-you-like, pedestrian-style make file.
#### Alternatively, you can install xrolodex in your MIT source tree and
#### use `Imakefile' to build xrolodex.
####

# The C compiler:
CC = gcc

# These two preprocessor constants M U S T be defined; see REQD_CFLAGS below:
#
# WIDGET_ACCESS is in `editor.[ch]'
# MANUAL_CLIP is in `editor.c'
#

# EDITRES compiler flag (in `xrolo.c' to include `editres' support -- X11R5/6
# only.  If you enable this flag, you'll probably need to link in the X
# miscellaneous-utilities library; see "Generic Xmu library flags" below):
X_FLAGS =
#X_FLAGS = -DEDITRES

# REQD_CFLAGS -- required compiler flags:
REQD_CFLAGS = -D_NO_PROTO -DMANUAL_CLIP -DWIDGET_ACCESS

# EXTRA_CFLAGS -- extra compiler flags:
EXTRA_CFLAGS =
# Configure dialogs as secondary, top-level application windows:
#EXTRA_CFLAGS = -DNO_POPUP
# Whether or not the application physically restricts the action
# area paned windows, e.g., in dialogs, the help window, etc. in
# lieu of using `XmNskipAdjust'.  Enabling this code causes start-up
# resize problems with Motif 2.0:
#EXTRA_CFLAGS = -DRESTRICT_ACTION_AREA
# Use cp(1) and system(3) instead of rename(2) to create back-up files:
#EXTRA_CFLAGS = -DBACKUP_CP
# Substitute an alternate, do-nothing error handler for the Xt standard:
#EXTRA_CFLAGS = -DALT_ERROR_HANDLER

# INCLUDES -- extra compiler flags:
INCLUDES = -I/usr/include/Xm
# HP includes:
#INCLUDES = -I/usr/include/Motif1.2 -I/usr/include/X11R5

# Sample generic compiler flags:
CFLAGS = $(INCLUDES) $(REQD_CFLAGS) $(EXTRA_CFLAGS) $(X_FLAGS)
# Sample HP compiler flags:
#CFLAGS = -Wp,-H300000 $(INCLUDES) $(REQD_CFLAGS) $(EXTRA_CFLAGS) $(X_FLAGS)
# Sample SGI compiler flags:
#CFLAGS = -Wf,-XNl12000 $(INCLUDES) $(REQD_CFLAGS) $(EXTRA_CFLAGS) $(X_FLAGS)

# Generic loader flags:
LDFLAGS =
# Sample HP loader flags:
#LDFLAGS = -L/usr/lib/Motif1.2 -L/usr/lib/X11R5
# Sample Linux loader flags:
#LDFLAGS = -L/usr/X11R6/lib

# Generic Xt library flags:
XTLIB = -lXt
# If it's not `Xt', name your Xt library, e.g.,:
#XTLIB = -lXtm

# Generic Xmu library flags:
XMULIB =
# If you need 'Xmu', uncomment this line:
#XMULIB = -lXmu

# Generic Xpm library flags for Linux:
XPMLIB =
# If you need 'Xpm', uncomment this line:
#XPMLIB = -lXpm

# If you need other libraries, name them:
OTHERLIBS =
# Sample DG, SGI other libraries:
#OTHERLIBS = -lPW

# HP static loader flags:
#STATIC = -Wl,-a,archive
# Sun static loader flags:
#STATIC = -Bstatic


xrolodex:   xrolo.o xrolo.db.o xrolo.index.o help.o streamdb.o \
         ctrlpanel.o editor.o listshell.o dialog.o strstr.o motif.o
         $(CC) $(LDFLAGS) -o xrolodex xrolo.o xrolo.db.o xrolo.index.o \
         help.o streamdb.o ctrlpanel.o editor.o \
         listshell.o dialog.o strstr.o motif.o -lXm $(XPMLIB) $(XMULIB) \
         $(XTLIB) -lX11 $(OTHERLIBS)

xrolodex.static:   xrolo.o xrolo.db.o xrolo.index.o help.o streamdb.o \
               ctrlpanel.o editor.o listshell.o dialog.o strstr.o motif.o
               $(CC) $(STATIC) $(LDFLAGS) -o xrolodex xrolo.o xrolo.db.o \
               xrolo.index.o help.o streamdb.o ctrlpanel.o editor.o \
               listshell.o dialog.o strstr.o motif.o -lXm $(XPMLIB) \
               $(XMULIB) $(XTLIB) -lX11 $(OTHERLIBS)


I did edit it to change "cc" to "gcc" under what compiler to use. I tried "cc" first, but it does the same thing.

Any help would be appreciated, even if it's to say it won't work. The software is about 21 years old.
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Fri Oct 17, 2014 6:38 am    Post subject: Reply with quote

Ugh, with that compilation output the most probable cause (I'd say) for the segfault is an overflow. It seems like they are using lots of pointers of incompatible types and the effect of that only depends on the types, the compiler and the architecture you use. It's perfectly possible that the code will work in some architecture and compiler version while failing on some others.

If you truly want to run this I suggest that you run it under gdb and get a backtrace. That will at least tell you whatever the segfault is taking place. You will need to edit the sources and correct them, then recompile.
Back to top
View user's profile Send private message
Silent-Hunter
Apprentice
Apprentice


Joined: 07 Jul 2013
Posts: 166

PostPosted: Sun Oct 19, 2014 2:36 am    Post subject: Reply with quote

OK, thank you! I will try that. I don't know the language, but I may be able to figure it out.
Back to top
View user's profile Send private message
Silent-Hunter
Apprentice
Apprentice


Joined: 07 Jul 2013
Posts: 166

PostPosted: Sun Oct 19, 2014 2:40 am    Post subject: Reply with quote

It does this:

(gdb) run
Starting program: /home/silent/Downloads/xrolodex.15/xrolodex
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
Warning: Cannot convert string "-dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*" to type FontStruct
Warning: Missing charsets in String to FontSet conversion
Warning: Cannot convert string "-dt-interface system-medium-r-normal-m*-*-*-*-*-*-*-*-*" to type FontSet
Warning: Missing charsets in String to FontSet conversion
Warning: Cannot convert string "-dt-interface user-medium-r-normal-m*-*-*-*-*-*-*-*-*" to type FontSet

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff706b11f in ?? () from /lib64/libc.so.6
(gdb) backtrace
#0 0x00007ffff706b11f in ?? () from /lib64/libc.so.6
#1 0x00000000004037d3 in create_dialogs ()
#2 0x000000000040336f in main ()

I did email the author, but his email is gone.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Sun Oct 19, 2014 9:39 am    Post subject: Reply with quote

Try adding: -g3 -ggdb to CFLAGS.

You appear to be building from source, not ebuild:
Code:
export CFLAGS='-pipe -g3 -ggdb'

then run:
Code:
make clean
make
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Sun Oct 19, 2014 10:25 am    Post subject: Reply with quote

That rolodex thing seems to have a custom makefile, so you are probably better with editing it. You will need to add -g -ggdm as said above, for that look into the make file for EXTRA_FLAGS or CFLAGS, however, this line in the output above:

Code:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff706b11f in ?? () from /lib64/libc.so.6



... seems to suggest that the program was written with an old libc version in mind. You might need to re-emerge glibc with FEATURES="splitdebug" enabled to get the real debug info here. To that purpose, just put a line with FEATURES="splitdebug" in your make.conf file, then use this to re-emerge the package:

Code:
# emerge -1 glibc


Then the split files with the debug symbols will live under /usr/lib/debug, they will just take space in your disk and won't interfere with the system in any other way so it's convenient to have them there when you need to use a debugger.
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Sun Oct 19, 2014 12:28 pm    Post subject: Reply with quote

I have looked at bit deeper.

Code:
 $ gdb xrolodex
GNU gdb (Gentoo 7.6.2 p1) 7.6.2
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
<http://bugs.gentoo.org/>...
Reading symbols from /home/i92guboj/Downloads/xrolodex-1.6/xrolodex...done.
(gdb) run
Starting program: /home/i92guboj/Downloads/xrolodex-1.6/xrolodex
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff710c45c in __strncpy_ssse3 () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff710c45c in __strncpy_ssse3 () from /lib64/libc.so.6
#1  0x00000000004038f7 in create_dialogs (app=0x6270e0, parent=0x64fa40,
    resource_data=0x7fffffffda00) at xrolo.c:656
#2  0x0000000000403484 in main (argc=1, argv=0x7fffffffdc18) at xrolo.c:406
(gdb) quit


The segfault seems to happen at strncpy(). This is a typical case of a developer relying on how a specific compiler on a specific architecture handles things. You can google for strncpy segfault" and you will surely find lots of explanation on what's happening. Also, before doing that look at the strncpy man page, which also gives a few hints about this.

I don't have the time to debug this right now, but, just so you know, I tried disabling the two occurrences of strncpy() on xrolo.c, and then the program crashed at another function: strlen(). So this might just be the tip of the iceberg. Surely the whole program is full of bogus C code ;)

Code:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff705203a in strlen () from /lib64/libc.so.6
(gdb) quit
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Sun Oct 19, 2014 12:42 pm    Post subject: Reply with quote

I managed to get it working by patching xrolo.c this way:

Code:

--- xrolo.c.orig   2014-10-19 14:30:30.532837369 +0200
+++ xrolo.c   2014-10-19 14:38:48.497611953 +0200
@@ -648,15 +648,22 @@
    Widget printPane, printControl, printLabel, printAction,
       printCurrentButton, printAllButton, printDismissButton, printToggleBox;
 
-   if (*resource_data->dir_mask)
-      strncpy(dir_mask, resource_data->dir_mask, xrolo_DIR_MASK_MAX_LEN);
-   else if ((home = (char *) getenv("HOME")) == NULL)
-      strcpy(dir_mask, xrolo_DIR_MASK);
-   else {
-      strncpy(dir_mask, home, xrolo_DIR_MASK_MAX_LEN);
-      strncat(dir_mask, "/", xrolo_DIR_MASK_MAX_LEN - strlen(home));
-      strncat(dir_mask, xrolo_DIR_MASK, xrolo_DIR_MASK_MAX_LEN - strlen(home) - 1);
-   }
+  if(strlen(dir_mask) >= xrolo_DIR_MASK_MAX_LEN)
+  {
+     if (*resource_data->dir_mask)
+     {
+        strncpy(dir_mask, resource_data->dir_mask, xrolo_DIR_MASK_MAX_LEN);
+        dir_mask[xrolo_DIR_MASK_MAX_LEN - 1] = 0;
+     }
+     else if ((home = (char *) getenv("HOME")) == NULL)
+        strcpy(dir_mask, xrolo_DIR_MASK);
+     else {
+        strncpy(dir_mask, home, xrolo_DIR_MASK_MAX_LEN);
+        dir_mask[xrolo_DIR_MASK_MAX_LEN - 1] = 0;
+        strncat(dir_mask, "/", xrolo_DIR_MASK_MAX_LEN - strlen(home));
+        strncat(dir_mask, xrolo_DIR_MASK, xrolo_DIR_MASK_MAX_LEN - strlen(home) - 1);
+     }
+  }
    i = 0;
    XtSetArg(args[i], XmNdialogTitle,
       XmStringCreateLtoR("xrolodex", char_set)); i++;


The problem in this case was that it was trying to copy a string into an un-initialized buffer. I haven't checked the details and I have no idea about what the program does (let alone what that snippet of code does...). but that should put you into the right track. ;)

edit: typos
Back to top
View user's profile Send private message
Silent-Hunter
Apprentice
Apprentice


Joined: 07 Jul 2013
Posts: 166

PostPosted: Mon Oct 20, 2014 2:58 am    Post subject: Reply with quote

I tried the patch, but for some reason it doesn't work:

Code:
patch xrolo.c < xrolo.patch
patching file xrolo.c
Hunk #1 FAILED at 648.
1 out of 1 hunk FAILED -- saving rejects to file xrolo.c.rej


Am I doing it wrong? Sorry to be a bother.

EDIT: Nevermind! I applied the patch by hand, and it worked! Thank you so much! :D
Back to top
View user's profile Send private message
i92guboj
Bodhisattva
Bodhisattva


Joined: 30 Nov 2004
Posts: 10315
Location: Córdoba (Spain)

PostPosted: Mon Oct 20, 2014 6:09 am    Post subject: Reply with quote

Just delete the ".orig" string from the patch and it should work ;)

In any case, you are welcome, but beware that as said I didn't look at all at the code. I just added a check so that the strncpy() func doesn't run over uninitialized buffers. I have no idea on how that will impact the program workflow.

See you around ;)
Back to top
View user's profile Send private message
Silent-Hunter
Apprentice
Apprentice


Joined: 07 Jul 2013
Posts: 166

PostPosted: Fri Oct 24, 2014 5:08 am    Post subject: Reply with quote

No worries, it works fine!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum