Ticket #668 (closed task: fixed)

Opened 8 months ago

Last modified 8 months ago

src/data_sources/srusb2ew are not likely to be 64-bit compatible

Reported by: baker Owned by: somebody
Priority: minor Milestone: All Platforms
Component: ALL modules Version: 7.9
Keywords: 64-bit Cc:


src/data_sources/srusb2ew contains structure definitions that assume long is 32 bits. On 64-bit systems, this may not be the case. In that case, the program will not function properly, if at all.

I added a test in the header file that defines the data file format:

 * NOTE: The layout of the .dat file header assumes long is 32-bits. *
 * On a 64-bit system, this may not be correct.  Any data types that *
 * must be 8, 16 ,or 32 bits should be declared using the C standard *
 * integer types defined in stdint.h.  Until then, fail on systems   *
 * where long is not 32 bits.                                        *

#include <limits.h>
#include <stdint.h>
#if ( LONG_MAX != INT32_MAX )
#error sizeof( long ) != sizeof( int )

On my Mac, this causes the 64-bit compile to fail:

gcc -c -g -m64 -g -D_MACOSX -D_DARWIN_C_SOURCE -D_INTEL -D_USE_SCHED -D_USE_PTHREADS -D_DARWIN_USE_64_BIT_INODE -I/Users/baker/Desktop/Software/Earthworm/earthworm-7.10-7509/include -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unknown-pragmas -Wno-pragmas -Wformat -Wdeclaration-after-statement -DSROS_LINUX -I/Users/baker/Desktop/Software/Earthworm/earthworm-7.10-7509/src/data_sources/srusb2ew/USBXCH/Include -o srusb2ew.o  srusb2ew.c
In file included from srusb2ew.c:141:
/Users/baker/Desktop/Software/Earthworm/earthworm-7.10-7509/src/data_sources/srusb2ew/USBXCH/Include/SrUsbXch.h:25:2: error: sizeof( long ) != sizeof( int )
#error sizeof( long ) != sizeof( int )
1 error generated.
make[2]: *** [srusb2ew.o] Error 1
make[1]: *** [unix_modules] Error 2
make: *** [unix_modules] Error 2

As expected, the size of int and long are not the same when -m64 is used:

$ gcc -m32 junk.c
$ ./a.out
sizeof( int )  = 4
sizeof( long ) = 4
$ gcc -m64 junk.c
$ ./a.out
sizeof( int )  = 4
sizeof( long ) = 8

Until programs can be converted to use the C standard integer types in stdint.h, this is probably a valuable guard that can be replicated elsewhere when data structures rely on long to be 32 bits.

Change History

comment:1 Changed 8 months ago by baker

  • Status changed from new to closed
  • Resolution set to fixed

r7531 enforces the assumptions in src/data_sources/srusb2ew that long is an int and that int is 32 bits (4 characters). A preprocessor #error prevents compilation from succeeding if those conditions fail. Also, the use of (not portable) muti-byte character constants is disabled.

r7532 modifies src/data_sources/Makefile to separate out builds that are not 64-bit compliant. srusb2ew is only built when EW_BITS == 32. The technique there (syntax that is acceptable to both make/sh on Unix and nmake/cmd.exe on WINNT) can be replicated elsewhere for the same purpose.

r7532 also modifies src/data_sources/Makefile to clean/clean_bin all modules, whether they are built or not on the platform.

There were many missing or broken clean/clean_bin make targets. r7533 fixes existing makefiles and adds missing makefile.unix's for WINNT-only builds. make clean and make clean_bin should not have any makefile errors; there may be error messages if files that are being deleted do not exist.

comment:2 Changed 8 months ago by stefan

From the Wendy Tucker at Symmetric:

Our current stuff is working just fine on Windows and Linux 32 and 64 bit on the PC. But we've never done much with the Mac or Solaris, and it seems doubtful we ever will. So ifdef-ing it out on those machines is fine.

Recently we restructured our software to use software pipelines and a more modular approach so it is easier to maintain. As part of that I've been revising our Earthworm interface too. I'll send you a new version when it's done. If you have a target date for the next EW release, let me know and I'll have the code ready before then.

comment:3 Changed 8 months ago by baker


Can you get clarification about what Wendy means by "Our current stuff is working just fine on Windows and Linux 32 and 64 bit on the PC"? If she means the same code that is in the Earthworm SVN, I'll demonstrate the failure on 64-bit compiles. Any platform on which a long and an int are not both 32 bits breaks assumptions built into the code. Perhaps silently.

My changes to the code do not if-def out anything. They cause the compile to fail when those prerequisites are not met.

I disabled building the broken srusb2ew module for all 64-bit builds in the makefiles after verifying the code fails to compile on a 64-bit Mac.


Note: See TracTickets for help on using tickets.