Funnily enough, I currently have trouble cross-compiling applications on ARM
with my libc. It used to work, but maybe I was doing things differently and I
don't remember it (static linking? manual patches? less code?). Anyway, I am
coming across these two problems now.
« hidden symbol `__name_here' in /some/library/path.a(_filename.o) is referenced by DSO »
This one made me lose an incredible amount of time. It usually occurs when you
overrule the linker's default libraries and object files, because then a
plethora of compiler-specific functions are not linked in anymore, whereas often
(not always) used in the compiled code. This happens typically with "complex"
mathematical functions on RISC platforms, like ARM.
Here is an illustration of the problem:
(compiling as root as I'm testing hackable:1's cross compiler in a
chroot)
# ./build.sh CC=arm-linux-gnueabi-gcc all
arm-linux-gnueabi-gcc -o sh token.o scanner.o parser.o builtin.o job.o sh.o -no
stdlib -L /root/DeforaOS/destdir-Linux-i386/usr/local/lib -Wl,-rpath-link,/usr/l
ocal/lib -l c -l gcc /root/DeforaOS/destdir-Linux-i386/usr/local/lib/start.o
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: sh: h
idden symbol `__aeabi_uidiv' in /usr/lib/gcc/arm-linux-gnueabi/4.3.2/libgcc.a(_u
divsi3.o) is referenced by DSO
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: final
link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[1]: *** [sh] Error 1
make[1]: Leaving directory `/home/khorben/DeforaOS/Apps/Unix/src/sh/src'
make: *** [subdirs] Error 2
In this case, the problem is usually solved by adding either "-l gcc"
or "`gcc -print-libgcc-file-name`" to the linking flags (LDFLAGS).
However, unlike my other regular platforms (i386, amd64, sparc64) here it wasn't
enough. After a lot of head-banging (to be fair, it also comes from the music) I
realized that this flag is necessary both when linking the libc *and* the
final executable file.
« warning: type and size of dynamic symbol `choose_your_poison'
are not defined »
So yeah, problem solved, right? Until the next one :(
(after hacking System/src/libc/src/Makefile so that
LDFLAGS are used when linking the libc too)
# ./build.sh CC=arm-linux-gnueabi-gcc all
arm-linux-gnueabi-gcc -o du du.o -nostdlib -L /root/DeforaOS/destdir-Linux-i386
/usr/local/lib -Wl,-rpath-link,/usr/local/lib -l c -l gcc /root/DeforaOS/destdir
-Linux-i386/usr/local/lib/start.o
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: warni
ng: type and size of dynamic symbol `lstat' are not defined
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: dynam
ic variable `lstat' is zero size
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: warni
ng: type and size of dynamic symbol `stat' are not defined
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: dynam
ic variable `stat' is zero size
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: du.o(
.text+0x208): unresolvable R_ARM_ABS32 relocation against symbol `lstat'
/usr/lib/gcc/arm-linux-gnueabi/4.3.2/../../../../arm-linux-gnueabi/bin/ld: final
link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[1]: *** [du] Error 1
make[1]: Leaving directory `/root/DeforaOS/Apps/Unix/src/utils/src'
make: *** [subdirs] Error 2
Unfortunately, this one still eludes me: the fault seems to be within my libc,
as it compiles fine against the glibc. Here is the incriminated code:
Apps/Unix/src/utils/src/du.c:
64 static int _du_do(Prefs * prefs, char const * filename)
65 {
66 int (* _stat)(const char * filename, struct stat * buf) = lstat;
67 struct stat st;
68
69 if(*prefs & PREFS_H)
70 _stat = stat;
71 if(_stat(filename, &st) != 0)
72 return _du_error(filename);
73 if(!S_ISDIR(st.st_mode))
74 {
75 _du_print(prefs, st.st_blocks, filename);
76 return 0;
77 }
78 return _du_do_recursive(prefs, filename);
79 }
System/src/libc/src/kernel/linux/arm/syscalls.S:
32 /* macros */
33 #define SYSCALL(name) \
34 .global name; \
35 name:; \
36 mov %ip, %r7; \
37 ldr %r7, =SYS_ ## name; \
38 b _syscall;
System/src/libc/src/syscalls.S:
217 #ifdef SYS_lstat
218 SYSCALL(lstat)
219 #endif
I tried different combinations of extra assembly-level information, like
".type name,@function; \", but only unsuccessfully so far. If you know
what I should do, feel free to contact me.