ncbi / sra-tools

SRA Tools
Other
1.12k stars 246 forks source link

gcc version 7.3.1 20180712 Target: aarch64-redhat-linux fails to build tools/copycat/ccsra.c #504

Open kgmoore opened 3 years ago

kgmoore commented 3 years ago

In several places in this file GCC for ARM has compiler errors, but GCC for x86 compiles without error.

/home/ec2-user/ncbi/sra-tools/tools/copycat/ccsra.c:616:22: error: used struct type value where scalar is required
     path_size = args ?
                      ^
/home/ec2-user/ncbi/sra-tools/tools/copycat/ccsra.c: In function ‘CCNodeSraDirFileContiguous’:

The copycat tool won't attempt to build unless libmagic is installed (via the package file-devel). If you don't have that installed, you won't hit this error.

This code seems to be relying on undefined compiler behavior that is different with gcc x86 and gcc ARM.

The code is being clever and using the ternary operator to route between the vsnprintf and snprintf functions.

static
rc_t CC CCNodeSraDirFilePhysicalSize (const CCNodeSraDir *self,
                                      uint64_t *size,
                                      const char *path_fmt,
                                      va_list args)
{
    char path[4096];
    int path_size;

    assert (self != NULL);
    assert (size != NULL);
    assert (path_fmt != NULL);

    path_size = args ?
        vsnprintf ( path, sizeof path, path_fmt, args ) :
        snprintf  ( path, sizeof path, "%s", path_fmt );

I think what's happening here is that in the x86 toolchain this aliases to a pointer, which can have zeroness. In the ARM toolchain, va_list seems to alias to a real struct, and therefore fails scalar tests.

It's not clear what this code is trying to do. It seems to be a safety valve where if no arguments are supplied, then the format string is emitted with the format terms still intact. In my testing I was not able to trigger this condition (i.e. vsnprintf was always invoked.)

I've attached a main_error.c which isolates this issue. It compiles and runs on a t3 (x86) instance, and fails to compile on a t4g (ARM) instance.

x86 GCC

[ec2-user@ip-172-31-61-210 ~]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-libsanitizer --enable-gnu-indirect-function --enable-libcilkrts --enable-libatomic --enable-libquadmath --enable-libitm --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180712 (Red Hat 7.3.1-12) (GCC)

ARM GCC

[ec2-user@ip-172-31-4-207 repro]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/7/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --disable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-libsanitizer --enable-gnu-indirect-function --disable-libcilkrts --enable-libatomic --disable-libquadmath --enable-libitm --build=aarch64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180712 (Red Hat 7.3.1-12) (GCC)

main_error.c.txt

tongzhouxu commented 3 years ago

I had the same issue while compiling ccsra.o. I am using gcc (Ubuntu 10.3.0-1ubuntu1) with a aarch64.

hyacz commented 2 years ago

I also got the same error, #507 really helped me, thanks!