dwarf2out: Always emit required 0 entries for DWARF 5 in *.debug_line [PR98796]

When GCC is emitting .debug_line or .gnu.debuglto_.debug_line section by
itself (happens either with too old or non-GNU assembler, with
-gno-as-loc-support or with -flto) on empty translation units, it violates
the DWARF 5 requirements.
The standard says:
"The first entry is the current directory of the compilation."
and a few lines later:
"The first entry in the sequence is the primary source file whose file name
exactly matches that given in the DW_AT_name attribute in the compilation
unit debugging information entry."
GCC emits 4 zeros (directory entry format count, directories count,
filename entry format count and filename count), which would be ok if the
spec said The first entry may be rather than is.

I had a brief look at whether I could just fall through into the rest of the
function, but there are too many assumptions that there is at least one
normal file that it can't be done that way easily.

So this patch instead extends the early out code to emit the required
minimum, which is 15 bytes more than we used to emit before.

2021-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR debug/98796
	* dwarf2out.c (output_file_names): For -gdwarf-5, if there are no
	filenames to emit, still emit the required 0 index directory and
	filename entries that match DW_AT_comp_dir and DW_AT_name of the
	compilation unit.
This commit is contained in:
Jakub Jelinek 2021-01-22 22:37:36 +01:00
parent 32a93eac7a
commit b485fa167e

View File

@ -12252,10 +12252,50 @@ output_file_names (void)
{
if (dwarf_version >= 5)
{
dw2_asm_output_data (1, 0, "Directory entry format count");
dw2_asm_output_data_uleb128 (0, "Directories count");
dw2_asm_output_data (1, 0, "File name entry format count");
dw2_asm_output_data_uleb128 (0, "File names count");
const char *comp_dir = comp_dir_string ();
if (comp_dir == NULL)
comp_dir = "";
dw2_asm_output_data (1, 1, "Directory entry format count");
enum dwarf_form str_form = DW_FORM_string;
if (DWARF5_USE_DEBUG_LINE_STR)
str_form = DW_FORM_line_strp;
dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
dw2_asm_output_data_uleb128 (str_form, "%s",
get_DW_FORM_name (str_form));
dw2_asm_output_data_uleb128 (1, "Directories count");
if (str_form == DW_FORM_string)
dw2_asm_output_nstring (comp_dir, -1, "Directory Entry: %#x", 0);
else
output_line_string (str_form, comp_dir, "Directory Entry", 0);
const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name);
if (filename0 == NULL)
filename0 = "";
#ifdef VMS_DEBUGGING_INFO
dw2_asm_output_data (1, 4, "File name entry format count");
#else
dw2_asm_output_data (1, 2, "File name entry format count");
#endif
dw2_asm_output_data_uleb128 (DW_LNCT_path, "DW_LNCT_path");
dw2_asm_output_data_uleb128 (str_form, "%s",
get_DW_FORM_name (str_form));
dw2_asm_output_data_uleb128 (DW_LNCT_directory_index,
"DW_LNCT_directory_index");
dw2_asm_output_data_uleb128 (DW_FORM_data1, "%s",
get_DW_FORM_name (DW_FORM_data1));
#ifdef VMS_DEBUGGING_INFO
dw2_asm_output_data_uleb128 (DW_LNCT_timestamp, "DW_LNCT_timestamp");
dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
dw2_asm_output_data_uleb128 (DW_LNCT_size, "DW_LNCT_size");
dw2_asm_output_data_uleb128 (DW_FORM_udata, "DW_FORM_udata");
#endif
dw2_asm_output_data_uleb128 (1, "File names count");
output_line_string (str_form, filename0, "File Entry", 0);
dw2_asm_output_data (1, 0, NULL);
#ifdef VMS_DEBUGGING_INFO
dw2_asm_output_data_uleb128 (0, NULL);
dw2_asm_output_data_uleb128 (0, NULL);
#endif
}
else
{