2011年4月27日

cross-compile:libtool

From: http://orzlab.blogspot.com/2007/05/cross-compilelibtool.html

/bin/sh libtool --mode=link target-gcc -c -O2 -o libbar.so ... -lfoo
target-gcc -c -O2 -o libbar.so ... /usr/lib/libfoo.so
/usr/lib/libfoo.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status

In cross-compilation, the link should point to target installation path, not local host path.

Solution:
1. Edit libfoo.la.
2. Modify
libdir='/usr/lib' to target lib installation path. Such as "/export/arm_toolchain/usr/lib".

2011年4月12日

system() return (10): No child processes

The code includes "signal(SIGCHLD, SIG_IGN); " to prevent process from zombie.
So the wait() is unable to get the signal and system() will return -1.

Solution:
Change from SIG_IGN to SIG_DFL.

In my case, I have to retain signal(SIGCHLD, SIG_IGN), so how to handle well with its return value?

2011年4月7日

popen hangs!?

The suspicion is waitpid()?
After comment it out, the code works well and doesn't hang on popen().

Ref: http://pubs.opengroup.org/onlinepubs/009695399/functions/pclose.html
The issue may be related to pclose().
The return value of pclose() is always "-1", and the next popen() call hangs then.
From functional description, it says:

The pclose() function shall close a stream that was opened by popen(), wait for the command to terminate, and return the termination status of the process that was running the command language interpreter. However, if a call caused the termination status to be unavailable to pclose(), then pclose() shall return -1 with errno set to [ECHILD] to report this situation. This can happen if the application calls one of the following functions:

  • wait()
  • waitpid() with a pid argument less than or equal to 0 or equal to the process ID of the command line interpreter
  • Any other function not defined in this volume of IEEE Std 1003.1-2001 that could do one of the above.

In any case, pclose() shall not return before the child process created by popen() has terminated.

And in my case, the signal handler routine is using waitpid(-1, &stat, WNOHANG). After change it to waitpid(forked_pid, &stat, WNOHANG) to ignore SIGCHLD triggered by popen(), the application doesn't hang anymore.

2011年4月6日

time.h: undefined reference to `__aeabi_uldivmod'

linux_2_6_21/include/linux/time.h:184: undefined reference to `__aeabi_uldivmod'

Kernel: v2.6.21.1
Compiler: gcc v4.3.3

Solution:

From http://lkml.org/lkml/2008/2/22/464.

--- include/linux/time.h 2008-10-09 19:47:23.000000000 +0200
+++ include/linux/time.h.new 2008-10-09 19:47:54.000000000 +0200
@@ -173,6 +173,10 @@
{
ns += a->tv_nsec;
while(unlikely(ns >= NSEC_PER_SEC)) {
+ /* The following asm() prevents the compiler from
+ * optimising this loop into a modulo operation. */
+ asm("" : "+r"(ns));
+
ns -= NSEC_PER_SEC;
a->tv_sec++;
}