简体   繁体   English

ndk-build NDK_TOOLCHAIN_VERSION 4.8与clang

[英]ndk-build NDK_TOOLCHAIN_VERSION 4.8 vs clang

Some time ago I developed a jni wrapper for the C libspeex audio codec. 前一段时间,我为C libspeex音频编解码器开发了jni包装器。 Recently I had some problem in compiling and running this with the ndk r10e, since the audio encode function crashed in runtime. 最近,我在使用ndk r10e进行编译和运行时遇到了一些问题,因为音频编码功能在运行时崩溃了。

Finally I found that when I compile with 最终我发现,当我用

NDK_TOOLCHAIN_VERSION:=4.8

the native code runs while with 本机代码与

NDK_TOOLCHAIN_VERSION:=clang

it crashes. 它崩溃了。 I wonder about the difference between the two toolchains. 我想知道这两个工具链之间的区别。

The logcat of the crash: 崩溃的日志:

11-02 14:26:33.642 1908-1908/com.ermes.intau D/dalvikvm: GC_FOR_ALLOC freed 1248K, 20% free 34140K/42456K, paused 102ms, total 102ms
11-02 14:26:33.642 1908-2514/com.ermes.intau A/libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 2514 (Thread-103909)
11-02 14:26:33.742 1908-1908/com.ermes.intau D/dalvikvm: GC_FOR_ALLOC freed 6K, 18% free 34883K/42456K, paused 89ms, total 89ms

gcc and clang are completely different C compilers. gcc和clang是完全不同的C编译器。 They have no common code. 他们没有通用代码。

Of course they aren't developed in a vacuum. 当然,它们并不是在真空中开发的。 The developers of both compilers do compete with each other to generate the best / fastest machine code. 两种编译器的开发人员都相互竞争以生成最佳/最快的机器代码。 While the optimisations they both perform may be based on the same ideas, they both have different edge cases that will be compiled differently. 虽然它们都执行的优化可能基于相同的思想,但是它们都有不同的边缘情况,这些情况会以不同的方式进行编译。

With clang being the newest compiler to be developed, they do try to compile other open source projects that have a history of being compiled by gcc. 随着clang是要开发的最新编译器,他们确实尝试编译其他具有gcc编译历史的开源项目。 With either clang or the open source project being changed whenever bugs are found. 只要发现错误,就可以更改clang或开源项目。

The C language standard also leaves a lot of behaviour undefined. C语言标准还留下了许多不确定的行为。 Things like dividing by zero, dereferencing a NULL pointer, signed integer overflows, alignment of stack allocations... Both compilers will exploit these edge cases to generate faster code. 诸如除以零,取消引用NULL指针,有符号整数溢出,对齐堆栈分配之类的事情……两个编译器都将利用这些边缘情况生成更快的代码。 If a block of code "might" do something weird, the compiler can assume that the developer knows what they are doing and have handled these cases elsewhere. 如果代码块“可能”做一些奇怪的事情,则编译器可以假定开发人员知道他们在做什么,并且已经在其他地方处理了这些情况。 http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM