User account creation filtered due to spam.

Bug 12079 - Regression from gcc 3.2.2: incorrect code generation when -O3 optimization is used
Summary: Regression from gcc 3.2.2: incorrect code generation when -O3 optimization is...
Status: RESOLVED DUPLICATE of bug 10877
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.1
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2003-08-27 12:59 UTC by Andrew A. Peristiy
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Andrew A. Peristiy 2003-08-27 13:00:00 UTC
andr@asp:~/test/gcc331\%uname -a
Linux asp 2.4.18-27.7.x #1 Fri Mar 14 06:44:53 EST 2003 i686 unknown

andr@asp:~/test/gcc331\%gcc -v
Reading specs from /home/dev/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
Configured with: /home/dev/src/gcc-3.3.1/configure --prefix=/home/dev
--enable-threads --enable-languages=c,c++
Thread model: posix
gcc version 3.3.1

Consider program with three simple files Test.h, Test.cpp and main.cpp:
File Test.h :
#ifndef ___TEST_
#define ___TEST_

class Test
    static const char* str;


    static const char* get();



File Test.cpp :
#include "Test.h"

const char* Test::str = "SomeString";

const char* Test::get()
    return str;

File main.cpp :
#include "Test.h"
#include <iostream>

int main(  int, char** )
  const char* x = Test::get();

  std::cout << x << "\n";
  return 0;

Compile class Test from Test.cpp into shared library with -O3 optimization:

andr@asp:~/test/gcc331\%g++ -g -O3 -fPIC -shared Test.cpp -o

Then compile code from the file main.cpp that will use it:

andr@asp:~/test/gcc331\%g++ -g main.cpp -o main

Now run it:
Segmentation fault (core dumped)

Recompile shared library with -O2 optimization and run test again:

andr@asp:~/test/gcc331\%g++ -g -O2 -fPIC -shared Test.cpp -o

It works fine in this case !
With gcc 3.2.2 it works fine in both cases with -O2 and -O3 options.
Comment 1 Andrew Pinski 2003-08-27 13:37:37 UTC
What binutils version are you using?
If it is less than 2.13.1 then please upgrade as any version less than that, misassembles code.
From <*-linux*>:
As of GCC 3.3, binutils 2.13.1 or later is required for this platform.  See bug 10877 for more 

If that is your problem then this is a dup of bug 10877.
Comment 2 Andrew A. Peristiy 2003-08-28 12:07:48 UTC
I have upgraded binutils to 2.13.90 now it works! I confirm that my report
describes the same problem as in 10877.

*** This bug has been marked as a duplicate of 10877 ***