aboutsummaryrefslogtreecommitdiff
path: root/gas/dwarf2dbg.c
AgeCommit message (Collapse)AuthorFilesLines
2022-06-14gas dwarf2dbg.c tidyAlan Modra1-35/+75
Make it a little more obvious that remap_debug_filename returns an allocated string (that should be freed) by returning a char * rather than const char *. Free a few missed cases in dwarf2dbg.c, and free other memory allocated in dwarf2dbg.c. Also remove static initialisation of variables and initialise in dwarf2_init instead, in order to ensure gas state is saner for oss-fuzz. * remap.c (remap_debug_filename): Remove const from return. * as.h (remap_debug_filename): Update prototype. * config/obj-elf.c (obj_elf_ident): Simplify free of remap_debug_filename output. * stabs.c (stabs_generate_asm_file): Likewise. * dwarf2dbg.c (dirs, dirs_in_use, dirs_allocated, current): Don't initialise statically.. (dwarf2_init): ..do so here, along with most other static vars. (assign_file_to_slot): Don't set files_allocated until we succeed in allocating memory. (purge_generated_debug): Add bool param, free more stuff if true. (dwarf2_directive_filename): Adjust purge_generated_debug call. (process_entries): Don't free line_entry here.. (dwarf2_cleanup): ..do so here instead, new function. (dwarf2_finish): Call dwarf2_cleanup. When chaining together subseg line entries, unhook entries from old subseg list. (dwarf2_directive_loc): Free remap_debug_filename string. (out_dir_and_file_list): Likewise. (out_debug_str): Likewise.
2022-06-02asan: heap buffer overflow in dwarf2_directive_filenameAlan Modra1-3/+5
Seen with .file 4294967289 "xxx.c" * dwarf2dbg.c (assign_file_to_slot): Catch more cases of integer overflow. Make param i an unsigned int.
2022-04-12gas: drop .appfile and .applineJan Beulich1-2/+2
These were used originally to represent "# <line> <file>" constructs inserted by (typically) compilers when pre-processing. Quite some time ago they were replaced by .linefile though. Since the original directives were never documented, we ought to be able to remove support for them. As a result in a number of case function parameter aren't used anymore and can hence be dropped.
2022-04-07gas/Dwarf: record functionsJan Beulich1-7/+149
To help tools like addr2line looking up function names, in particular when dealing with e.g. PE/COFF binaries (linked from ELF objects), where there's no ELF symbol table to fall back to, emit minimalistic information for functions marked as such and having their size specified. Notes regarding the restriction to (pure) ELF: - I realize this is a layering violation; I don't see how to deal with that in a better way. - S_GET_SIZE(), when OBJ_MAYBE_ELF is defined, looks wrong: Unlike S_SET_SIZE() it does not check whether the hook is NULL. - symbol_get_obj(), when OBJ_MAYBE_ELF is defined, looks unusable, as its return type can only ever be one object format's type (and this may then not be ELF's). The new testcases are limited to x86 because I wanted to include the case where function size can't be determined yet at the time Dwarf2 info is generated. As .nops gains support by further targets, they could also be added here then (with, as necessary, expecations suitably relaxed to cover for insn size differences).
2022-03-23gas/Dwarf5: re-use file 0 line string table entry when faking file 0Jan Beulich1-2/+10
No need to emit the same string a 2nd time for file 1 in this case.
2022-03-23gas/Dwarf5: adjust .debug_line file 0 checkingJan Beulich1-11/+10
First of all when a table entry has a NULL filename, the two inner if()s are better done the other way around: The 2nd doesn't depend on what the first does. This then renders redundant half of the conditions of the other if() and clarifies that subsequently only entry 0 is dealt with (indicating that part of the comment was wrong). Finally for there to be a usable name in slot 1, files_in_use needs to be larger than 1 and slot 1's (rather than slot 0's) name needs to be non-NULL.
2022-03-23gas/Dwarf5: drop dead codeJan Beulich1-11/+3
Commit 3417bfca676f ("GAS: DWARF-5: Ensure that the 0'th entry in the directory table contains the current... ") added a "dwarf_level < 5" check to out_dir_and_file_list(). This rendered dead that branch of the construct, due to the enclosing if()'s "DWARF2_LINE_VERSION >= 5". Delete that code as well as the corresponding part of the comment. While there also drop a redundant "dirs != NULL": "dirs" will always be non-NULL when dirs_in_use is not zero.
2022-03-09Constant fold view increment expressionsAlan Modra1-4/+13
The idea here is to replace expressions like v + 1 + 1 + 1 with v + 3. * dwarf2dbg.c (set_or_check_view): Remove useless assertion. Resolve multiple view increments. * testsuite/gas/elf/dwarf2-18.d: Don't xfail mep.
2022-01-02Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The result of running etc/update-copyright.py --this-year, fixing all the files whose mode is changed by the script, plus a build with --enable-maintainer-mode --enable-cgen-maint=yes, then checking out */po/*.pot which we don't update frequently. The copy of cgen was with commit d1dd5fcc38ead reverted as that commit breaks building of bfp opcodes files.
2021-11-26gas: Update commit 4780e5e4933H.J. Lu1-1/+1
Update commit 4780e5e4933a2497a5aecc4ceabbbb8e82aaf822 Author: Tom de Vries <tdevries@suse.de> Date: Fri Nov 26 09:59:45 2021 +0100 [gas] Fix file 0 dir with -gdwarf-5 1. Replace i with j in for (j = 0; i < NUM_MD5_BYTES; ++j) 2. Pass -W to readelf to force CU: in output due to: if (do_wide || strlen (directory) < 76) printf (_("CU: %s/%s:\n"), directory, file_table[0].name); else printf ("%s:\n", file_table[0].name); PR gas/28629 * dwarf2dbg.c (out_dir_and_file_list): Fix a typo in commit 4780e5e4933. * testsuite/gas/elf/dwarf-5-nop-for-line-table.d: Pass -W to readelf.
2021-11-26[gas] Fix file 0 dir with -gdwarf-5Tom de Vries1-2/+8
In out_dir_and_file_list, if file 0 is copied from file 1, only the filename is copied, and the dir and md5 fields are left to their default values. Fix this by adding the copy of the dir and md5 fields. gas/ChangeLog: 2021-11-26 Tom de Vries <tdevries@suse.de> PR 28629 * dwarf2dbg.c (out_dir_and_file_list): When copying file 1 to file 0, also copy dir and md5 fields. * testsuite/gas/i386/dwarf5-line-4.d: Adjust expected output.
2021-11-15Deal with full path in .file 0 directiveEric Botcazou1-13/+31
Gas uses the directory part, if present, of the .file 0 directive to set entry 0 of the directory table in DWARF 5, which represents the "current directory". Now Gas also uses the file part of the same directive to set entry 0 of the file table, which represents the "current compilation file". But the latter need not be located in the former so GCC will use a full path in the file part when it is passed a full path: gcc -c /full/path/test.c -save-temps yields: .file 0 "/current/directory" "/full/path/test.c" in the assembly file and: The Directory Table (offset 0x22, lines 2, columns 1): Entry Name 0 (indirect line string, offset: 0x25): /current/directory 1 (indirect line string, offset: 0x38): /full/path The File Name Table (offset 0x30, lines 2, columns 2): Entry Dir Name 0 0 (indirect line string, offset: 0x43): /full/path/test.c in the object file. Note the full path and the questionable Dir value in the 0 entry of the file table.
2021-09-20Fix allocate_filenum last dir/file checksAlan Modra1-3/+3
* dwarf2dbg.c (allocate_filenum) Correct use of last_used_dir_len.
2021-09-20Re: PR28149, debug info with wrong file associationAlan Modra1-13/+23
Fixes segfaults when building aarch64-linux kernel, due to only doing part of the work necessary when allocating file numbers late. I'd missed looping over subsegments, which resulted in some u.filename entries left around and later interpreted as u.view. PR 28149 * dwarf2dbg.c (purge_generated_debug): Iterate over subsegs too. (dwarf2_finish): Call do_allocate_filenum for all subsegs too, in a separate loop before subsegs are chained.
2021-09-18PR28149 part 2, purge generated line infoAlan Modra1-1/+29
Mixing compiler generated line info with gas generated line info is generally just confusing. Also .loc directives with non-zero view fields might reference a previous .loc. It becomes a little more tricky to locate that previous .loc if there might be gas generated line info present too. Mind you, we turn off gas generation of line info on seeing compiler generated line info, so any reference back won't hit gas generated line info. At least, if the view info is sane. Unfortunately, gas needs to handle mangled source. PR 28149 * dwarf2dbg.c (purge_generated_debug): New function. (dwarf2_directive_filename): Call the above. (out_debug_line): Don't segfault after purging. * testsuite/gas/i386/dwarf2-line-4.d: Update expected output. * testsuite/gas/i386/dwarf4-line-1.d: Likewise. * testsuite/gas/i386/dwarf5-line-1.d: Likewise. * testsuite/gas/i386/dwarf5-line-2.d: Likewise.
2021-09-18PR28149, debug info with wrong file associationAlan Modra1-67/+85
gcc-11 and gcc-12 pass -gdwarf-5 to gas, in order to prime gas for DWARF 5 level debug info. Unfortunately it seems there are cases where the compiler does not emit a .file or .loc dwarf debug directive before any machine instructions. (Note that the .file directive typically emitted as the first line of assembly output doesn't count as a dwarf debug directive. The dwarf .file has a file number before the file name string.) This patch delays allocation of file numbers for gas generated line debug info until the end of assembly, thus avoiding any clashes with compiler generated file numbers. Two fixes for test case source are necessary; A .loc can't use a file number that hasn't already been specified with .file. A followup patch will remove all the gas generated line info on seeing a .file directive. PR 28149 * dwarf2dbg.c (num_of_auto_assigned): Delete. (current): Update initialisation. (set_or_check_view): Replace all accesses to view with u.view. (dwarf2_consume_line_info): Likewise. (dwarf2_directive_loc): Likewise. Assert that we aren't generating line info. (dwarf2_gen_line_info_1): Don't call set_or_check_view on gas generated line entries. (dwarf2_gen_line_info): Set and track filenames for gas generated line entries. Simplify generation of labels. (get_directory_table_entry): Use filename_cmp when comparing dirs. (do_allocate_filenum): New function. (dwarf2_where): Set u.filename and filenum to -1 for gas generated line entries. (dwarf2_directive_filename): Remove num_of_auto_assigned handling. (process_entries): Update view field access. Call do_allocate_filenum. * dwarf2dbg.h (struct dwarf2_line_info): Add filename field in union aliasing view. * testsuite/gas/i386/dwarf2-line-3.s: Add .file directive. * testsuite/gas/i386/dwarf2-line-4.s: Likewise. * testsuite/gas/i386/dwarf2-line-4.d: Update expected output. * testsuite/gas/i386/dwarf4-line-1.d: Likewise. * testsuite/gas/i386/dwarf5-line-1.d: Likewise. * testsuite/gas/i386/dwarf5-line-2.d: Likewise.
2021-09-09gas: Use the directory name in .file 0H.J. Lu1-4/+8
DWARF5 allows .file 0 to take an optional directory name. Set the entry 0 of the directory table to the directory name in .file 0. PR gas/28266 * dwarf2dbg.c (get_directory_table_entry): Add an argument for the directory name in .file 0 and use it, instead of PWD. (allocate_filenum): Pass NULL to get_directory_table_entry. (allocate_filename_to_slot): Pass the incoming dirname to get_directory_table_entry. * testsuite/gas/elf/dwarf-5-file0-2.d: New file. * testsuite/gas/elf/dwarf-5-file0-2.s: Likewise. * testsuite/gas/elf/elf.exp: Run dwarf-5-file0-2.
2021-08-09GAS: DWARF-5: Ensure that the 0'th entry in the directory table contains the ↵Nick Clifton1-9/+29
current working directory. * dwarf2dbg.c (get_directory_table_entry): Ensure that dir[0] contains current working directory. (out_dir_and_file_list): Likewise. * testsuite/gas/elf/dwarf-5-dir0.s: New test source file. * testsuite/gas/elf/dwarf-5-dir0.d: New test driver. * testsuite/gas/elf/elf.exp: Run the new test. * testsuite/gas/elf/dwarf-5-file0.d: Adjust expected output. * testsuite/gas/i386/dwarf5-line-1.d: Likewise. * testsuite/gas/i386/dwarf5-line-2.d: Likewise.
2021-04-05C99 gas configuryAlan Modra1-11/+0
Also remove alloca stuff since we don't use alloca in gas nowadays. * configure.ac: Don't check for string.h, strings.h, stdlib.h, errno.h, limits.h, locale.h or time.h. Don't check for unlink, remove, sbrk (unused) or setlocale. Adjust gas_test_headers. Don't check for errno, free, malloc, realoc, sbrk, strstr, getenv strstr, or vsnprintf declarations. (AC_ISC_POSIX, AC_FUNC_ALLOCA, AC_C_INLINE): Don't invoke. * as.h: Don't include alloca-conf.h, include config.h instead. Include string.h, stdlib.h, errno.h unconditionally. Remove various fallback declarations. * asintl.h: Don't test HAVE_LOCALE_H. * as.c: Don't test HAVE_SETLOCALE. * dwarf2dbg.c: Include limits.h unconditionally. * expr.c: Likewise. * sb.c: Likewise. * symbols.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-d30v.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-tic54x.c (tic54x_mlib): Call remove rather than unlink. * config.in: Regenerate. * configure: Regenerate. * Makefile.in: Regenerate. * doc/Makefile.in: Regenerate.
2021-04-01Use startswith in gas subfolder.Martin Liska1-1/+1
gas/ChangeLog: * as.c (select_emulation_mode): Use startswith. * config/m68k-parse.y: Likewise. * config/obj-aout.c (obj_aout_type): Likewise. * config/obj-elf.c (elf_common_parse): Likewise. (obj_elf_section_type): Likewise. (obj_elf_section_word): Likewise. (obj_elf_section): Likewise. (obj_elf_symver): Likewise. (adjust_stab_sections): Likewise. * config/obj-evax.c (evax_shorten_name): Likewise. * config/obj-macho.c (obj_mach_o_is_frame_section): Likewise. * config/tc-aarch64.c (parse_aarch64_imm_float): Likewise. (aarch64_parse_features): Likewise. (create_register_alias): Likewise. (aarch64_data_in_code): Likewise. (md_parse_option): Likewise. * config/tc-alpha.c (s_alpha_section_word): Likewise. (s_alpha_pdesc): Likewise. * config/tc-arc.c (tokenize_extregister): Likewise. * config/tc-arm.c (create_register_alias): Likewise. (create_neon_reg_alias): Likewise. (parse_ifimm_zero): Likewise. (parse_qfloat_immediate): Likewise. (arm_elf_section_type): Likewise. (arm_parse_extension): Likewise. (aeabi_set_public_attributes): Likewise. (s_arm_arch_extension): Likewise. (arm_data_in_code): Likewise. (start_unwind_section): Likewise. * config/tc-avr.c (avr_ldi_expression): Likewise. * config/tc-csky.c (is_freglist_legal): Likewise. (csky_s_section): Likewise. * config/tc-d30v.c (do_assemble): Likewise. * config/tc-dlx.c (parse_operand): Likewise. * config/tc-epiphany.c (md_assemble): Likewise. * config/tc-h8300.c (h8300_elf_section): Likewise. (get_operand): Likewise. * config/tc-hppa.c (pa_ip): Likewise. (pa_level): Likewise. (pa_space): Likewise. * config/tc-i386.c (i386_mach): Likewise. (md_assemble): Likewise. (check_VecOperations): Likewise. (i386_target_format): Likewise. (i386_elf_section_type): Likewise. * config/tc-ia64.c (start_unwind_section): Likewise. (md_parse_option): Likewise. (is_taken_branch): Likewise. (idesc->name,): Likewise. (note_register_values): Likewise. (do_alias): Likewise. * config/tc-m32c.c (insn_to_subtype): Likewise. * config/tc-m68hc11.c (get_operand): Likewise. (md_assemble): Likewise. * config/tc-m68k.c (m68k_ip): Likewise. (m68k_elf_suffix): Likewise. * config/tc-mcore.c (mcore_s_section): Likewise. * config/tc-metag.c (parse_get_set): Likewise. (md_parse_option): Likewise. * config/tc-microblaze.c (parse_imm): Likewise. (check_got): Likewise. (md_apply_fix): Likewise. * config/tc-mips.c (CPU_HAS_MIPS16): Likewise. (md_begin): Likewise. (s_is_linkonce): Likewise. (check_regno): Likewise. (match_float_constant): Likewise. (classify_vr4120_insn): Likewise. (match_insn): Likewise. (mips_after_parse_args): Likewise. (s_change_sec): Likewise. (s_option): Likewise. (parse_code_option): Likewise. (md_section_align): Likewise. (nopic_need_relax): Likewise. * config/tc-mmix.c (mmix_handle_mmixal): Likewise. * config/tc-mn10300.c (mn10300_fix_adjustable): Likewise. (mn10300_end_of_match): Likewise. * config/tc-msp430.c (msp430_make_init_symbols): Likewise. * config/tc-nds32.c (nds32_parse_option): Likewise. * config/tc-nds32.h (md_do_align): Likewise. * config/tc-nios2.c (strprefix): Likewise. (nios2_special_relocation_p): Likewise. (nios2_parse_base_register): Likewise. (nios2_cons): Likewise. * config/tc-ns32k.c (addr_mode): Likewise. * config/tc-pdp11.c (set_option): Likewise. (parse_reg): Likewise. (parse_ac5): Likewise. (parse_op_no_deferred): Likewise. (set_cpu_model): Likewise. (set_machine_model): Likewise. * config/tc-pj.c (md_operand): Likewise. * config/tc-ppc.c (ppc_set_cpu): Likewise. (ppc_arch): Likewise. (ppc_section_type): Likewise. * config/tc-s12z.c (tb_reg_rel): Likewise. (tb_opr_rel): Likewise. * config/tc-s390.c (s390_parse_cpu): Likewise. (md_parse_option): Likewise. * config/tc-score.c (s3_nopic_need_relax): Likewise. (s3_pic_need_relax): Likewise. * config/tc-score7.c (s7_nopic_need_relax): Likewise. (s7_pic_need_relax): Likewise. * config/tc-sh.h (SUB_SEGMENT_ALIGN): Likewise. * config/tc-sparc.c (md_parse_option): Likewise. (sparc_ip): Likewise. (s_reserve): Likewise. (s_common): Likewise. (s_seg): Likewise. (sparc_cons): Likewise. * config/tc-tic54x.c (stag_add_field): Likewise. (tic54x_endstruct): Likewise. * config/tc-tic6x.c (tic6x_start_unwind_section): Likewise. * config/tc-v850.c (v850_comm): Likewise. (md_begin): Likewise. (md_assemble): Likewise. * config/tc-vax.c (vax_cons): Likewise. * config/tc-wasm32.c (wasm32_leb128): Likewise. * config/tc-xstormy16.c (md_operand): Likewise. * config/tc-xtensa.c (get_directive): Likewise. (xg_instruction_matches_option_term): Likewise. (is_unaligned_label): Likewise. (cache_literal_section): Likewise. * config/xtensa-relax.c (parse_precond): Likewise. (parse_option_cond): Likewise. (transition_applies): Likewise. (wide_branch_opcode): Likewise. * dw2gencfi.c: Likewise. * dwarf2dbg.c (dwarf2_directive_filename): Likewise. * ehopt.c (get_cie_info): Likewise. * input-file.c (input_file_open): Likewise. * listing.c (listing_newline): Likewise. (debugging_pseudo): Likewise. * read.c (read_a_source_file): Likewise. * write.c (adjust_reloc_syms): Likewise. (compress_debug): Likewise. (maybe_generate_build_notes): Likewise.
2021-03-31Use bool in gasAlan Modra1-38/+38
* as.h (POISON_BFD_BOOLEAN): Define. * as.c, * as.h, * atof-generic.c, * config/atof-ieee.c, * config/bfin-aux.h, * config/obj-coff.c, * config/obj-ecoff.c, * config/obj-elf.c, * config/obj-elf.h, * config/obj-som.c, * config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c, * config/tc-arc.h, * config/tc-arm.c, * config/tc-arm.h, * config/tc-avr.c, * config/tc-avr.h, * config/tc-bfin.c, * config/tc-bfin.h, * config/tc-bpf.c, * config/tc-cris.c, * config/tc-csky.c, * config/tc-csky.h, * config/tc-d10v.c, * config/tc-d10v.h, * config/tc-d30v.c, * config/tc-d30v.h, * config/tc-dlx.c, * config/tc-dlx.h, * config/tc-epiphany.c, * config/tc-epiphany.h, * config/tc-fr30.c, * config/tc-fr30.h, * config/tc-frv.c, * config/tc-frv.h, * config/tc-ft32.c, * config/tc-ft32.h, * config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386-intel.c, * config/tc-i386.c, * config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c, * config/tc-iq2000.h, * config/tc-lm32.c, * config/tc-lm32.h, * config/tc-m32c.c, * config/tc-m32c.h, * config/tc-m32r.c, * config/tc-m32r.h, * config/tc-m68hc11.c, * config/tc-m68k.c, * config/tc-mcore.c, * config/tc-mcore.h, * config/tc-mep.c, * config/tc-mep.h, * config/tc-metag.c, * config/tc-metag.h, * config/tc-microblaze.c, * config/tc-mips.c, * config/tc-mips.h, * config/tc-mmix.c, * config/tc-mn10200.c, * config/tc-mn10300.c, * config/tc-mn10300.h, * config/tc-moxie.c, * config/tc-msp430.c, * config/tc-msp430.h, * config/tc-mt.c, * config/tc-mt.h, * config/tc-nds32.c, * config/tc-nds32.h, * config/tc-nios2.c, * config/tc-ns32k.c, * config/tc-or1k.c, * config/tc-or1k.h, * config/tc-pdp11.c, * config/tc-ppc.c, * config/tc-pru.c, * config/tc-pru.h, * config/tc-riscv.c, * config/tc-riscv.h, * config/tc-rx.c, * config/tc-rx.h, * config/tc-s12z.c, * config/tc-s12z.h, * config/tc-s390.c, * config/tc-score.c, * config/tc-score.h, * config/tc-score7.c, * config/tc-sh.c, * config/tc-sh.h, * config/tc-spu.c, * config/tc-tic54x.c, * config/tc-tic6x.c, * config/tc-tic6x.h, * config/tc-tilegx.c, * config/tc-tilepro.c, * config/tc-v850.c, * config/tc-v850.h, * config/tc-visium.c, * config/tc-visium.h, * config/tc-wasm32.c, * config/tc-wasm32.h, * config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c, * config/tc-xstormy16.h, * config/tc-xtensa.c, * config/tc-xtensa.h, * config/tc-z80.c, * config/tc-z8k.c, * config/xtensa-istack.h, * config/xtensa-relax.c, * config/xtensa-relax.h, * dw2gencfi.c, * dwarf2dbg.c, * dwarf2dbg.h, * expr.c, * expr.h, * frags.c, * frags.h, * listing.c, * macro.c, * output-file.c, * read.c, * read.h, * stabs.c, * symbols.c, * write.c: Replace bfd_boolean with bool, FALSE with false, and TRUE with true.
2021-02-16PR27426, More bugs in dwarf2dbg.cAlan Modra1-3/+11
PR 27426 * dwarf2dbg.c (allocate_filename_to_slot): Allocate the dirs array in another place.
2021-02-08Fix an illegal memory access when parsing a corrupt assembler file.Nick Clifton1-2/+10
PR 27355 * dwarf2dbg.c (allocate_filename_to_slot): Allocate the dirs array if it has not already been created.
2021-01-21PR27221, 058430b4a1 warnings while assembling the Linux kernelAlan Modra1-2/+3
PR 27221 * dwarf2dbg.c (dwarf2_gen_line_info_1): Don't warn about ignored line number info when gas is generating it. * testsuite/gas/elf/dwarf2-20.d: Adjust to not expect warnings. * testsuite/gas/m68hc11/indexed12.d: Likewise. * testsuite/gas/elf/elf.exp: Don't run warn-2. * gas/testsuite/gas/elf/warn-2.s: Delete.
2021-01-21PR27218, memory access violation in dwarf2dbg.cAlan Modra1-13/+13
PR 27218 * dwarf2dbg.c (dwarf2_gen_line_info): Correct setting of dwarf_level. (dwarf2_directive_filename, dwarf2_directive_loc): Likewise, and error for negative file numbers.
2021-01-18as: Automatically enable DWARF5 supportH.J. Lu1-6/+18
Currently $ as -o x.o x.s fails when x.s contains DWARF5 ".file 0" or ".loc 0" directives. Update assembler to automatically enable DWARF5 support so that $ gcc -S -g -c x.c $ gcc -c x.s works. PR gas/27195 * dwarf2dbg.c (dwarf2_gen_line_info): Set dwarf_level to 5 if needed. (dwarf2_directive_filename): Likewise. (dwarf2_directive_loc): Likewise. * testsuite/gas/elf/dwarf-5-file0.d: Pass --gdwarf-3. * testsuite/gas/lns/lns-diag-1.l: Remove the "Error: file number less than one" errors.
2021-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2020-11-18Re: Stop Gas from generating line info or address rangesAlan Modra1-7/+9
* doc/as.texi (.nop): Document optional size arg. * dwarf2dbg.c (dwarf2_gen_line_info_1): Only check SEC_ALLOC when ELF. Warn whenever dwarf line number information is ignored. * frags.c (frag_offset_ignore_align_p): New function. * frags.h (frag_offset_ignore_align_p): Declare. * read.c (s_nop): Extend to support optional size arg. * testsuite/gas/elf/dwarf2-20.d: Expect warnings, and exact range. * testsuite/gas/elf/dwarf2-20.s: Emit 16 bytes worth of nops. * testsuite/gas/m68hc11/indexed12.d: Expect warnings.
2020-11-12Stop Gas from generating line info or address ranges for sections that do ↵Nick Clifton1-4/+14
not contain code or are not loaded. PR 26850 * dwarf2dbg.c (dwarf2_gen_line_info_1): Do not record lines in sections that are not executable or not loadable. (out_debug_line): Move warning message into dwarf2_gen_line_info_1. * testsuite/gas/elf/dwarf2-20.s: New test. * testsuite/gas/elf/dwarf2-20.d: New test driver. * testsuite/gas/elf/elf.exp: Run the new test. * testsuite/gas/elf/warn-2.s: Use the .nop directive.
2020-10-26gas: Clear all auto-assigned file slotsH.J. Lu1-11/+13
Since a file slot is auto-assigned for the #APP marker appeared before the first .file <NUMBER> directive has been seen, clear all auto-assigned file slots when seeing the first .file <NUMBER> directive. PR gas/26778 * * dwarf2dbg.c (num_of_auto_assigned): New. (allocate_filenum): Increment num_of_auto_assigned. (dwarf2_directive_filename): Clear the slots auto-assigned before the first .file <NUMBER> directive was seen. * testsuite/gas/i386/dwarf4-line-1.d: New file. * testsuite/gas/i386/dwarf4-line-1.s: Likewise. * testsuite/gas/i386/i386.exp: Run dwarf4-line-1.
2020-10-17gas: Always use as_where for preprocessed assembly codesH.J. Lu1-19/+24
Always clear the slot 1 if it was assigned to the input file before the first .file <NUMBER> directive has been seen. Always use as_where to generate the correct debug infor for preprocessed assembly codes. PR gas/25878 PR gas/26740 * dwarf2dbg.c (allocate_filename_to_slot): Don't reuse the slot 1 here. (dwarf2_where): Restore as_where. (dwarf2_directive_filename): Clear the slot 1 if it was assigned to the input file. * testsuite/gas/i386/dwarf5-line-2.d: New file. * testsuite/gas/i386/dwarf5-line-2.s: Likewise. * testsuite/gas/i386/dwarf5-line-3.d: Likewise. * testsuite/gas/i386/dwarf5-line-3.s: Likewise. * testsuite/gas/i386/i386.exp: Run dwarf5-line-2 and dwarf5-line-3.
2020-10-16gas: Reuse the input file entry in the file tableH.J. Lu1-18/+10
Some instructions can be emitted (dwarf2_emit_insn is called) before the first .file <NUMBER> directive has been seen, which allocates the input file as the first file entry. Reuse the input file entry in the file table. PR gas/25878 PR gas/26740 * dwarf2dbg.c (file_entry): Remove auto_assigned. (assign_file_to_slot): Remove the auto_assign argument. (allocate_filenum): Updated. (allocate_filename_to_slot): Reuse the input file entry in the file table. (dwarf2_where): Replace as_where with as_where_physical. * testsuite/gas/i386/dwarf5-line-1.d: New file. * testsuite/gas/i386/dwarf5-line-1.s: Likewise. * testsuite/gas/i386/i386.exp: Run dwarf5-line-1.
2020-09-11gas: Don't error when .debug_line already exists, unless .loc was usedMark Wielaard1-8/+21
When -g was used to generate DWARF gas would error out when a .debug_line already exists. But when a .debug_info section already exists it would simply skip generating one without warning or error. Do the same for .debug_line. It is only an error when the user explicitly uses .loc directives and also generates the .debug_line table itself. The tests are unfortunately arch specific because the line table is only generated when actual instructions have been emitted. Use i386 because that is probably the most used architecture. Before this patch the new dwarf-line-2 testcase would fail, with this patch it succeeds (and doesn't try to add its own line table). gas/ChangeLog: * as.texi (-g): Explicitly mention when .debug_info and .debug_line are generated for the DWARF format. (Loc): Add that it is an error to both use a .loc directive and generate a .debug_line yourself. * dwarf2dbg.c (dwarf2_any_loc_directive_seen): New static variable. (dwarf2_directive_loc): Set dwarf2_any_loc_directive_seen to TRUE. (dwarf2_finish): Check dwarf2_any_loc_directive_seen before emitting an error. Only create .debug_line if it is empty (or doesn't exist). * testsuite/gas/i386/i386.exp: Add dwarf2-line-{1,2,3,4} when testing an elf target. * testsuite/gas/i386/dwarf2-line-{1,2,3,4}.{s,d,l}: New test files.
2020-09-07gas: Output directory and file names in .debug_line_str for DWARF5Mark Wielaard1-17/+65
* dwarf2dbg.c (add_line_strp): New function. (out_dir_and_file_list): Take line_seg and sizeof_offset as arguments, Use DW_FORM_line_strp for dir and file. Call add_line_strp and set symbol offset for DWARF2_LINE_VERSION 5. (out_debug_line): Call out_dir_and_file_list with line_seg and sizeof_offset. * gas/testsuite/gas/elf/dwarf-5-file0.d: Expect indirect line strings.
2020-09-07gas: Output .debug_rnglists for DWARF 5.Mark Wielaard1-13/+85
* dwarf2dbg.c (DWARF2_RNGLISTS_VERSION): New constant. (out_debug_ranges): Add ranges_sym argument and set it. (out_debug_rnglists): New function. (out_debug_info): Change ranges_seg argument to ranges_sym and use it to set DW_AT_ranges value. (dwarf2_finish): Remove ranges_seg, add ranges_sym. For DWARF2_VERSION 5 call out_debug_rnglists.
2020-09-07gas: Make sure to only add an md5 to a .file when requested.Mark Wielaard1-1/+1
* dwarf2dbg.c (dwarf2_directive_filename): Initialize with_md5 to FALSE. * gas/testsuite/gas/elf/dwarf-5-file0.s: Add a random bignum.
2020-09-03gas: Use DW_FORM_sec_offset for DWARF version 4 or higher.Mark Wielaard1-9/+11
Older DWARF versions used DW_FORM_data4 or DW_FORM_data8 for offsets into sections for e.g. DW_AT_stmt_list ot DW_AT_ranges. But version 4 introduced a dedicated form for such section offsets. Make sure to emit the proper form for newer DWARF versions. gas/ChangeLog: * dwarf2dbg.c (out_debug_abbrev): Use DW_FORM_sec_offset for DWARF version 4 or higher.
2020-08-21Rearrange symbol_create parametersAlan Modra1-9/+9
These functions take an offset within frag, frag within section, and section parameter. So it makes sense to order the parameters as section, frag, offset. * symbols.h (symbol_new, symbol_create, local_symbol_make), (symbol_temp_new): Arrange params as section, frag, offset. * symbols.c: Adjust to suit. * as.c: Likewise. * cgen.c: Likewise. * dwarf2dbg.c: Likewise. * ecoff.c: Likewise. * expr.c: Likewise. * itbl-ops.c: Likewise. * read.c: Likewise. * stabs.c: Likewise. * subsegs.c: Likewise. * config/obj-coff.c: Likewise. * config/obj-elf.c: Likewise. * config/obj-macho.c: Likewise. * config/tc-aarch64.c: Likewise. * config/tc-alpha.c: Likewise. * config/tc-arc.c: Likewise. * config/tc-arm.c: Likewise. * config/tc-avr.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-cris.c: Likewise. * config/tc-csky.c: Likewise. * config/tc-dlx.c: Likewise. * config/tc-hppa.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m32r.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mips.c: Likewise. * config/tc-mmix.c: Likewise. * config/tc-mn10200.c: Likewise. * config/tc-mn10300.c: Likewise. * config/tc-nds32.c: Likewise. * config/tc-nios2.c: Likewise. * config/tc-ppc.c: Likewise. * config/tc-riscv.c: Likewise. * config/tc-s390.c: Likewise. * config/tc-sh.c: Likewise. * config/tc-tic4x.c: Likewise. * config/tc-tic54x.c: Likewise. * config/tc-xtensa.c: Likewise.
2020-08-04gas: Use udata for DW_AT_high_pc when emitting DWARF4Mark Wielaard1-3/+5
For DWARF4 DW_AT_high_pc can be expressed as constant offset from DW_AT_low_pc which saves a relocation. Use DW_FORM_udate (uleb128) to keep the constant value as small as possible. gas/ChangeLog: * dwarf2dbg.c (out_debug_abbrev): When DWARF2_VERSION >= 4, use DW_FORM_udata for DW_AT_high_pc. (out_debug_info): Use emit_leb128_expr for DW_AT_high_pc, when DWARF2_VERSION >= 4. * read.c (emit_leb128_exp): No longer static. * read.h (emit_leb128_exp): Define.
2020-08-04gas: Make sure .debug_line file table contains a zero filename and dirMark Wielaard1-9/+26
For DWARF5 the zero file list entry in the .debug_line table represents the compile unit main file. It can be set with .file 0 when -gdwarf-5 is given. But since this directive is illegal for older versions, this is almost never set. To make sure it is always set (so DW_AT_name of the compile unit can be set) use file (and dir) 1 if that is defined (otherwise fall back to pwd, to match DW_AT_comp_dir). gas/ChangeLog: * gas/dwarf2dbg.c (out_dir_and_file_list): For DWARF5 emit at least one directory if there is at least one file. Use dirs[1] if dirs[0] is not set, or if there is no dirs[1] the current working directory. Use files[1] filename, when files[0] filename isn't set.
2020-08-04gas: Fix .debug_info CU header for --gdwarf-5Mark Wielaard1-2/+16
DWARF5 CU headers have a new unit type field and move the abbrev offset to the end of the header. gas/ChangeLog: * dwarf2dbg.c (out_debug_info): Emit unit type and abbrev offset for DWARF5. * gas/testsuite/gas/elf/dwarf-4-cu.d: New file. * gas/testsuite/gas/elf/dwarf-4-cu.s: Likewise. * gas/testsuite/gas/elf/dwarf-5-cu.d: Likewise. * gas/testsuite/gas/elf/dwarf-5-cu.s: Likewise. * testsuite/gas/elf/elf.exp: Run dwarf-4-cu and dwarf-5-cu.
2020-05-05Restore readelf's warnings that describe real problems with the file being ↵Nick Clifton1-0/+5
examined. Fix bug displaying empty file name tables. binutils* dwarf.c (do_checks): New global variable. (display_formatted_table): Warn about an unexpected number of columns in the table, if checks are enabled. Do not complain about the lack of data following the number of entries in the table if the table is empty. (display_debug_lines_decoded): Only warn about an unexpected number of columns in a table if checks are enabled. * dwarf.h (do_checks): Add a prototype. * elfcomm.c (error): Remove weak attribute. (warn): Likewise. * readelf.c (do_checks): Delete. (warn): Delete. (process_section_headers): Only warn about empty sections if checks are enabled. gas * dwarf2dbg.c (out_dir_and_file_list): Add comments describing the construction of a DWARF-5 directory name table. * testsuite/gas/elf/pr25917.d: Update expected output.
2020-05-04GAS: Do not create an entry for the default directory if the directory table ↵Nick Clifton1-4/+1
is empty. Improve readelf's decoding of empty directory and file name tables. PR 25917 * dwarf.c (display_debug_lines_decoded): Warn if encountering a supicious number of entries for DWARF-5 format directory and file name tables. Do not display file name table header if the table is empty. Do not allocate space for empty tables.
2020-05-04Fix an illegal memory access in the assembler when generating a DWARF5 ↵Nick Clifton1-1/+1
file/directory table with no entries. PR 25917 * dwarf2dbg.c (out_dir_and_file_list): Check for the directory table's existence before looking at its entries. * testsuite/gas/elf/pr25917.s: New test source file. * testsuite/gas/elf/pr25917.d: New test driver. * testsuite/gas/elf/elf.exp (run_elf_list_test): Run the new test.
2020-04-27GAS: Allow automatically assigned entries in the file table to be reassigned ↵Nick Clifton1-51/+60
if the source file specifically requests to use the assigned slot. PR 25878 * dwarf2dbg.c (struct file_entry): Add auto_assigned field. (assign_file_to_slot): New function. Fills in an entry in the files table. (allocate_filenum): Use new function. (allocate_filename_to_slot): Use new function. If the specified slot entry is already in use, but was chosen automatically then reassign the automatic entry.
2020-03-31PR 25611, PR 25614: GAS: Remove a double inclusion of "bignum.h"Maciej W. Rozycki1-1/+0
Correct an issue with commit 5496f3c635dc ("Add support for generating DWARF-5 format directory and file name tables from the assembler.") and remove a duplicate direct inclusion of "bignum.h" from dwarf2dbg.c that causes a GAS compilation error: In file included from .../gas/dwarf2dbg.c:33: .../gas/bignum.h:42: error: redefinition of typedef 'LITTLENUM_TYPE' .../gas/bignum.h:42: error: previous declaration of 'LITTLENUM_TYPE' was here make[4]: *** [dwarf2dbg.o] Error 1 with some GCC versions, as this header has been already included via "as.h" and then "flonum.h". gas/ PR 25611 PR 25614 * dwarf2dbg.c: Do not include "bignum.h".
2020-03-11Add support for generating DWARF-5 format directory and file name tables ↵Nick Clifton1-148/+535
from the assembler. PR 25611 PR 25614 * dwarf.h (DWARF2_Internal_LineInfo): Add li_address_size and li_segment_size fields. * dwarf.c (read_debug_line_header): Record the address size and segment selector size values (if present) in the lineinfo structure. (display_formatted_table): Warn if the format count is empty but the table itself is not empty. Display the format count and entry count at the start of the table dump. (display_debug_lines_raw): Display the address size and segement selector size fields, if present. * testsuite/binutils-all/dw5.W: Update expected output. gas * dwarf2dbg.c (DWARF2_FILE_TIME_NAME): Default to -1. (DWARF2_FILE_SIZE_NAME): Default to -1. (DWARF2_LINE_VERSION): Default to the current dwarf level or 3, whichever is higher. (DWARF2_LINE_MAX_OPS_PER_INSN): Provide a default value of 1. (NUM_MD5_BYTES): Define. (struct file entry): Add md5 field. (get_filenum): Delete and replace with... (get_basename): New function. (get_directory_table_entry): New function. (allocate_filenum): New function. (allocate_filename_to_slot): New function. (dwarf2_where): Use new functions. (dwarf2_directive_filename): Add support for extended .file pseudo-op. (dwarf2_directive_loc): Allow the use of file number zero with DWARF 5 or higher. (out_file_list): Rename to... (out_dir_and_file_list): Add DWARF 5 support. (out_debug_line): Emit extra values into the section header for DWARF 5. (out_debug_str): Allow for file 0 to be used with DWARF 5. * doc/as.texi (.file): Update the description of this pseudo-op. * testsuite/gas/elf-dwarf-5-file0.s: Add more lines. * testsuite/gas/elf-dwarf-5-file0.d: Update expected dump output. * testsuite/gas/lns/lns-diag-1.l: Update expected error message. * NEWS: Mention the new feature.
2020-03-06Add support for a ".file 0" directive if supporting DWARF 5 or higher.Nick Clifton1-6/+16
PR 25614 * dwarf2dbg.c (dwarf2_directive_filename): Allow a file number of 0 if the dwarf_level is 5 or more. Complain if a filename follows a file 0. * testsuite/gas/elf/dwarf-5-file0.s: New test. * testsuite/gas/elf/dwarf-5-file0.d: New test driver. * testsuite/gas/elf/elf.exp: Run the new test. PR 25612 * config/tc-ia64.h (DWARF2_VERISION): Fix typo. * doc/as.texi: Fix another typo.
2020-03-06Add support for --dwarf-[3|4|5] to assembler command line.Nick Clifton1-1/+1
PR 25612 * as.c (dwarf_level): Define. (show_usage): Add --gdwarf-3, --gdwarf-4 and --gdwarf-5. (parse_args): Add support for the new options. as.h (dwarf_level): Prototype. * dwarf2dbg.c (DWARF2_VERSION): Use dwarf_level as default version value. * config/tc-ia64.h (DWARF2_VERISION): Update definition. (DWARF2_LINE_VERSION): Remove definition. * doc/as.texi: Document the new options.
2020-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1