This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/4999: asm code with concatenated content fails in template class member functions



>Number:         4999
>Category:       c++
>Synopsis:       asm code with concatenated content fails in template class member functions
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 03 16:16:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     sethml@ofb.net
>Release:        2.95.4
>Organization:
>Environment:
Debian unstable (sid) i386, Linux 2.2.17
>Description:
It appears that using literal string concatenation within asm code can cause corruption of the assembly generated by gcc - it contains random junk (including characters with the high bit set) rather than the assembly, and gas gives up.  Note that literal string concatenation within asm code is used extensively by libmmx:
  http://min.ecn.purdue.edu/~rfisher/Research/Libmmx/libmmx.html

Here's a chunk of code that demonstrates the problem:

  template <class X> struct test {
    static int foo(int *b1, int *b2) {
      __asm__ ("movq" " %0, %%" "mm2" : : "m" (*(long long *)b1)); 
      __asm__ ("movq" " %" "mm2" ", %" "mm3")  ; 
      __asm__ ("punpckhbw" " %" "mm0" ", %" "mm2")  ; 
      __asm__ ("punpckhbw" " %" "mm0" ", %" "mm3")  ; 
      __asm__ ("movq" " %0, %%" "mm4" : : "m" (*(long long *)b2)); 
      __asm__ ("movq" " %" "mm4" ", %" "mm5")  ; 
      __asm__ ("punpckhbw" " %" "mm0" ", %" "mm4")  ; 
      __asm__ ("punpckhbw" " %" "mm0" ", %" "mm5")  ; 
      __asm__ ("psubsw" " %" "mm4" ", %" "mm2")  ; 
      __asm__ ("psubsw" " %" "mm5" ", %" "mm3")  ; 
      __asm__ ("pmaddwd" " %" "mm2" ", %" "mm2")  ; 
      __asm__ ("pmaddwd" " %" "mm3" ", %" "mm3")  ; 
      __asm__ ("paddd" " %" "mm2" ", %" "mm1")  ; 
      __asm__ ("paddd" " %" "mm3" ", %" "mm1")  ; 
    }
  }; 
  
  int main(int argc) {
    test<int>::foo(&argc, &argc);
  }

Here's what happens when attempting to compile it, for me:

  % g++ -v --save-temps bug1.cc
  Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
  gcc version 2.95.4 20011006 (Debian prerelease)
   /usr/lib/gcc-lib/i386-linux/2.95.4/cpp0 -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ bug1.cc bug1.ii
  GNU CPP version 2.95.4 20011006 (Debian prerelease) (i386 Linux/ELF)
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3
   /usr/local/include
   /usr/lib/gcc-lib/i386-linux/2.95.4/include
   /usr/include
  End of search list.
  The following default directories have been omitted from the search path:
   /usr/lib/gcc-lib/i386-linux/2.95.4/../../../../i386-linux/include
  End of omitted list.
   /usr/lib/gcc-lib/i386-linux/2.95.4/cc1plus bug1.ii -quiet -dumpbase bug1.cc -version -o bug1.s
  GNU C++ version 2.95.4 20011006 (Debian prerelease) (i386-linux) compiled by GNU C version 2.95.4 20011006 (Debian prerelease).
   as -V -Qy -o bug1.o bug1.s
  GNU assembler version 2.11.92.0.10 (i386-linux) using BFD version 2.11.92.0.10 20011021 Debian/GNU Linux
  bug1.s: Assembler messages:
  bug1.s:46: Error: invalid character (0xffffffe7) in mnemonic
  bug1.s:47: Error: invalid character (0xffffffa0) in mnemonic
  bug1.s:48: Warning: rest of line ignored; first ignored character valued 0xb
  bug1.s:49: Warning: rest of line ignored; first ignored character is `6'
  bug1.s:50: Error: invalid character '.' in mnemonic
  bug1.s:57: Error: invalid character '>' in mnemonic

I've attached an archive with the intermediate .s file, which contains such exciting lines of assembly as "pç8ç&", "e.t.foo__t4test1ZiPiT1", and "int>::foo(int *, int *)".  Clearly there's some random memory corruption going on.

See also bug report titled "volatile asm code fails in template class member functions".
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-gzip-compressed; name="bug1.tgz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug1.tgz"

H4sIAJEUDDwAA+1X/W7iRhDnz7P7EiuniSAy7n45UO50ursciSLRNOqHVPUfyzYb4sY2LjYJ1yrv
0Efo27Vv0c6uDTbEHFUqrrqeB+Edz+58/WbZWbz5hHzR2i9hzHGvZ8NIe0yNwOGeGgtq4R7HDBPS
w6QFA+3xFrL3HJeieZq5M4RaqchuonD7ul3zHyl5sv7yYaV784EJxicnfFv9Gbd5pf6wFwhlFLcQ
3ltEFfrE669Z10EoNENtAd83dM26E7M0mMaagYmFiaFPfJ86/jRKYOHYGuhWJhYZrHPDYBIjrluT
cOqFKHKDGKTZu0Ro6sV8dT2P/QxM6fIVFEdnb8hA15J5ehOiQ+ElIDo9u8Agi6Z3UpQmZimXa9M5
mP68b8qpXEpB6o7HIO0WYi0Uboj6banZAZG7KH1I/v3TyigDo74bhuh6OnWcjGcizciPwVXwHVl6
IyeFt8V0lqsWtn6KEmSNKOSe0AIT0+yBXRkp+L4TujYTmUx/SCQK10JmZqXBL0uklKyrELRSoTDT
rEk8t8Igvp3GvrAy63FkpuEuDPNVMptOvCBLKyXRrHvh3mp1yRQFqrFWluvxZF48WlM8vqV49lK+
DrwSEbqSjRf6weurK7D7x9GzPnx/g+9fQLr2+59Hz0507TNdg2c9AjKcOPFvb7x7dBhF2JRPXiu1
QQqbKVUirkRQsvwTxNnLwQDMt4FDxyZSQwemDi6/dlR4eZH5kmGPq80lRuxxyWleclqWvAZ7taJb
k2BlP4gb53rmRgLKfl8tu+OcffP6q6HzZnh+cek40g/33mVCs0aj04shAfffyrGcwAsMfMGSkq2X
9vyS75dsRcpr2X5/3dzqvBgNl+HAobqM0izE3SLaahZnb/Ms5FhNTwm6G/lX5uG4qb4p47msEu1y
Wh5Em/OiNvO+XfJ0qzHpTNosF4xL1t6qxnK1ShC0EgXB60AuESmAlK9mIe4W+GwAyQog2SaQ7L1A
0jUgaXcpq0+Cb87/GyDtHBG+Fch1PNg6HqzAgxV4yF9uMBZxphnnp6cD1D6//L6DqPWlbXFEMVxB
4LKC2m+FF7gxSmZiJuAHnYqOof/XvXofVN7/fH9fPnbc/4jN2Or+RzCT9z/OeHP/+xCUiSgJ3Uyg
F37opin64SVKs9ncz5DsQuhXHcG7mwW+6omrFumRokl6tKMWIeQ4bho5Dmob0ON/NpCBDmXnPQQO
Wq2BBvAxIgO1j9vhNJ4g9TjueKTTeb7NwFLXMAueGR2ENpevun2pgys69Ak6tX5q8uLb86K78uIV
f/YTYuRP0Kn3o+5F9YHVg7ehYO+sUAR36PtxfU3rXWxqsJ0+QGGLB/IP1rO69Q/6w3Ndlxtd3s3V
1ndnEz/f8vIH8qK8Oh7JGROpASr/8HG0i/L8D4J9+dh5/ttk8/8/t1lz/n8IOkAElX/+m27QdIOm
G3y63aChhhpqqKGGGmqooYYaaqihhhr6P9LfzaY9LgAoAAA=


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]