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]

libstdc++/9076: Call Frame Instructions are not handled correctly during unwind operation..


>Number:         9076
>Category:       libstdc++
>Synopsis:       Call Frame Instructions are not handled correctly during unwind operation..
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 27 20:26:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     sunil.k.davasam@intel.com
>Release:        gcc-3.2
>Organization:
>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
>Description:
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.
>How-To-Repeat:

>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;
........

>Release-Note:
>Audit-Trail:
>Unformatted:


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