Failure to compile with r7

864 views
Skip to first unread message

kugel

unread,
Dec 30, 2011, 4:36:28 AM12/30/11
to android-ndk
Hello,

I'm from the Rockbox[1] project. Our code base fails to compile with
the r7 of the NDK. The error is:

> LD librockbox.so
> /home/kugel/rockbox-client/build-android22/apps/replaygain.o: In
> function `fp_atof':
> replaygain.c:(.text.fp_atof+0x138): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/fixedpoint.o: In
> function `fp_factor':
> fixedpoint.c:(.text.fp_factor+0x40): undefined reference to
> `__aeabi_ldivmod'
> fixedpoint.c:(.text.fp_factor+0x240): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/dsp.o: In function
> `resampler_new_delta':
> dsp.c:(.text.resampler_new_delta+0x20): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/dsp.o: In function
> `dsp_set_compressor':
> dsp.c:(.text.dsp_set_compressor+0x14c): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/dsp.o:dsp.c:(.text.dsp_set_compressor+0x19c):
> more undefined references to `__aeabi_ldivmod' follow
> /home/kugel/rockbox-client/build-android22/apps/metadata/asf.o: In
> function `get_asf_metadata':
> asf.c:(.text.get_asf_metadata+0x214): undefined reference to
> `__aeabi_uldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/flac.o: In
> function `get_flac_metadata':
> flac.c:(.text.get_flac_metadata+0x138): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/monkeys.o: In
> function `get_monkeys_metadata':
> monkeys.c:(.text.get_monkeys_metadata+0x134): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/mp4.o: In
> function `read_mp4_container':
> mp4.c:(.text.read_mp4_container+0xdd4): undefined reference to
> `__aeabi_uldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/mp4.o: In
> function `get_mp4_metadata':
> mp4.c:(.text.get_mp4_metadata+0x94): undefined reference to
> `__aeabi_ldivmod'
> mp4.c:(.text.get_mp4_metadata+0xc0): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/mpc.o: In
> function `get_musepack_metadata':
> mpc.c:(.text.get_musepack_metadata+0x338): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/ogg.o: In
> function `get_ogg_metadata':
> ogg.c:(.text.get_ogg_metadata+0x280): undefined reference to
> `__aeabi_ldivmod'
> ogg.c:(.text.get_ogg_metadata+0x2bc): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/wave.o: In
> function `read_header':
> wave.c:(.text.read_header+0x7ac): undefined reference to
> `__aeabi_uldivmod'
> wave.c:(.text.read_header+0x7f8): undefined reference to
> `__aeabi_uldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/wavpack.o: In
> function `get_wavpack_metadata':
> wavpack.c:(.text.get_wavpack_metadata+0x2f8): undefined reference to
> `__aeabi_ldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/smaf.o: In
> function `set_length':
> smaf.c:(.text.set_length+0x54): undefined reference to `__aeabi_uldivmod'
> /home/kugel/rockbox-client/build-android22/apps/metadata/tta.o: In
> function `get_tta_metadata':
> tta.c:(.text.get_tta_metadata+0x160): undefined reference to
> `__aeabi_uldivmod'
> /home/kugel/rockbox-client/build-android22/firmware/libfirmware.a(support-arm.o):
> In function `__div0_wrap_s':
> (.text+0x4): undefined reference to `__div0'
> /home/kugel/rockbox-client/build-android22/firmware/libfirmware.a(support-arm.o):
> In function `__div0_wrap':
> (.text+0xc): undefined reference to `__div0'
> collect2: ld returned 1 exit status
> make: *** [/home/kugel/rockbox-client/build-android22/librockbox.so]
> Fehler 1


I found we can work work around (it at least links, haven't checked if
it actually runs too) by adding -lgcc to the linker.

We run on a couple of platforms and we never needed to link libgcc
explicitely. And didn't need to with r6 or earlier. Is that expected
with the new toolchain?

Best regards.

Thomas Martitz

unread,
Dec 29, 2011, 6:52:34 AM12/29/11
to andro...@googlegroups.com

David Turner

unread,
Dec 31, 2011, 5:47:04 AM12/31/11
to andro...@googlegroups.com
All these functions are part of libgcc.a, and adding -lgcc to your link command will solve the issue.

It's a long story, but in a nutshell, the reason why this wasn't an issue before is because these specific symbols were also exported by the NDK libc.so, and this is no longer the case in r7.

The reason for this change is to prevent binary breakages when the platform is built with a newer toolchain (e.g. switch from GCC 4.21 to 4.4.3, or to 4.6.2). Whenever we do this, the content of libgcc.a changes slightly, and the generated system code will export a different set of libgcc symbols. This typically results in random NDK binaries breaking (i.e. refusing to load) and is very painful to fix.

By refusing to expose these symbols from the NDK system libraries that are used to generate your binaries, we ensure that every libgcc symbol that it requires is statically linked to it. This avoids any binary compatibility issue (and also provides for slightly better performance).

Right now, it means you need to explicitely add -lgcc to your link command line though. I'm not sure I understand why gcc doesn't do that by default on ARM though. I tried to find a way to enable that automatically, but didn't find it (though I admit didn't spend a lot of time on it).

If you use ndk-build, all of this is handled for you automatically, so you don't need to worry about this.



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Thomas Martitz

unread,
Jan 2, 2012, 10:23:08 AM1/2/12
to andro...@googlegroups.com
Am 31.12.2011 11:47, schrieb David Turner:
> All these functions are part of libgcc.a, and adding -lgcc to your
> link command will solve the issue.
>
>

Thanks. Indeed that fixes it.


>
> Right now, it means you need to explicitely add -lgcc to your link
> command line though. I'm not sure I understand why gcc doesn't do that
> by default on ARM though. I tried to find a way to enable that
> automatically, but didn't find it (though I admit didn't spend a lot
> of time on it).

I had a deeper look at our gcc cmdline, and we actually pass -nostdlib
(by accident) so that would explain the need for -lgcc. We also have -lc
explicitely so it worked before r7.

>
> If you use ndk-build, all of this is handled for you automatically, so
> you don't need to worry about this.
>

We use our own build system which is very flexible because we have
(historically) lots of targets, native and hosted. Adjusting our build
system was way less effort than wrapping our huge code base around
ndk-build. Anyway, after resolving this error in our cmdline we can
build Rockbox again.

Best regards.

Reply all
Reply to author
Forward
0 new messages