Bug 707915

Summary: gs gives bus error on NetBSD/sparc (32-bit) 10.0
Product: Ghostscript Reporter: Brandon Applegate <brandon>
Component: GeneralAssignee: Chris Liddell (chrisl) <chris.liddell>
Status: RESOLVED INVALID    
Severity: normal CC: ghostpdl-bugs, robin.watts
Priority: P2    
Version: 10.03.1   
Hardware: Sun   
OS: NetBSD   
Customer: Word Size: ---
Attachments: gs ktruss output
golfer.eps
config.log

Description Brandon Applegate 2024-07-29 20:10:45 UTC
Created attachment 25881 [details]
gs ktruss output

Hello,

I know this OS and platform are way in the weeds, but I do actually use GS on my old Suns running NetBSD.

In the NetBSD pkgsrc system, there are currently two versions of GS:

9.06 (GPL)
10.03.1 (AGPL)

I am getting the error on 10.03.1 version.  9.06 seems to work as expected, but obviously that's a very old version and will likely be removed from pkgsrc at some point soon.

I don't get a core dump, just a bus error.

The example command line is:

gs -sDEVICE=x11 golfer.eps

I get a split second window outline to appear and then it's gone and I get bus error at my shell.

I will attach golfer.eps as well as a ktruss output from the command.  I'm looking into any other diag info I can give you guys as well.  If there's anything I can further test please let me know, happy to do so.
Comment 1 Brandon Applegate 2024-07-29 20:11:20 UTC
Created attachment 25882 [details]
golfer.eps
Comment 2 Brandon Applegate 2024-07-29 20:20:00 UTC
Also forgot to mention...

In a QEMU NetBSD/sparc VM - gs seems to work okay.  On real hardware (in my case an SS10 with 320mb RAM (plenty...)) it doesn't.  The QEMU machine emulates a TCX and my SS10 has a TGX+ video/framebuffer.  

Let me know if there are some non-X11 display/device commands I can run to validate the other functionality in gs.
Comment 3 Brandon Applegate 2024-07-30 02:59:35 UTC
Ran gdb on this too, seems like something is getting confused between sparcv8 (32 bit what I have) and sparcv9 (64-bit - NOT what I am running):

Starting program: /usr/pkg/bin/gs -sDEVICE=x11 golfer.eps

Program received signal SIGILL, Illegal instruction.
0xeb0762b4 in _sparcv9_vis1_probe () from /usr/lib/libcrypto.so.15
Comment 4 Chris Liddell (chrisl) 2024-07-30 07:30:28 UTC
I'm not sure there's much we can do to help. I have no access to a system such as the one you are using.


The error seems to be occurring in the libcrypto.so shared library, which isn't a (direct) dependency of Ghostscript, so must be getting pulled in via some other dependency.

I don't know how Ghostscript is configured when built for the pkgsrc system.

I'd suggest trying something other than X11 for the output, something like:

gs -sDEVICE=ppmraw -o /dev/null golfer.eps

and see how that behaves.

Past that, I feel your first port of call needs to be the pkgsrc package maintainer.
Comment 5 Brandon Applegate 2024-08-16 00:16:18 UTC
I found a workaround in another ghostscript bug report:

https://bugs.ghostscript.com/show_bug.cgi?id=695979#c20

The crash was actually happening in lcms2 due to an alignment error.  I guess sparc is much less forgiving of those than x86.

Adding "-dUseFastColor=true” to gs args uses the older color management engine and bypasses this error.

We can close this issue, thanks.
Comment 6 Ken Sharp 2024-08-16 07:29:46 UTC
(In reply to Brandon Applegate from comment #5)
> I found a workaround in another ghostscript bug report:
> 
> https://bugs.ghostscript.com/show_bug.cgi?id=695979#c20
> 
> The crash was actually happening in lcms2 due to an alignment error.  I
> guess sparc is much less forgiving of those than x86.
> 
> Adding "-dUseFastColor=true” to gs args uses the older color management
> engine and bypasses this error.
> 
> We can close this issue, thanks.

Could you possibly try the suggestion in comment #28 (!!) of that bug report ?

From chris's comment:

----------------------------------------------
You could try building thus:

make clean
./configure CFLAGS="-DCMS_PTR_ALIGNMENT=8"
make

And see if the problem still happens.
----------------------------------------------

And let us know if that helps ? We'd like to get the problem addressed properly if we can, and your output will be poorer quality regarding colours if you use -dUseFastColor.
Comment 7 Chris Liddell (chrisl) 2024-08-16 08:05:12 UTC
Also... if that does resolve the problem, could you attached the "config.log" file from your build, please? I can then get the information required to have configure set the alignment automatically.
Comment 8 Brandon Applegate 2024-08-16 23:43:19 UTC
Yes to both.  I think I know how to shim this CFLAGS change in correctly in pkgsrc.  I will try to work on this tomorrow.  Thanks.
Comment 9 Brandon Applegate 2024-08-17 02:55:54 UTC
Created attachment 25958 [details]
config.log

Here is the config.log from a default "make configure" in pkgsrc.  This is using NetBSD's pkgsrc defaults for ghostscript-agpl.  In other words, I didn't disable anything or enable anything extra.  Vanilla build.
Comment 10 Brandon Applegate 2024-08-17 02:56:57 UTC
I'm going to try to build this overnight with the extra CFLAG.  Since I was paranoid about cross compile, QEMU etc, I'm actually building this on real hardware which is incredibly slow.
Comment 11 Brandon Applegate 2024-08-17 22:38:30 UTC
So I'm having a bit of trouble with this.

https://www.netbsd.org/docs/pkgsrc/faq.html#ufaq-cflags

If you look at section 10.15 right there - it seems sometimes setting this in /etc/mk.conf isn't passed through / honored.  I don't know if gs does this or not.

On NetBSD - running "make configure" in a package directory pulls in includes of other Makefile snippets from the greater pkgsrc system.  If I add -DCMS_PTR_ALIGNMENT=8 to CFLAGS+= in /etc/mk.conf - make configure bombs out.  I'm guessing that flag trips up gcc on a test in make configure ?

So what I thought I would do is edit a Makefile *after* configuration.  Is this okay:

CFLAGS=$(CFLAGS_STANDARD) $(GCFLAGS) $(AC_CFLAGS) $(XCFLAGS) -DCMS_PTR_ALIGNMENT=8

This is in the "main" gs level Makefile:

ss10# pwd
/usr/pkgsrc/print/ghostscript-agpl/work/ghostscript-10.03.1

ss10# grep ^CFLAGS= Makefile
CFLAGS=$(CFLAGS_STANDARD) $(GCFLAGS) $(AC_CFLAGS) $(XCFLAGS)

I promise I'm not trying to make this more difficult than need be.  I'm just trying to apply this change and still do it "the NetBSD way".

Thanks for your patience with me and I do really appreciate the attention on this from you guys.
Comment 12 Brandon Applegate 2024-08-18 01:52:22 UTC
Sorry to jump around so much, I just wanted to ask before I forgot..

I found a section in the code that sets the alignment to 8 on certain (older) platforms (I think at least):

if test x"$GS_MEMPTR_ALIGNMENT" = xcheck ; then
  case $host in
    *hpux*|*-sun*|*-aix*|*-solaris*)
     GS_MEMPTR_ALIGNMENT=8

But on a NetBSD/sparc system, this is the host type yes ?:

ss10# gcc -v 2>&1 | grep ^Target
Target: sparc--netbsdelf

Could it just be that this test isn't matching on the sparc and/or netbsd part and therefore causing this issue ?
Comment 13 Brandon Applegate 2024-08-18 14:01:54 UTC
Okay so here's what I did.  Spoiler - it seems setting that alignment to 8 didn't fix the issue, still get a bus error from liblcms.

I edited the configure script before actually configuring.  I added *sparc* to this section:

if test x"$GS_MEMPTR_ALIGNMENT" = xcheck ; then
  case $host in
    *hpux*|*-sun*|*-aix*|*-solaris*|*sparc*)
     GS_MEMPTR_ALIGNMENT=8
    ;;
    *)
    ;;
  esac
fi

This seems to have added the alignment CFLAG as evidenced by the below.  If I am off base on this or this is wrong please let me know.

ss10# grep GS_MEMPTR_ALIGNMENT .work.log | grep gcc | wc -l
     713

ss10# grep GS_MEMPTR_ALIGNMENT .work.log | grep gcc | tail -1
<.> /usr/pkgsrc/print/ghostscript-agpl/work/.gcc/bin/gcc -fcommon -fstack-protector-strong -D_FORTIFY_SOURCE=2 -DHAVE_MKSTEMP -DHAVE_FSEEKO -DHAVE_FONTCONFIG -DHAVE_LIBIDN -DHAVE_SETLOCALE -DHAVE_BSWAP32 -DHAVE_STRERROR -DHAVE_ISNAN -DHAVE_ISINF -DHAVE_PREAD_PWRITE=1 -DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE -O2 -DNDEBUG -DPNG_NO_ASSEMBLER_CODE -I/usr/pkgsrc/print/ghostscript-agpl/work/.buildlink/include -I/usr/pkgsrc/print/ghostscript-agpl/work/.x11-buildlink/include -I/usr/include/krb5 -I/usr/pkgsrc/print/ghostscript-agpl/work/.buildlink/include/freetype2 -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 '-DGX_COLOR_INDEX_TYPE=unsigned long long' -D__USE_UNIX98=1 -DHAVE_SNPRINTF -DGS_USE_MEMORY_HEADER_ID=0 -DGS_MEMPTR_ALIGNMENT=8 -DBUILD_PDF=1 -I./pdf -O2 -DA4 -fPIC -DHAVE_RESTRICT=1 -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1 -I./soobj -I./base -I./devices -DWHICH_CMS=lcms2 -L./sobin -L/usr/pkgsrc/print/ghostscript-agpl/work/.buildlink/lib -L/usr/pkgsrc/print/ghostscript-agpl/work/.x11-buildlink/lib -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib -o ./sobin/gsx ./soobj/dxmainc.o -lgs

ss10# grep DCMS_PTR_ALIGNMENT .work.log | grep gcc | wc -l
       1

ss10# grep DCMS_PTR_ALIGNMENT .work.log | grep gcc 
<.> /usr/pkgsrc/print/ghostscript-agpl/work/.gcc/bin/gcc -fcommon -fstack-protector-strong -D_FORTIFY_SOURCE=2 -DSHARE_LCMS=1 -DCMS_USE_BIG_ENDIAN=1 -DCMS_PTR_ALIGNMENT=8 -O2 -DNDEBUG -fPIC -fvisibility=hidden '-DGSDLLEXPORT=__attribute__((visibility("default")))' -DPNG_NO_ASSEMBLER_CODE -I/usr/pkgsrc/print/ghostscript-agpl/work/.buildlink/include -I/usr/pkgsrc/print/ghostscript-agpl/work/.x11-buildlink/include -I/usr/include/krb5 -I/usr/pkgsrc/print/ghostscript-agpl/work/.buildlink/include/freetype2 -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 '-DGX_COLOR_INDEX_TYPE=unsigned long long' -D__USE_UNIX98=1 -DHAVE_SNPRINTF -DGS_USE_MEMORY_HEADER_ID=0 -DGS_MEMPTR_ALIGNMENT=8 -DBUILD_PDF=1 -I./pdf -O2 -DA4 -fPIC -DHAVE_RESTRICT=1 -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1 -I./soobj -I./base -I./devices -Isrc/include -o ./soobj/gsicc_lcms2_1.o -c ./base/gsicc_lcms2.c
Comment 14 Robin Watts 2024-08-19 00:24:08 UTC
Possible dumb question here...

Could you try a debug build, and run it under gdb?

  make debug
  gdb --args debugbin/gs -sDEVICE=x11 golfer.eps

It's still worth trying a non-x11 device, as was suggested above!

 gdb --args debugbin/gs -sDEVICE=ppmraw -o out.ppm golfer.eps

If it fails under gdb, then issuing the 'bt' command will give us a backtrace that leads us to a much more exact location of the error.

There may be reasons why that isn't possible for you of course (like gdb not being available), but I'd imagine that it *SHOULD* be available for most systems of your vintage now.
Comment 15 Brandon Applegate 2024-08-19 16:18:18 UTC
Here is what I tried.

Used source tar achive from NetBSD distfiles (same as from Github).  Applied NetBSD patches from pkgsrc.  Ran autogen.sh with config args as such:

./configure --enable-openjpeg --without-tesseract --with-x --enable-cups --with-libiconv=no --x-includes=/usr/X11R7/include --x-libraries=/usr/X11R7/lib --prefix=/usr/pkg --build=sparc--netbsdelf --host=sparc--netbsdelf --mandir=/usr/pkg/man --enable-option-checking=yes

I had to remove one of the libtiff args that NetBSD uses as it complained about something regarding local libtiff vs. shared jpeg ?

Anyway - this is what I get now when I try a "make debug":

ss10# make debug
make -f Makefile GENOPT='-DDEBUG' CFLAGS='-gdwarf-2 -g3 -O0 -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -DHAVE_SNPRINTF -DGS_USE_MEMORY_HEADER_ID=0  -DBUILD_PDF=1 -I./pdf  -DHAVE_RESTRICT=1 -I/usr/pkg/include -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1 '  GENOPTAUX='-DDEBUG_AUX' CFLAGSAUX='-gdwarf-2 -g3 -O0 -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -DHAVE_SNPRINTF -DGS_USE_MEMORY_HEADER_ID=0  -DHAVE_RESTRICT=1 -fno-strict-aliasing -DHAVE_POPEN_PROTO=1 ' BUILDDIRPREFIX=debug default
make[1]: don't know how to make |. Stop

make[1]: stopped in /root/gstmp/ghostscript-10.03.1
*** Error code 2

Stop.
make: stopped in /root/gstmp/ghostscript-10.03.1
Comment 16 Chris Liddell (chrisl) 2024-08-19 20:58:20 UTC
If you have GNU make (often "gmake") available, use that.

Otherwise, rerun configure with "--without-gnu-make" and then try building again.
Comment 17 Brandon Applegate 2024-08-20 16:09:23 UTC
So I got the debug build to complete successfully.  However now the debug bin can't find a handful of libs.  There's plenty that do get found properly, but doing an ldd no the debugbin gives me this:

	-lXt.7 => not found
	-lSM.7 => not found
	-lICE.7 => not found
	-lXext.7 => not found
	-lX11.7 => not found
	-lfontconfig.2 => not found
	-lfreetype.19 => not found
Comment 18 Chris Liddell (chrisl) 2024-10-30 14:13:50 UTC
(In reply to Brandon Applegate from comment #17)
> So I got the debug build to complete successfully.  However now the debug
> bin can't find a handful of libs.  There's plenty that do get found
> properly, but doing an ldd no the debugbin gives me this:
> 
> 	-lXt.7 => not found
> 	-lSM.7 => not found
> 	-lICE.7 => not found
> 	-lXext.7 => not found
> 	-lX11.7 => not found
> 	-lfontconfig.2 => not found
> 	-lfreetype.19 => not found

Sorry, I completely missed this message.

At a guess, you may need to set library search paths so the specific instances of those libs can be found.

IIRC, you can use the environment variable LD_LIBRARY_PATH to set it for the current shell instance.
Comment 19 Chris Liddell (chrisl) 2025-07-17 08:38:15 UTC
With no way to reproduce this, and no response for quite some time, I'm closing.