User account creation filtered due to spam.

Bug 9076 - Call Frame Instructions are not handled correctly during unwind operation..
Summary: Call Frame Instructions are not handled correctly during unwind operation..
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: ---
Assignee: Benjamin Kosnik
URL:
Keywords:
: 8540 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-12-27 20:26 UTC by sunil.k.davasam
Modified: 2003-07-31 18:40 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sunil.k.davasam 2002-12-27 20:26:01 UTC
Based on DWARF2 Standard (6.4.2 Call Frame Instructions),

The instructions "DW_CFA_undefined" & "DW_CFA_same_value" takes a single unsigned LEB128 argument that represents a register number. While executing these instructions, The runtime library is not treating the next data as operands to the "DW_CFA_undefined" & "DW_CFA_same_value" instructions. Instead, it treats them as opcodes and executes them. Due to this, the program behaviour changes and gives segmentation fault at runtime.

  This is not a problem when I use gcc compiler and libraries. Because, gcc compiler may not be generating "DW_CFA_undefined" & "DW_CFA_same_value" instructions. But, This is an interoperability issue.
I tried to compile the testcase with intel compiler and linked with gcc libraries. I got segmentation fault.

  Fix for this problem may be simple. While handling "DW_CFA_undefined" & "DW_CFA_same_value" instructions (in file: gcc-3.2/gcc/unwind-dw2.c, function: execute_cfa_program), read the next LEB128 argument and ignore it.


    Please let me know, if it is not correct.

Thanks,
-Sunil.

Release:
gcc-3.2

Environment:
$ g++ -v
Reading specs from /local/skdavasa/gcc321/lib/gcc-lib/i386-redhat-linux/3.2.1/specs
Configured with: gcc-3.2.1/configure --prefix=/local/skdavasa/gcc321 --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2.1
cat /etc/issue
Red Hat Linux release 8.0 (Psyche)
Kernel \r on an \m
Comment 1 sunil.k.davasam 2002-12-27 20:26:01 UTC
Fix:
file: gcc-3.2/gcc/unwind-dw2.c
function: execute_cfa_program

code:
static void
execute_cfa_program (const unsigned char *insn_ptr,
		     const unsigned char *insn_end,
		     struct _Unwind_Context *context,
		     _Unwind_FrameState *fs)
{
      ....
      ....

      switch (insn)
	{
	case DW_CFA_set_loc:
	  insn_ptr = read_encoded_value (context, fs->fde_encoding,
					 insn_ptr, (_Unwind_Ptr *) &fs->pc);
	  break;

	case DW_CFA_advance_loc1:
	  fs->pc += read_1u (insn_ptr) * fs->code_align;
	  insn_ptr += 1;
	  break;
	case DW_CFA_advance_loc2:
	  fs->pc += read_2u (insn_ptr) * fs->code_align;
	  insn_ptr += 2;
	  break;
	case DW_CFA_advance_loc4:
	  fs->pc += read_4u (insn_ptr) * fs->code_align;
	  insn_ptr += 4;
	  break;

	case DW_CFA_offset_extended:
	  insn_ptr = read_uleb128 (insn_ptr, &reg);
	  insn_ptr = read_uleb128 (insn_ptr, &utmp);
	  offset = (_Unwind_Sword) utmp * fs->data_align;
	  fs->regs.reg[reg].how = REG_SAVED_OFFSET;
	  fs->regs.reg[reg].loc.offset = offset;
	  break;

	case DW_CFA_restore_extended:
	  insn_ptr = read_uleb128 (insn_ptr, &reg);
	  fs->regs.reg[reg].how = REG_UNSAVED;
	  break;

770	case DW_CFA_undefined:
771	case DW_CFA_same_value:
772	case DW_CFA_nop:
773	  break;
.....
.....
}

 Change the code in line numbers from 770 to 773 to the following..

	case DW_CFA_undefined:
	case DW_CFA_same_value:
	  insn_ptr = read_uleb128 (insn_ptr, &reg);
	  break;
	case DW_CFA_nop:
	  break;
........
Comment 2 Benjamin Kosnik 2003-01-02 14:47:46 UTC
Responsible-Changed-From-To: unassigned->rth
Responsible-Changed-Why: Hey Richard can you give me some feedback about this? This bug has a patch enclosed to unwind-dw2.c, and it seems reasonable. 
    
    Thanks,
    benjamin
Comment 3 Benjamin Kosnik 2003-01-02 14:47:46 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Seems reasonable.
Comment 4 Benjamin Kosnik 2003-01-07 12:23:22 UTC
Responsible-Changed-From-To: rth->bkoz
Responsible-Changed-Why: Ok, well whatever.
Comment 5 Benjamin Kosnik 2003-01-07 12:23:22 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: In gcc, gcc-3_3-branch, gcc-3_3-branch.
Comment 6 Benjamin Kosnik 2003-01-07 20:20:54 UTC
From: bkoz@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: libstdc++/9076
Date: 7 Jan 2003 20:20:54 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	bkoz@gcc.gnu.org	2003-01-07 12:20:54
 
 Modified files:
 	gcc            : ChangeLog unwind-dw2.c 
 
 Log message:
 	2003-01-07  Benjamin Kosnik  <bkoz@redhat.com>
 	Sunil Davasam  <sunil.k.davasam@intel.com>
 	
 	PR libstdc++/9076
 	* unwind-dw2.c (execute_cfa_program): DW_CFA_undefined,
 	DW_CFA_same_value, read next and ignore.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.16276&r2=1.16277
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unwind-dw2.c.diff?cvsroot=gcc&r1=1.23&r2=1.24
 

Comment 7 Benjamin Kosnik 2003-01-07 20:33:05 UTC
From: bkoz@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: libstdc++/9076
Date: 7 Jan 2003 20:33:05 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	bkoz@gcc.gnu.org	2003-01-07 12:33:05
 
 Modified files:
 	gcc            : ChangeLog unwind-dw2.c 
 
 Log message:
 	2003-01-07  Benjamin Kosnik  <bkoz@redhat.com>
 	Sunil Davasam  <sunil.k.davasam@intel.com>
 	
 	PR libstdc++/9076
 	* unwind-dw2.c (execute_cfa_program): DW_CFA_undefined,
 	DW_CFA_same_value, read next and ignore.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.40&r2=1.16114.2.41
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unwind-dw2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.22&r2=1.22.2.1
 

Comment 8 Benjamin Kosnik 2003-01-07 20:36:19 UTC
From: bkoz@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: libstdc++/9076
Date: 7 Jan 2003 20:36:19 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	bkoz@gcc.gnu.org	2003-01-07 12:36:19
 
 Modified files:
 	gcc            : unwind-dw2.c ChangeLog 
 
 Log message:
 	2003-01-07  Benjamin Kosnik  <bkoz@redhat.com>
 	Sunil Davasam  <sunil.k.davasam@intel.com>
 	
 	PR libstdc++/9076
 	* unwind-dw2.c (execute_cfa_program): DW_CFA_undefined,
 	DW_CFA_same_value, read next and ignore.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/unwind-dw2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.18&r2=1.18.6.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.170&r2=1.13152.2.657.2.171
Comment 9 Andrew Pinski 2003-07-31 18:40:25 UTC
*** Bug 8540 has been marked as a duplicate of this bug. ***