From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jim Wilson To: binutils@sourceware.cygnus.com Cc: wilson@cygnus.com, rth@cygnus.com Subject: patch for gas/dwarf2dbg.c, core dump and corrupted .debug_line section Date: Wed, 25 Aug 1999 20:43:00 -0000 Message-id: <199908260343.UAA26025@ada.cygnus.com.cygnus.com> X-SW-Source: 1999-08/msg00143.html This fixes 4 problems I noticed while trying to use this code from gcc. 1) The comments in get_filenum do not match the code. The code is correct. 2) get_filenum performs an out-of-bounds array access if filenum is 0, which makes last == -1. 3) get_filenum does not update ls.last_filename when creating a new filetable entry. 4) dwarf2_gen_line_info saves seg/subseg info after it has already been clobbered by a subseg_new call. This causes gas to accidentally emit code into the .debug_line section. Wed Aug 25 20:20:33 1999 Jim Wilson * dwarf2dbg.c (out_end_sequence): Correct comments. Set last to ls.last_filename if last is less than zero. Set ls.last_filename when allocating new entry. (dwarf2_gen_line_info): Save seg and subseg info before subseg_new call. Index: dwarf2dbg.c =================================================================== RCS file: /cvs/cvsfiles/devo/gas/dwarf2dbg.c,v retrieving revision 1.7 diff -p -r1.7 dwarf2dbg.c *** dwarf2dbg.c 1999/07/23 22:12:34 1.7 --- dwarf2dbg.c 1999/08/26 03:34:48 *************** out_end_sequence () *** 359,365 **** /* Look up a filenumber either by filename or by filenumber. If both a filenumber and a filename are specified, lookup by filename takes precedence. If the filename cannot be found, it is added to the ! filetable the filenumber for the new entry is returned. */ static int get_filenum (filenum, file) int filenum; --- 359,365 ---- /* Look up a filenumber either by filename or by filenumber. If both a filenumber and a filename are specified, lookup by filename takes precedence. If the filename cannot be found, it is added to the ! filetable and the filenumber for the new entry is returned. */ static int get_filenum (filenum, file) int filenum; *************** get_filenum (filenum, file) *** 368,377 **** int i, last = filenum - 1; char char0 = file[0]; ! if (last >= ls.num_filenames) last = ls.last_filename; ! /* do a quick check against the previously used filename: */ if (ls.num_filenames > 0 && ls.file[last].name[0] == char0 && strcmp (ls.file[last].name + 1, file + 1) == 0) return last + 1; --- 368,379 ---- int i, last = filenum - 1; char char0 = file[0]; ! /* If filenum is out of range of the filename table, then try using the ! table entry returned from the previous call. */ ! if (last >= ls.num_filenames || last < 0) last = ls.last_filename; ! /* Do a quick check against the specified or previously used filenum. */ if (ls.num_filenames > 0 && ls.file[last].name[0] == char0 && strcmp (ls.file[last].name + 1, file + 1) == 0) return last + 1; *************** get_filenum (filenum, file) *** 395,400 **** --- 397,403 ---- } ls.file[ls.num_filenames].dir = 0; ls.file[ls.num_filenames].name = file; + ls.last_filename = ls.num_filenames; return ++ls.num_filenames; } *************** dwarf2_gen_line_info (addr, l) *** 425,430 **** --- 428,438 ---- else return; /* no filename, no filnum => no play */ + /* Must save these before the subseg_new call, as that call will change + them. */ + saved_seg = now_seg; + saved_subseg = now_subseg; + if (!ls.line_seg) { #ifdef BFD_ASSEMBLER *************** dwarf2_gen_line_info (addr, l) *** 445,452 **** #endif } - saved_seg = now_seg; - saved_subseg = now_subseg; subseg_set (ls.line_seg, DL_BODY); if (ls.text_seg != saved_seg || ls.text_subseg != saved_subseg) --- 453,458 ----