Lei Zhao
2012-Aug-31 20:29 UTC
[LLVMdev] Clang incompatible with GCC on Linux + ARM Cortex-A9
Hello, I played with Clang + LLVM 3.1 release on ARM Linux and suspected it is incompatible with GCC. My program works fine while compiled using GCC but will crash with Clang. Specifically, the alignment strategy of Clang confused me. I wrote a small program to print the structure layout of the following and compiled it with both Clang and GCC. struct S { pthread_mutex_t mutex; pthread_cond_t cond; int32_t int32_1; int32_t int32_2; }; The output are as following (the format is: field_address (+offset): field_name; field_size): gcc 0xbe92d588 (+0) : mutex ; 24 0xbe92d5a0 (+24): cond ; 48 0xbe92d5d0 (+72): int32_1 ; 4 0xbe92d5d4 (+76): int32_2 ; 4 clang 0xbe856580 (+0) : mutex ; 24 0xbe856598 (+24): cond ; 48 0xbe8565d0 (+80): int32_1 ; 4 0xbe8565d4 (+84): int32_2 ; 4 I don't understand the way how Clang aligned int32_1. Why does Clang not align the field to 4 bytes but pad 8 bytes before it? The problem is annoying as my program works fine with GCC but will crash with Clang. And I am unable to debug the Clang-compiled version since it is incompatible with GDB as well. I assume Clang should be compatible with GCC since they share the ABI (gnueabihf). Is this a bug in Clang+LLVM or that I did something wrong? Is there a way to get around this problem? Thank you! ---------------------------------------------------------------------------------------- Following are the testing environment details ---------------------------------------------------------------------------------------- 1. Platform: Pandaboard ES (ARM Cortex-A9 + Ubuntu/Linaro Linux 12.04)> uname -aLinux lei-desktop 3.2.0-1412-omap4 #16-Ubuntu SMP PREEMPT Tue Apr 17 19:38:42 UTC 2012 armv7l armv7l armv7l GNU/Linux 2. LLVM + Clang version 3.1 release, natively built with --enable-optimized --target armv7l-unknown-linux-gnueabihf> clang -vclang version 3.1 (branches/release_31) Target: armv7l-unknown-linux-gnueabihf Thread model: posix 3. GCC 4.6.3> gcc -vUsing built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper Target: arm-linux-gnueabihf Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf Thread model: posix gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 4. Testing program code: #define P(B, F) printf("%p (+%d): %s\n", &B->F,(unsigned int)&B->F - (unsigned int)B, #F); struct S { pthread_mutex_t mutex; pthread_cond_t cond; int32_t int32_1; int32_t int32_2; }; void print(struct S *l) { P(l, mutex); P(l, cond); P(l, int32_1); P(l, int32_2); } int main() { struct S s; print(&s); return 0; } 5. C flags: gcc: -mcpu=cortex-a9 -mfloat-abi=hard -mfpu=vfpv3 clang: -mcpu=cortex-a9 -mfloat-abi=hard -mfpu=vfpv3 -ccc-host-triple armv7l-unknown-linux-gnueabihf - Lei -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120831/084c782f/attachment.html>
Anton Korobeynikov
2012-Sep-01 07:24 UTC
[LLVMdev] Clang incompatible with GCC on Linux + ARM Cortex-A9
> 4. Testing program code:Please report a bug and attach the preprocessed source. Thanks. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Lei Zhao
2012-Sep-02 01:26 UTC
[LLVMdev] Clang incompatible with GCC on Linux + ARM Cortex-A9
I tried the most recent checkout from svn (revision 163071). It seems this bug has already been fixed. No need to report anymore:) Thank you. - Lei On Sep 1, 2012, at 3:24 AM, Anton Korobeynikov wrote:>> 4. Testing program code: > Please report a bug and attach the preprocessed source. Thanks. > > -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University