gcc produces incorrect code for __builtin_frame_address for i386 in RHEL-5

Solution Unverified - Updated -

Issue

  • gcc produces incorrect code for __builtin_frame_address for i386 in RHEL-5
  • Sample program to reproduce this:

#include <cxxabi.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

static int buf[2] = {0xdeadbeef, 0xcafedeed};
void* f1 (int* i)
{
return (void*)buf;
}

void myunwind (char** args)
{
   char* my_char_star = "xxxx";

   void** baseframe  = (void**) (__builtin_frame_address(0));
   void* pc       = baseframe[1];
   //  (uncomment next line for alternate 'fix')
   /// std::cout << "baseframe[1]: " <<  baseframe[1] << endl;
   std::cout << "       pc: " << pc << endl;
   while (true)
   {

      //  The following heals it (remove 'break')!
      //  as do -O1, no -m32, or cout of baseframe (above)

      //  (uncomment next line for alternate 'fix')
      //  if (objinfo.p3 && !strcmp (objinfo.p3, "xxxx")){ break;}

      if (my_char_star && !strcmp (my_char_star, "xxxx")){ break;}

   }

}

int main (int argc, char** argv)
{
   myunwind(argv);
}

  • Build this with the following command:

gcc -m32 sample.cc

  • Running the sample gives the output as 0 instead of the actual frame pointer address, which is incorrect.

Environment

  • Red Hat Enterprise Linux 5 (RHEL-5)
  • i386 target for gcc output

  • gcc-4.1.2-48.el5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.