Bug 692211 - ghostscript 9.02 includes byteswap.h which does not exist on FreeBSD
Summary: ghostscript 9.02 includes byteswap.h which does not exist on FreeBSD
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 9.02
Hardware: PC FreeBSD
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-18 15:47 UTC by Johan Hattne
Modified: 2011-05-24 20:31 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
Fix include of byteswap.h, non-existant on FreeBSD (451 bytes, application/octet-stream)
2011-05-18 15:47 UTC, Johan Hattne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Johan Hattne 2011-05-18 15:47:20 UTC
Created attachment 7514 [details]
Fix include of byteswap.h, non-existant on FreeBSD

ghostscript 9.02 uses byteswap.h, even though it seems to have code in place to use GCC's built-in byte swapping functions.  FreeBSD's libc does not come with byteswap.h.  Attempting to build ghostscript 9.0.2 yields

i686-gentoo-freebsd8.0-gcc  -DHAVE_MKSTEMP -DHAVE_HYPOT   -DHAVE_FONTCONFIG -DHAVE_SETLOCALE -DHAVE_SSE2  -fPIC  -O2 -fPIC -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -Wno-strict-aliasing -Wdeclaration-after-statement -fno-builtin -fno-common -DHAVE_STDINT_H -DGX_COLOR_INDEX_TYPE="unsigned long long" -march=pentium4 -O2 -pipe -fomit-frame-pointer -DUSE_LIBICONV_GNU -DUSE_LIBPAPER -DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\"/usr/lib/ghostscript/9.02\" -I./psi -I./obj/../soobj -I./obj/../soobj -I./base  -o ./obj/../soobj/zchar1.o -c ./psi/zchar1.c
In file included from ./base/gxdevcli.h:27:0,
                 from ./base/gxdevice.h:21,
                 from ./psi/zchar1.c:22:
./base/gsropt.h:386:22: fatal error: byteswap.h: No such file or directory compilation terminated.

Attached patch addresses the problem.  It's been tested on FreeBSD 8, as well as a recent Gentoo/Linux installation.
Comment 1 Robin Watts 2011-05-19 17:34:48 UTC
I've done some googling, and it looks like byteswap.h should be present on all versions of gcc > 2, and the __builtin_bswap32 function on all GCC_VERSIONS from than 4.3.

I therefore propose to use __builtin_bswap32 if GCC >= 4.3 and byteswap.h otherwise.

See git commit e60ed1f.

Please let me know if this doesn't resolve it for you. Thanks for your bug report and patch!
Comment 2 Johan Hattne 2011-05-19 19:38:18 UTC
(In reply to comment #1)
> I've done some googling, and it looks like byteswap.h should be present on all
> versions of gcc > 2, and the __builtin_bswap32 function on all GCC_VERSIONS
> from than 4.3.

I'm OK with the use of GCC's __builtin_bswap32 function, but byteswap.h is supplied by glibc on my Linux boxes, and FreeBSD provides its own standard C library.  As far as I can see, neither GCC 4.4.5 nor GCC 4.5.2 install a byteswap.h header--the source tarballs don't even contain a file by that name.

> I therefore propose to use __builtin_bswap32 if GCC >= 4.3 and byteswap.h
> otherwise.

That'd work for me, since my FreeBSD machine has GCC >= 4.3.  However, for the above reason, I'm not sure it's correct.  What about falling back on an implementation like

  #define ENDIAN_SWAP_INT(x) (             \
        (uint32_t)(x) & 0x000000ff << 24 | \
        (uint32_t)(x) & 0x0000ff00 <<  8 | \
        (uint32_t)(x) & 0x00ff0000 >>  8 | \
        (uint32_t)(x) & 0xff000000 >> 24)

if GCC < 4.3 and byteswap.h isn't there?
Comment 3 Henry Stiles 2011-05-20 00:44:05 UTC
In file included from ./base/gxdevcli.h:27,
                 from ./base/gxdevice.h:21,
                 from ./psi/zchar1.c:22:
./base/gsropt.h:396:22: error: byteswap.h: No such file or directory
make: *** [obj/zchar1.o] Error 1


gcc --version
i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

uname -a
Darwin henry-stiles2s-macbook-pro.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386

I'd recommend a test in configure to check if byteswap.h exists.
Comment 4 Robin Watts 2011-05-24 15:34:20 UTC
Autoconf hackery added to detect bswap intrinsics and/or byteswap.h

http://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=4dc31e78ea0b58973f5a97319eafcbc10e5b9f2b
Comment 5 Johan Hattne 2011-05-24 17:08:49 UTC
(In reply to comment #4)
> Autoconf hackery added to detect bswap intrinsics and/or byteswap.h

Even though I don't have access to such a system, the case where neither byteswap.h nor __builtin_bswap32 is available isn't covered?
Comment 6 Robin Watts 2011-05-24 20:31:18 UTC
If neither is defined, then we don't define ENDIAN_SWAP_INT. The code internally to gs copes with or without ENDIAN_SWAP_INT.

Specifically, the code inside gs knows 2 idioms; one that works bytewise, and one that works in int sized chunks. The benefit of using ints only pays off if they are natively big endian, or can be made so *fast*.

So using a generic #define would not be a win for us - hence we don't provide one.

I hope that makes sense :)