I'm trying to port some Ogg multimedia codecs to Java with the help of Cibyl. The first step would be to compile libogg. I'm using following script to set up crosscompiling:
With these things set the configure script for libogg will complete successfully. The actual build doesn't work that nicely (see build messages at the end of this mail).
Those undefined reference errors seem to stem from not using the standard libraries. I very much assume that the standard libraries cannot be used together with Cibyl, so I wonder how to get around those errors. Is this caused by e.g. Cibyl not implementing those functions or by some error on my part?
bye,
Maik
mips-unknown-linux-gnu-gcc -D_V_SELFTEST -O20 -fsigned-char -Wall -mips1 -mno-check-zero-division -Os -fno-pic -mno-abicalls -I/mnt/data/builds/cibyl-15/include -I/mnt/data/mips/include -march=mips1 -nostdlib -T/mnt/data/builds/cibyl-15/build/linker.lds --static -o test_bitwise test_bitwise-bitwise.o -L/mnt/data/builds/cibyl-15/lib/ -L/mnt/data/mips/lib/ /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/bin/ld: warning: cannot find entry symbol __start; defaulting to 0000000001000000 test_bitwise-bitwise.o(.text+0x14): In function `oggpack_writeinit': : undefined reference to `memset' test_bitwise-bitwise.o(.text+0x1c): In function `oggpack_writeinit': : undefined reference to `malloc' test_bitwise-bitwise.o(.text+0x118): In function `oggpack_write': : undefined reference to `realloc' test_bitwise-bitwise.o(.text+0x278): In function `oggpackB_write': : undefined reference to `realloc' test_bitwise-bitwise.o(.text+0x4a4): In function `oggpack_writecopy_helper': : undefined reference to `realloc' test_bitwise-bitwise.o(.text+0x4c4): In function `oggpack_writecopy_helper': : undefined reference to `memmove' test_bitwise-bitwise.o(.text+0x5f8): In function `oggpack_writeclear': : undefined reference to `free' test_bitwise-bitwise.o(.text+0x614): In function `oggpack_writeclear': : undefined reference to `memset' test_bitwise-bitwise.o(.text+0x648): In function `oggpack_readinit': : undefined reference to `memset' test_bitwise-bitwise.o(.text+0xca4): In function `report': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0xca8): In function `report': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0xcac): In function `report': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0xcb4): In function `report': : undefined reference to `exit' test_bitwise-bitwise.o(.text+0xdc0): In function `cliptest': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0xdc8): In function `cliptest': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0xdd8): In function `cliptest': : undefined reference to `fprintf' test_bitwise-bitwise.o(.text+0x10fc): In function `cliptestB': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1104): In function `cliptestB': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1114): In function `cliptestB': : undefined reference to `fprintf' test_bitwise-bitwise.o(.text+0x193c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1370): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1378): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1554): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x13a8): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x13ac): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1348): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x13b4): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x13bc): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x13e8): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x13ec): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x13f4): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x13fc): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1428): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x142c): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1434): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x143c): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1510): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1518): In function `main': : undefined reference to `fprintf' test_bitwise-bitwise.o(.text+0x1564): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1568): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x156c): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1574): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x157c): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x15a8): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x15ac): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x15b4): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x15bc): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x15e4): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x15e8): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x15f0): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x15f8): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1624): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1628): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1630): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x163c): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1744): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x174c): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x175c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1764): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1790): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1794): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x179c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x17a4): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x17d0): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x17d4): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x17dc): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x17e4): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x180c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1810): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1818): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1820): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x18f8): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1900): In function `main': : undefined reference to `fprintf' test_bitwise-bitwise.o(.text+0x194c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1950): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1954): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x195c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1964): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x1990): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x1994): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x199c): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x19a4): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x19cc): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x19d0): In function `main': : undefined reference to `fputs' test_bitwise-bitwise.o(.text+0x19d8): In function `main': : undefined reference to `stderr' test_bitwise-bitwise.o(.text+0x19e0): In function `main': :
Maik Merten <maikmer...@googlemail.com> wrote: > Those undefined reference errors seem to stem from not using the > standard libraries. I very much assume that the standard libraries > cannot be used together with Cibyl, so I wonder how to get around > those errors. Is this caused by e.g. Cibyl not implementing those > functions or by some error on my part?
They should all, unless I missed something, be implemented by Cibyl (or more correctly: the implementation comes from uClibc, NetBSD and some other sources). The solution is simple: add
> They should all, unless I missed something, be implemented by Cibyl (or > more correctly: the implementation comes from uClibc, NetBSD and some > other sources). The solution is simple: add
> -lc
> to the linker command line.
Thanks. This apparently does solve something but will give different errors (end of this mail). Hmmm... does it try to link to the libc provided by the mips-unknown-linux-gnu setup?
Once I get a working setup I should better document it on the wiki :)
> Just watch out so that there is > no libc.a in /mnt/data/mips/lib/ (I'm not sure what parts are there).
Oh, /mnt/data/mips is just the prefix for all MIPS-compiled libraries I need to cross compile actual applications. There's nothing in there yet.
Maik
mips-unknown-linux-gnu-gcc -D_V_SELFTEST -O20 -fsigned-char -Wall -mips1 -mno-check-zero-division -Os -fno-pic -mno-abicalls -I/mnt/data/builds/cibyl-15/include -I/mnt/data/mips/include -march=mips1 -nostdlib -T/mnt/data/builds/cibyl-15/build/linker.lds --static -o test_bitwise test_bitwise-bitwise.o -L/mnt/data/builds/cibyl-15/lib/ -L/mnt/data/mips/lib/ -lc /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/bin/ld: /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(exit.o) : warning: linking PIC files with non-PIC files /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/bin/ld: warning: cannot find entry symbol __start; defaulting to 0000000001000000 /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(exit.o) (.text+0x0): In function `exit': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(cxa_ate xit.o)(.text+0x0): In function `__new_exitfn': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(cxa_ate xit.o)(.text+0x164): In function `__cxa_atexit': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(fprintf .o)(.text+0x0): In function `fprintf': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(iofputs .o)(.text+0x0): In function `_IO_fputs': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(malloc. o)(.text+0x0): In function `malloc_init_state': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(malloc. o)(.text+0x11c): In function `ptmalloc_lock_all': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(malloc. o)(.text+0x2a0): In function `ptmalloc_unlock_all': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(malloc. o)(.text+0x3d4): In function `ptmalloc_unlock_all2': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(malloc. o)(.text+0x510): In function `munmap_chunk': : relocation truncated to fit: R_MIPS_HI16 _gp_disp /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(malloc. o)(.text+0x564): In function `new_heap': : additional relocation overflows omitted from the output collect2: ld returned 1 exit status make[2]: *** [test_bitwise] Error 1 make[2]: Leaving directory `/mnt/data/builds/ogg/src' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/mnt/data/builds/ogg' make: *** [all] Error 2
I forgot one thing in the last mail: Also link with -ljava, which is used by the Cibyl libc.
On Sun, 09 Mar 2008 18:04:09 +0100
Maik Merten <maikmer...@googlemail.com> wrote: > Thanks. This apparently does solve something but will give different > errors (end of this mail). Hmmm... does it try to link to the libc > provided by the mips-unknown-linux-gnu setup?
It looks like it's trying to do that since you have:
which looks like the system libc. Try linking with ld instead, linking with gcc will typically include some "magic" behind the scenes (compare to when you link C++ applications with g++, which will automatically link with libstdc++ and some other needed libraries). ld will not do this.
You can look in $CIBYL_PATH/build/Rules.mk for how the Cibyl examples are built (or just build one and look at the output).
This is the libc for Linux from your cross-compiler. It's built as position-independent code ("PIC") and that's why you get those warnings (Cibyl uses -fno-pic).
> /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/bin/ld: > warning: cannot find entry symbol __start; defaulting to > 0000000001000000 /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-
__start is defined in $CIBYL_BASE/libs/crt0.o, you should also include that to get a working binary (again you can take a look in Rules.mk).
> linux-gnu/lib/libc.a(exit.o)(.text+0x0): > In function `exit': > : relocation truncated to fit: R_MIPS_HI16 _gp_disp > /opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/lib/gcc/mips-un known-linux-gnu/3.4.5/../../../../mips-unknown-linux-gnu/lib/libc.a(cxa_ate xit.o)(.text+0x0):
This is once more related to position-independence (or how MIPS binaries work). MIPS typically assigns a register to use as base for global data, "GP" as in "Global Pointer". Cibyl again does not use this, if I remember correctly it comes from -fno-pic.
So to summarise: your build errors are with all likelyhood caused by linking with gcc :-)
Apart from the missing -ljava and -lcrt0 the -L$CIBYL_BASE/lib/ was of course wrong (it's libs, not lib - perhaps the Hello World example in the wiki is outdated?).
I think the $CIBYL_BASE/libs/crt0.o is misplaced in LDFLAGS (but inspired from both the Hello World wiki example and Rules.mk) - apparently it tries to generate libogg from crt0.o (?), which of course can only fail. Just using -lcrt0 will result in __start not being found.
As you can easily see my skills with the usual C toolchains are utterly underdeveloped. How I wished "javac *.java" would work ;-)
Looks good, but as you said crt0.o should perhaps not be in LDFLAGS (just on the command line where you invoke ld). --static should not be needed - it's implicit.
> Apart from the missing -ljava and -lcrt0 the -L$CIBYL_BASE/lib/ was of > course wrong (it's libs, not lib - perhaps the Hello World example in > the wiki is outdated?).
You're right, that's a bug on the wiki.
> I think the $CIBYL_BASE/libs/crt0.o is misplaced in LDFLAGS (but > inspired from both the Hello World wiki example and Rules.mk) - > apparently it tries to generate libogg from crt0.o (?), which of > course can only fail. Just using -lcrt0 will result in __start not > being found.
Yes, crt0 should be linked in as a normal object (it's just a small assembly function __start which calls main(), you have the source in crt0.S).
> As you can easily see my skills with the usual C toolchains are > utterly underdeveloped. How I wished "javac *.java" would work ;-)
OK, this part does not really make sense - I suppose it's from the autoconf build of libogg. It depends a bit on what you want to do. If you want to create a libogg.a which you can use from other C programs translated with Cibyl, you can just use ar to create the archive:
ar crs libogg.a a.o b.o ...
but I suppose that you in the long run would want to access the ogg functionality from Java? Note that Cibyl always requires a ELF executable to translate, i.e., you always have to link together a "program" even if you just plan to use it as a library.
The second issue is how to call the C functions from Java. The most reliable way of doing this is through the call table. You can then provide a Java method which registers C function pointers which can later be called by Java code through the call table (invoked with the function address).
> Looks good, but as you said crt0.o should perhaps not be in LDFLAGS > (just on the command line where you invoke ld). --static should not be > needed - it's implicit.
Ah, that's good to know.
> It depends a bit on what you want to do. If > you want to create a libogg.a which you can use from other C programs > translated with Cibyl, you can just use ar to create the archive:
> ar crs libogg.a a.o b.o ...
> but I suppose that you in the long run would want to access the ogg > functionality from Java? Note that Cibyl always requires a ELF > executable to translate, i.e., you always have to link together a > "program" even if you just plan to use it as a library.
At first I only planned to compile libogg so I can satisfy the requirements of libvorbis and libtheora (there's already a Java port of libogg, which really is a very very small library).
However, now I think I should perhaps go through the whole "Java 'port' with Cibyl, complete with Java access" story for libogg - mostly to discover the interface generation process.
libogg comes with a small test executable, I guess that should qualify as "program" :-)
> The second issue is how to call the C functions from Java. The most > reliable way of doing this is through the call table. You can then > provide a Java method which registers C function pointers which can > later be called by Java code through the call table (invoked with the > function address).
Once I actually have a working libogg I'll have a look at this. I was expecting to have a convenient (set of) "wrapper" class(es) for the translated libs anyway :-)
Maik Merten <maikmer...@googlemail.com> wrote: > However, now I think I should perhaps go through the whole "Java > 'port' with Cibyl, complete with Java access" story for libogg - > mostly to discover the interface generation process.
Probably good to start small and see that the basics work - it will be easier to debug that way :-)
Note that the interface generation only goes in the C->Java direction, the other direction is less well supported.
> libogg comes with a small test executable, I guess that should > qualify as "program" :-)
Sure. What I meant was just that you need to create an "Executable" even if you just plan to use it as a library - that's the way Cibyl works.