[gambit-list] I think I found a bug on Gambit-C's build process during building for iOS.

Eonil drawtree at gmail.com
Sun Feb 20 10:04:36 EST 2011


Hi.
I'm Hoon Hwangbo, and currently trying to build Gambit-C for Apple's iOS platforms. I think I found a bug on Gambit-C's build process. Please reply your opinions.

I started with cross-compiling whole source code with iOS SDK. I followed 'jlongster''s method described on:

	http://jlongster.com/legacy/scheme-iphone-apps.html

I had succeed building for iOS device. `libgambc.a` linked and executed well.
But I met some errors during building for iOS simulator. (iOS has 2 kind of platforms, I'll describe about this later section)

This is first error.

	os_io.c: In function ‘___device_stream_kind_from_fd’:
	os_io.c:5835: error: storage size of ‘s’ isn’t known
	make[1]: *** [os_io.o] Error 1
	make: *** [all-recursive] Error 1

The line at source code is,

	struct ___stat s;

`___stat` is typedef-ed as `stat`. I don't know why, however, it couldn't be compiled. I just modified the code uing `stat` type directly.

	struct stat s;

Compilation continued.
And another error pop up. 

	os.c: In function ‘___os_file_info’:
	os.c:1488: error: storage size of ‘s’ isn’t known
	make[1]: *** [os.o] Error 1
	make: *** [all-recursive] Error 1

Exactly same error and exactly same source code. I modified it as same as above.
Compilation continued. Build complete without additional error. It's linked but failed to be executed. It raised a runtime error:

	Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
	fstat64 called from function ___device_stream_setup_from_fd in image gambit-c-test3.
	If you are encountering this problem running a simulator binary within gdb, make sure you 'set start-with-shell off' first.
	Program received signal:  “SIGABRT”.

I felt there is an error about determining environment is 32-bit or 64-bit. Because iOS simulator is completely 32bit environment.
I rollbacked all changes. I searched `fstat64` from all source code, and I found it's on 'include/configure.h'. It's marked like this.

	#define HAVE_STAT64 1

I changed it like this.

	#define HAVE_STAT64 0

Compilation failed again exactly same with first 2 errors.
I didn't modified the code like before. Instead of, I looked at 'os.h'. There was a code block.

	#ifdef HAVE_STAT64
	#define USE_stat
	#define ___stat stat64
	#define ___lstat lstat64
	#define ___fstat fstat64
	#else
	#ifdef HAVE_STAT
	#define USE_stat
	#define ___stat stat
	#define ___lstat lstat
	#define ___fstat fstat
	#endif
	#endif

I modified it like this to force using only 32-bit functions.

	/*
	#ifdef HAVE_STAT64
	#define USE_stat
	#define ___stat stat64
	#define ___lstat lstat64
	#define ___fstat fstat64
	#else
	#ifdef HAVE_STAT
	 */
	#define USE_stat
	#define ___stat stat
	#define ___lstat lstat
	#define ___fstat fstat
	/*
	#endif
	#endif
	 */

And finally… It worked! Compiled well, linked well, executed well!
I don't know why it was configured using 64-bit functions. Maybe the bug in the tool-chain, but it should be evaded to support iOS.

It's working now, but I can't sure my modification is correct. Maybe it's not correct. My modification destructs #ifdef logic. I didn't analyze all the logic. There were test codes, but I don't know how to execute the test. (Can you let me know how to execute the test...?) I'm not good at low-level system programming. I'm just a programmer who want to embed nice scripting system with functional language into my app. I'm newbie on `make` tool-chain and complete newbie on Scheme :)

I wish this errors to be corrected. Maybe building for iOS is not so important, this errors may a sign of another bug. Please review the codes at the positions. 




PS. My environment:
- Mac OS X 10.6 Snow Leopard
- iOS SDK 4.2
- Gambit-C 4.6 source code of version





iOS platform description.
======================
There are 2 kind of iOS platform.

- iOS Device. This is real hardware platform composed of ARM(32bit)+darwin(32bit)
- iOS Simulator. This is simulated platform on Mac OS X. Composed of x86(32bit)+darwin(32bit) This is not a full emulator. It's behaves a little differently with iOS Device platform.

So, Apple offers SDK with 2 versions of development tool-chains.
Each version contains modified version of GCC for each platform.







CONTACT
+ Hwangbo Hoon
+ iPhone: +82 10 4583 3612
+ Twitter: http://twitter.com/#!/eonilc
+ Blog: http://blog.eonil.com/ (Korean)




More information about the Gambit-list mailing list