[LLVMbugs] [Bug 11911] New: gmp 5.0.3 on x86_64 Linux compiled with clang in 32-bit mode fails checks due to bug in clang assembler

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 2 14:40:36 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=11911

             Bug #: 11911
           Summary: gmp 5.0.3 on x86_64 Linux compiled with clang in
                    32-bit mode fails checks due to bug in clang assembler
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: neunhoef at mcs.st-and.ac.uk
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 7987
  --> http://llvm.org/bugs/attachment.cgi?id=7987
Result of m4 translated assembler source, this is fed into clang.

I work on Ubuntu Linux 11.04 on x86_64, I have used both clang 3.0 and clang
svn-head to compile gmp-5.0.3 from
  ftp://ftp.gmplib.org/pub/gmp-5.0.3/gmp-5.0.3.tar.bz2
in the following way:
  tar xjvf gmp-5.0.3.tar.bz2
  cd gmp-5.0.3
  ./configure ABI=32 CC=clang CFLAGS="-m32"
  make
  make check
The result is that the checks tests/mpz/t-hamdist and tests/mpz/t-popcount fail
with segfaults. 

I traced it down to the following problem:

The critical function is __gmpn_popcount, which is coded in assembler for x86.
The original source (for the CPU "Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz" 
I am using) is in
  gmp-5.0.3/mpn/x86/pentium4/sse2/popcount.asm
which is first translated by the m4 macro processor to the file
  tmp-popcount.s
which I attach to this bug report. This is then (for building the shared
library libgmp.so) in turn assembled by clang by the following command:

   clang -c -DHAVE_CONFIG_H -I. -I.. -D__GMP_WITHIN_GMP -I..
-DOPERATION_popcount -m32 -O0 -g -Wa,--noexecstack tmp-popcount.s 
-fPIC -DPIC -o .libs/popcount.o

Note in particular the -fPIC! The two following assembler lines (close to the
top of the attaced file) are then processed in a way such that the access to
the data table with label "cnsts" in the .rodata section (same source file)
does not work and indeed produces the segfault in the end:

        addl    $_GLOBAL_OFFSET_TABLE_, %ebx
        movl    cnsts at GOT(%ebx), %ebx

I do not understand the full details of the PIC-business for shared libraries
but it seems that the global offset table is not properly accessed by the code
produced.

Note that if I compare the outputs of clang and gcc on this assembler source
the single difference is the offset in the movl command. The file assembled by
gcc works, even if I compile the complete rest of gmp with clang. The problem
seems to occur only when using the shared library libgmp.so and not with static
linking.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list