[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#701082: gcc-4.7: gcc generates incorrect code with -O2 compiling libffi example



Package: gcc-4.7
Version: 4.7.2-5
Severity: normal

Dear Maintainer,
*** Please consider answering these questions, where appropriate ***

   * What led up to the situation?
I'm using libffi5
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
I noticed a problem with the simple libffi "call puts" example.
   * What was the outcome of this action?
With -O0 it works, with -O2 the second "This is cool!" ffi_call segfaults.
   * What outcome did you expect instead?
I expected two messages.

Also, I mixed in some debugging messages in another version of the file and
sometimes (depending on their location) I would see both messages.
I don't know if it worked because of the changes or if it was crashing at
random.
This was with -O0.

I shrunk the code down to the libffi5 sample, but that always works with -O0,
so I don't think they're the same probllem.

Reportbug states that there's a newer version in experimental - 4.7.2-21, I
guess it hasn't been mirrored to where I am (Ireland) yet - I'm using the
newest version.
Also, gcc-4.8 is broken (missing deps) in experimental.



-- System Information:
Debian Release: 7.0
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.2.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages gcc-4.7 depends on:
ii  binutils      2.22-7.1
ii  cpp-4.7       4.7.2-5
ii  gcc-4.7-base  4.7.2-5
ii  libc6         2.13-38
ii  libgcc1       1:4.7.2-5
ii  libgmp10      2:5.0.5+dfsg-2
ii  libgomp1      4.7.2-5
ii  libitm1       4.7.2-5
ii  libmpc2       0.9-4
ii  libmpfr4      3.1.1-1
ii  libquadmath0  4.7.2-5
ii  zlib1g        1:1.2.7.dfsg-13

Versions of packages gcc-4.7 recommends:
ii  libc6-dev  2.13-38

Versions of packages gcc-4.7 suggests:
pn  binutils-gold        <none>
ii  gcc-4.7-doc          4.7.2-2
pn  gcc-4.7-locales      <none>
ii  gcc-4.7-multilib     4.7.2-5
ii  libcloog-ppl0        0.15.11-5
ii  libgcc1-dbg          1:4.7.2-5
pn  libgomp1-dbg         <none>
pn  libitm1-dbg          <none>
pn  libmudflap0-4.7-dev  <none>
pn  libmudflap0-dbg      <none>
pn  libppl-c2            <none>
pn  libppl7              <none>
pn  libquadmath0-dbg     <none>

-- no debconf information
#include <stdio.h>
      #include <ffi.h>


      int main()
      {
        ffi_cif cif;
        ffi_type *args[1];
        void *values[1];
        char *s;
        int rc;


        /* Initialize the argument info vectors */
        args[0] = &ffi_type_pointer;
        values[0] = &s;


        /* Initialize the cif */
        if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
                       &ffi_type_uint, args) == FFI_OK)
          {
            s = "Hello World!";
            ffi_call(&cif, puts, &rc, values);
            /* rc now holds the result of the call to puts */


            /* values holds a pointer to the function's arg, so to
               call puts() again all we need to do is change the
               value of s */
            s = "This is cool!";
            ffi_call(&cif, puts, &rc, values);
          }


        return 0;
      }

Reply to: