Commit Graph

198 Commits

Author SHA1 Message Date
Alan Modra
5b714f5b6d Avoid possible signed overflow in decode_local_label_name
Matches what both fb_label_name and dollar_label_name use.

	* symbols.c (decode_local_label_name): Use unsigned variables.
2024-07-03 15:37:35 +09:30
Alan Modra
664239bcaa Make various gas symbol predicates and accessors take const args
* symbols.c (S_IS_FUNCTION, S_IS_EXTERNAL, S_IS_WEAK),
	(S_IS_WEAKREFR, S_IS_WEAKREFD, S_IS_COMMON, S_IS_DEFINED),
	(S_FORCE_RELOC, S_IS_DEBUG, S_IS_LOCAL, S_IS_STABD),
	(symbol_previous, symbol_next, symbol_X_add_number),
	(symbol_get_frag, symbol_used_p, symbol_used_in_reloc_p),
	(symbol_mri_common_p, symbol_written_p, symbol_removed_p),
	(symbol_resolved_p, symbol_resolving_p, symbol_section_p),
	(symbol_equated_p, symbol_equated_reloc_p, symbol_constant_p),
	(symbol_shadow_p, symbol_same_p): Constify sym args.
	* symbols.h: Update prototypes.
2024-02-15 22:05:23 +10:30
Alan Modra
2fbbadc2c3 PR30308, infinite recursion in i386_intel_simplify
This patch exposes the symbol "resolving" flag for use in
i386_intel_simplify, not only preventing infinite recursion on the
testcase in the PR but also more complicated cases like:

 .intel_syntax
 b = a
 a = b
 mov eax, [a]

	PR 30308
	* symbols.c (symbol_mark_resolving, symbol_clear_resolving),
	(symbol_resolving_p): New functions.
	* symbols.h: Declare them.
	* config/tc-i386-intel.c (i386_intel_simplify): Delete forward
	declaration.  Formatting.
	(i386_intel_simplify_symbol): Use resolving flag to prevent
	infinite recursion.
2024-02-15 11:24:13 +10:30
Indu Bhagat
c7defc5386 gas: x86: synthesize CFI for hand-written asm
This patch adds support in GAS to create generic GAS instructions
(a.k.a., the ginsn) for the x86 backend (AMD64 ABI only at this time).
Using this ginsn infrastructure, GAS can then synthesize CFI for
hand-written asm for x86_64.

A ginsn is a target-independent representation of the machine
instructions.  One machine instruction may need one or more ginsn.

This patch also adds skeleton support for printing ginsn in the listing
output for debugging purposes.

Since the current use-case of ginsn is to synthesize CFI, the x86 target
needs to generate ginsns necessary for the following machine
instructions only:

 - All change of flow instructions, including all conditional and
   unconditional branches, call and return from functions.
 - All register saves and unsaves to the stack.
 - All instructions affecting the two registers that could potentially
   be used as the base register for CFA tracking.  For SCFI, the base
   register for CFA tracking is limited to REG_SP and REG_FP only for
   now.

The representation of ginsn is kept simple:

- GAS instruction has GINSN_NUM_SRC_OPNDS (defined to be 2 at this time)
  number of source operands and one destination operand at this time.
- GAS instruction uses DWARF register numbers in its representation and
  does not track register size.
- GAS instructions carry location information (file name and line
  number).
- GAS instructions are ID's with a natural number in order of their
  addtion to the list.  This can be used as a proxy for the static
  program order of the corresponding machine instructions.

Note that, GAS instruction (ginsn) format does not support
GINSN_TYPE_PUSH and GINSN_TYPE_POP.  Some architectures, like aarch64,
do not have push and pop instructions, but rather STP/LDP/STR/LDR etc.
instructions.  Further these instructions have a variety of addressing
modes, like offset, pre-indexing and post-indexing etc.  Among other
things, one of differences in these addressing modes is _when_ the addr
register is updated with the result of the address calculation: before
or after the memory operation.  To best support such needs, the generic
instructions like GINSN_TYPE_LOAD, GINSN_TYPE_STORE together with
GINSN_TYPE_ADD, and GINSN_TYPE_SUB may be used.

The functionality provided in ginsn.c and scfi.c is compiled in when a
target defines TARGET_USE_SCFI and TARGET_USE_GINSN.  This can be
revisited later when there are other use-cases of creating ginsn's in
GAS, apart from the current use-case of synthesizing CFI for
hand-written asm.

Support is added only for System V AMD64 ABI for ELF at this time.  If
the user enables SCFI with --32, GAS issues an error:

  "Fatal error: SCFI is not supported for this ABI"

For synthesizing (DWARF) CFI, the SCFI machinery requires the programmer
to adhere to some pre-requisites for their asm:
   - Hand-written asm block must begin with a .type   foo, @function
It is highly recommended to, additionally, also ensure that:
   - Hand-written asm block ends with a .size foo, .-foo

The SCFI machinery encodes some rules which align with the standard
calling convention specified by the ABI.  Apart from the rules, the SCFI
machinery employs some heuristics.  For example:
   - The base register for CFA tracking may be either REG_SP or REG_FP.
   - If the base register for CFA tracking is REG_SP, the precise amount of
     stack usage (and hence, the value of REG_SP) must be known at all times.
   - If using dynamic stack allocation, the function must switch to
     FP-based CFA.  This means using instructions like the following (in
     AMD64) in prologue:
        pushq   %rbp
        movq    %rsp, %rbp
     and analogous instructions in epilogue.
   - Save and Restore of callee-saved registers must be symmetrical.
     However, the SCFI machinery at this time only warns if any such
     asymmetry is seen.

These heuristics/rules are architecture-independent and are meant to
employed for all architectures/ABIs using SCFI in the future.

gas/
	* Makefile.am: Add new files.
	* Makefile.in: Regenerated.
	* as.c (defined): Handle documentation and listing option for
	ginsns and SCFI.
	* config/obj-elf.c (obj_elf_size): Invoke ginsn_data_end.
	(obj_elf_type): Invoke ginsn_data_begin.
	* config/tc-i386.c (x86_scfi_callee_saved_p): New function.
	(ginsn_prefix_66H_p): Likewise.
	(ginsn_dw2_regnum): Likewise.
	(x86_ginsn_addsub_reg_mem): Likewise.
	(x86_ginsn_addsub_mem_reg): Likewise.
	(x86_ginsn_alu_imm): Likewise.
	(x86_ginsn_move): Likewise.
	(x86_ginsn_lea): Likewise.
	(x86_ginsn_jump): Likewise.
	(x86_ginsn_jump_cond): Likewise.
	(x86_ginsn_enter): Likewise.
	(x86_ginsn_safe_to_skip): Likewise.
	(x86_ginsn_unhandled): Likewise.
	(x86_ginsn_new): New functionality to generate ginsns.
	(md_assemble): Invoke x86_ginsn_new.
	(s_insn): Likewise.
	(i386_target_format): Add hard error for usage of SCFI with non AMD64 ABIs.
	* config/tc-i386.h (TARGET_USE_GINSN): New definition.
	(TARGET_USE_SCFI): Likewise.
	(SCFI_MAX_REG_ID): Likewise.
	(REG_FP): Likewise.
	(REG_SP): Likewise.
	(SCFI_INIT_CFA_OFFSET): Likewise.
	(SCFI_CALLEE_SAVED_REG_P): Likewise.
	(x86_scfi_callee_saved_p): Likewise.
	* gas/listing.h (LISTING_GINSN_SCFI): New define for ginsn and
	SCFI.
	* gas/read.c (read_a_source_file): Close SCFI processing at end
	of file read.
	* gas/scfidw2gen.c (scfi_process_cfi_label): Add implementation.
	(scfi_process_cfi_signal_frame): Likewise.
	* subsegs.h (struct frch_ginsn_data): New forward declaration.
	(struct frchain): New member for ginsn data.
	* gas/subsegs.c (subseg_set_rest): Initialize the new member.
	* symbols.c (colon): Invoke ginsn_frob_label to convey
	user-defined labels to ginsn infrastructure.
	* ginsn.c: New file.
	* ginsn.h: New file.
	* scfi.c: New file.
	* scfi.h: New file.
2024-01-15 03:31:35 -08:00
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
Adds two new external authors to etc/update-copyright.py to cover
bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then
updates copyright messages as follows:

1) Update cgen/utils.scm emitted copyrights.
2) Run "etc/update-copyright.py --this-year" with an extra external
   author I haven't committed, 'Kalray SA.', to cover gas testsuite
   files (which should have their copyright message removed).
3) Build with --enable-maintainer-mode --enable-cgen-maint=yes.
4) Check out */po/*.pot which we don't update frequently.
2024-01-04 22:58:12 +10:30
Jan Beulich
80968745ee gas: S_GET_{NAME,SEGMENT}() don't alter their input symbol
Make their parameters pointer-to-const, thus allowing callers to also be
const-correct where possible.
2023-11-08 09:29:39 +01:00
Jan Beulich
b41ef0baac gas: make S_IS_LOCAL() and S_IS_EXTERNAL() exclusive of one another
While they aren't opposites of each other, there also shouldn't be any
symbol for which both return true; both may return false. Therefore
use S_IS_EXTERNAL() in S_IS_LOCAL(), thus subsuming the sanity check
which so far both did alike.
2023-08-18 08:57:34 +02:00
Sam James
b5c37946cc Revert "2.41 Release sources"
This reverts commit 675b9d612c.

See https://sourceware.org/pipermail/binutils/2023-August/128761.html.
2023-08-02 12:06:23 +01:00
Nick Clifton
675b9d612c 2.41 Release sources 2023-08-02 09:23:36 +01:00
Alan Modra
a879fdb267 Make the default gas symbol hash table larger
We may as well start with the symbol table a little larger, saving
time resizing.  Even a simple C hello world compiled with -O2 -g will
exceed 16 symbols (by well over 3 times with gcc-11).

	* symbols.c (symbol_begin): Create sy_hash with more entries.
2023-07-14 12:01:41 +09:30
Jan Beulich
d50c498a1b gas: equates of registers
There are two problems: symbol_equated_p() doesn't recognize equates of
registers, and S_CAN_BE_REDEFINED() goes by section rather than by
expression type. Both together undermine .eqv and .equiv clearly meaning
to guard the involved symbols against re-definition (both ways).

To compensate pseudo_set() now using O_symbol and S_CAN_BE_REDEFINED()
now checking for O_register,
- for targets creating register symbols through symbol_{new,create}() ->
  symbol_init() -> S_SET_VALUE() (alpha, arc, dlx, ia64, m68k, mips,
  mmix, tic4x, tic54x, plus anything using cgen or itbl-ops), have
  symbol_init() set their expressions to O_register,
- x86'es parse_register() also can't go by section anymore when
  trying to "look through" equates; probably symbol_equated_p() should
  have been used there from the beginning, if only that had worked for
  equates of registers,
- various targets need to "look through" equates when parsing insn
  operands (which also helps transitive forward equates); perhaps even
  more ought to, but many don't look to consider the possibility of
  register equates in the first place.

This was uncovered by code reported in PR gas/30274 (duplicating
PR gas/30272), except that there .eqv was used when really .equ was
meant. Therefore that bug report is addressed here only in so far as
gas wouldn't crash anymore; the code there still won't assemble
successfully, just that now the issues there are properly diagnosed.
2023-05-12 08:55:48 +02:00
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
The newer update-copyright.py fixes file encoding too, removing cr/lf
on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and
embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2023-01-01 21:50:11 +10:30
Nick Clifton
12509439a1 Re: Error: attempt to get value of unresolved symbol `L0'
* symbols.c (S_GET_VALUE): If the unresolved symbol is the fake
	label provide a more helpful error message to the user.
	(S_GET_VALUE_WHERE): Like S_GET_VALUE, but includes a file/line
	number for error reporting purposes.
	* symbols.h (S_GET_VALUE_WHERE): Prototype.
	* write.c (fixup_segment): Use S_GET_VALUE_WHERE.
2022-10-11 15:29:03 +01:00
Nick Clifton
029b1ee8d8 Error: attempt to get value of unresolved symbol `L0'
* symbols.c (S_GET_VALUE): If the unresolved symbol is the fake
	label provide a more helpful error message to the user.
2022-10-11 11:52:38 +01:00
Alan Modra
f493c2174e Get rid of fprintf_vma and sprintf_vma
These two macros print either a 16 digit hex number or an 8 digit
hex number.  Unfortunately they depend on both target and host, which
means that the output for 32-bit targets may be either 8 or 16 hex
digits.

Replace them in most cases with code that prints a bfd_vma using
PRIx64.  In some cases, deliberately lose the leading zeros.
This change some output, notably in base/offset fields of m68k
disassembly which I think looks better that way, and in error
messages.  I've kept leading zeros in symbol dumps (objdump -t)
and in PE header dumps.

bfd/
	* bfd-in.h (fprintf_vma, sprintf_vma, printf_vma): Delete.
	* bfd-in2.h: Regenerate.
	* bfd.c (bfd_sprintf_vma): Don't use sprintf_vma.
	(bfd_fprintf_vma): Don't use fprintf_vma.
	* coff-rs6000.c (xcoff_reloc_type_tls): Don't use sprintf_vma.
	Instead use PRIx64 to print bfd_vma values.
	(xcoff_ppc_relocate_section): Likewise.
	* cofflink.c (_bfd_coff_write_global_sym): Likewise.
	* mmo.c (mmo_write_symbols_and_terminator): Likewise.
	* srec.c (srec_write_symbols): Likewise.
	* elf32-xtensa.c (print_r_reloc): Similarly for fprintf_vma.
	* pei-x86_64.c (pex64_dump_xdata): Likewise.
	(pex64_bfd_print_pdata_section): Likewise.
	* som.c (som_print_symbol): Likewise.
	* ecoff.c (_bfd_ecoff_print_symbol): Use bfd_fprintf_vma.
opcodes/
	* dis-buf.c (perror_memory, generic_print_address): Don't use
	sprintf_vma.  Instead use PRIx64 to print bfd_vma values.
	* i386-dis.c (print_operand_value, print_displacement): Likewise.
	* m68k-dis.c (print_base, print_indexed): Likewise.
	* ns32k-dis.c (print_insn_arg): Likewise.
	* ia64-gen.c (_opcode_int64_low, _opcode_int64_high): Delete.
	(opcode_fprintf_vma): Delete.
	(print_main_table): Use PRIx64 to print opcode.
binutils/
	* od-macho.c: Replace all uses of printf_vma with bfd_printf_vma.
	* objcopy.c (copy_object): Don't use sprintf_vma.  Instead use
	PRIx64 to print bfd_vma values.
	(copy_main): Likewise.
	* readelf.c (CHECK_ENTSIZE_VALUES): Likewise.
	(dynamic_section_mips_val): Likewise.
	(print_vma): Don't use printf_vma.  Instead use PRIx64 to print
	bfd_vma values.
	(dump_ia64_vms_dynamic_fixups): Likewise.
	(process_version_sections): Likewise.
	* rddbg.c (stab_context): Likewise.
gas/
	* config/tc-i386.c (offset_in_range): Don't use sprintf_vma.
	Instead use PRIx64 to print bfd_vma values.
	(md_assemble): Likewise.
	* config/tc-mips.c (load_register, macro): Likewise.
	* messages.c (as_internal_value_out_of_range): Likewise.
	* read.c (emit_expr_with_reloc): Likewise.
	* config/tc-ia64.c (note_register_values): Don't use fprintf_vma.
	Instead use PRIx64 to print bfd_vma values.
	(print_dependency): Likewise.
	* listing.c (list_symbol_table): Use bfd_sprintf_vma.
	* symbols.c (print_symbol_value_1): Use %p to print pointers.
	(print_binary): Likewise.
	(print_expr_1): Use PRIx64 to print bfd_vma values.
	* write.c (print_fixup): Use %p to print pointers.  Don't use
	fprintf_vma.
	* testsuite/gas/all/overflow.l: Update expected output.
	* testsuite/gas/m68k/mcf-mov3q.d: Likewise.
	* testsuite/gas/m68k/operands.d: Likewise.
	* testsuite/gas/s12z/truncated.d: Likewise.
ld/
	* deffilep.y (def_file_print): Don't use fprintf_vma.  Instead
	use PRIx64 to print bfd_vma values.
	* emultempl/armelf.em (gld${EMULATION_NAME}_finish): Don't use
	sprintf_vma.  Instead use PRIx64 to print bfd_vma values.
	* emultempl/pe.em (gld${EMULATION_NAME}_finish): Likewise.
	* ldlang.c (lang_map): Use %V to print region origin.
	(lang_one_common): Don't use sprintf_vma.
	* ldmisc.c (vfinfo): Don't use fprintf_vma or sprintf_vma.
	* pe-dll.c (pe_dll_generate_def_file): Likewise.
gdb/
	* remote.c (remote_target::trace_set_readonly_regions): Replace
	uses of sprintf_vma with bfd_sprintf_vma.
2022-08-01 13:52:18 +09:30
Dmitry Selyutin
ffd29c9c21 gas/symbols: introduce md_resolve_symbol
Assuming GMSD is a special operand, marked as O_md1, the code:

    .set VREG, GMSD
    .set REG, VREG
    extsw REG, 2

...fails upon attempts to resolve the value of the symbol. This happens
since machine-dependent values are not handled in the giant op switch.
We introduce a custom md_resolve_symbol macro; the ports can use this
macro to customize the behavior when resolve_symbol_value hits O_md
operand.
2022-07-20 12:20:14 +09:30
Alan Modra
0edfd2985b gas: use notes_calloc in string hash
Using notes_calloc means all of the string hash table memory should
now be freed before gas exits, even though htab_delete isn't called.
This also means that the hash table free_f and del_f must be NULL,
because freeing notes obstack memory results in all more recently
allocated notes memory being freed too.  So hash table resizing won't
free any memory, and will be a little faster.  Also, htab_delete won't
do anything (and be quick about it).

Since htab_traverse can also resize hash tables (to make another
traversal faster if the table is largely empty), stop that happening
when only one traversal is done.

	* as.h: Reorder hash.h after symbols.h for notes_calloc decl.
	* hash.h (str_htab_create): Use notes_calloc.  Do not free.
	* symbols.c (resolve_local_symbol_values): Don't resize
	during hash table traversal.
	* config/obj-elf.c (elf_frob_file_after_relocs): Likewise.
	* config/tc-ia64.c (ia64_adjust_symtab, ia64_frob_file): Likewise.
	* config/tc-nds32.c (nds32_elf_analysis_relax_hint): Likewise.
2022-07-09 21:47:24 +09:30
Alan Modra
b18220936c gas: free sy_hash, macro_hash and po_hash
* macro.c (macro_end): New function.
	* macro.h (macro_end): Declare.
	* read.c (read_end, poend): New functions.
	* read.h (read_end): Declare.
	* symbols.c (symbol_end): New function.
	* symbols.h (symbol_end): Declare.
	* output-file.c (output_file_close): Call new *_end functions.
2022-07-09 21:22:28 +09:30
Alan Modra
c30081c1f9 gas: utility notes memory alloc functions
Makes it a little easier to use the notes obstack for persistent
storage.

	* as.h (gas_mul_overflow): Define.
	* symbols.h (notes_alloc, notes_calloc, notes_memdup),
	(notes_strdup, notes_concat, notes_free): Declare.
	* symbols.c (notes_alloc, notes_calloc, notes_memdup),
	(notes_strdup, notes_concat, notes_free): New functions.
	(save_symbol_name): Use notes_strdup.
	(symbol_create, local_symbol_make, local_symbol_convert),
	(symbol_clone, decode_local_label_name): Use notes_alloc.
2022-07-09 21:15:30 +09:30
Alan Modra
6015985895 Replace bfd_hostptr_t with uintptr_t
bfd_hostptr_t is defined as a type large enough to hold either a long
or a pointer.  It mostly appears in the coff backend code in casts.
include/coff/internal.h struct internal_syment and union
internal_auxent have the only uses in data structures, where
comparison with include/coff/external.h and other code reveals that
the type only needs to be large enough for a 32-bit integer or a
pointer.  That should mean replacing with uintptr_t is OK.
2022-05-27 22:08:59 +09:30
Mark Harmstone
145667f8d9 Add support for COFF secidx relocations
bfd	* coff-i386.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_i386_relocation_section): Add support for R_SECTION.
	(coff_i386_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* coff-x86_64.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_amd64_relocation_section): Add support for R_SECTION.
	(coff_amd64_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* reloc.c: Add BFD_RELOC_16_SECIDX.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

gas	* config/tc-i386.c (pe_directive_secidx): New function.
	(md_pseudo_table): Add support for secidx.
	(x86_cons_fix_new): Likewise.
	(tc_gen_reloc): Likewise.
	* expr.c (op_rank): Add O_secidx.
	* expr.h (operatorT): Likewise.
	* symbols.c (resolve_symbol_value): Add support for O_secidx.
	* testsuite/gas/i386/secidx.s: New test source file.
	* testsuite/gas/i386/secidx.d: New test driver file.
	* testsuite/gas/i386/i386.exp: Run new test.

include	* coff/i386.h: Define R_SECTION.
	* coff/x86_64.h: Likewise.

ld	* testsuite/ld-pe/secidx1.s: New test source file.
	* testsuite/ld-pe/secidx2.s: New test source file.
	* testsuite/ld-pe/secidx.d: New test driver file.
	* testsuite/ld-pe/secidx_64.d: New test driver file.
	* testsuite/ld-pe/pe.exp: Add new tests.
2022-04-07 14:47:17 +01:00
Alan Modra
4afc889439 Reduce duplicated symbol_clone_if_forward_ref work
* symbol.c (struct symbol_flags): Add forward_resolved.
	(symbol_entry_find): Update needle initialisation.
	(symbol_clone_if_forward_ref): Do no work when forward_resolved
	is already set.  Set forward_resolved.
2022-03-09 14:10:00 +10:30
Alan Modra
19f7966ede gas local label and dollar label handling
Much of the gas source and older BFD source use "long" for function
parameters and variables, when other types would be more appropriate.
This patch fixes one of those cases.  Dollar labels and numeric local
labels do not need large numbers.  Small positive itegers are usually
all that is required.  Due to allowing longs, it was possible for
fb_label_name and dollar_label_name to overflow their buffers.

	* symbols.c: Delete unnecessary forward declarations.
	(dollar_labels, dollar_label_instances): Use unsigned int.
	(dollar_label_defined, dollar_label_instance): Likewise.
	(define_dollar_label): Likewise.
	(fb_low_counter, fb_labels, fb_label_instances): Likewise.
	(fb_label_instance_inc, fb_label_instance): Likewise.
	(fb_label_count, fb_label_max): Make them size_t.
	(dollar_label_name, fb_label_name): Rewrite using sprintf.
	* symbols.h (dollar_label_defined): Update prototype.
	(define_dollar_label, dollar_label_name): Likewise.
	(fb_label_instance_inc, fb_label_name): Likewise.
	* config/bfin-lex.l (yylex): Remove unnecessary casts.
	* expr.c (integer_constant): Likewise.
	* read.c (read_a_source_file): Limit numeric label range to int.
2022-02-16 22:05:24 +10:30
Alan Modra
a2c5833233 Update year range in copyright notice of binutils files
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.
2022-01-02 12:04:28 +10:30
Nick Clifton
578c64a45a Add multibyte character warning option to the assembler.
* as.c (parse_args): Add support for --multibyte-handling.
	* as.h (multibyte_handling): Declare.
	* app.c (scan_for_multibyte_characters): New function.
	(do_scrub_chars): Call the new function if multibyte warning is
	enabled.
	* input-scrub,c (input_scrub_next_buffer): Call the multibyte
	scanning function if multibyte warnings are enabled.
	* symbols.c (struct symbol_flags): Add multibyte_warned bit.
	(symbol_init): Call the multibyte scanning function if multibyte
	symbol warnings are enabled.
	(S_SET_SEGMENT): Likewise.
	* NEWS: Mention the new feature.
	* doc/as.texi: Document the new feature.
	* testsuite/gas/all/multibyte.s: New test source file.
	* testsuite/gas/all/multibyte1.d: New test driver file.
	* testsuite/gas/all/multibyte1.l: New test expected output.
	* testsuite/gas/all/multibyte2.d: New test driver file.
	* testsuite/gas/all/multibyte2.l: New test expected output.
	* testsuite/gas/all/gas.exp: Run the new tests.
2021-11-18 16:48:19 +00:00
H.J. Lu
eb09df162b as: Replace the removed symbol with the versioned symbol
When a symbol removed by .symver is used in relocation and there is one
and only one versioned symbol, don't remove the symbol.  Instead, mark
it to be removed and replace the removed symbol used in relocation with
the versioned symbol before generating relocation.

	PR gas/28157
	* symbols.c (symbol_flags): Add removed.
	(symbol_entry_find): Updated.
	(symbol_mark_removed): New function.
	(symbol_removed_p): Likewise.
	* symbols.h (symbol_mark_removed): New prototype.
	(symbol_removed_p): Likewise.
	* write.c (write_relocs): Call obj_fixup_removed_symbol on
	removed fixp->fx_addsy and fixp->fx_subsy if defined.
	(set_symtab): Don't add a symbol if symbol_removed_p returns true.
	* config/obj-elf.c (elf_frob_symbol):  Don't remove the symbol
	if it is used on relocation.  Instead, mark it as to be removed
	and issue an error if the symbol has more than one versioned name.
	(elf_fixup_removed_symbol): New function.
	* config/obj-elf.h (elf_fixup_removed_symbol): New prototype.
	(obj_fixup_removed_symbol): New.
	* testsuite/gas/symver/symver11.d: Updated expected error
	message.
	* testsuite/gas/symver/symver16.d: New file.
	* testsuite/gas/symver/symver16.s: Likewise.
2021-08-16 06:46:44 -07:00
Clément Chigot
cd026728f3 gas: improve C_BSTAT and C_STSYM symbols handling on XCOFF
A C_BSTAT debug symbol specifies the beginning of a static block.
Its n_value is the index of the csect containing static symbols.
A C_STSYM debug symbol represents the stabstring of a statically
allocated symbol. Its n_value is the offset in the csect pointed
by the containing C_BSTAT.

These two special n_value were not correctly handled both when
generating object files with gas or when reading them with objdump.
This patch tries to improve that and, above all, to allow gas-generated
object files with such symbols to be accepted by AIX ld.

bfd/
	* coff-bfd.c (bfd_coff_get_syment): Adjust n_value of symbols
	having fix_value = 1 in order to be an index and not a memory
	offset.
	* coffgen.c (coff_get_symbol_info): Likewize.
	(coff_print_symbol): Likewize.

gas/
	* config/tc-ppc.c (ppc_frob_label): Don't change within if
	already set.
	(ppc_stabx): Remove workaround changing exp.X_add_symbol's
	within.
	* config/tc-ppc.h (struct ppc_tc_sy): Update comments.
	* symbols.c (resolve_symbol_value): Remove symbol update
	when final_val is 0 and it's an AIX debug symbol.
	* testsuite/gas/ppc/aix.exp: Add new tests.
	* testsuite/gas/ppc/xcoff-stsym-32.d: New test.
	* testsuite/gas/ppc/xcoff-stsym-64.d: New test.
	* testsuite/gas/ppc/xcoff-stsym.s: New test.
2021-07-29 10:55:22 +02:00
Alan Modra
23d613801d C99 gas configury
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-05 15:31:25 +09:30
Alan Modra
5b7c81bd8c Use bool in gas
* 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-03-31 10:49:23 +10:30
Alan Modra
dd933805d1 PR27102, gas: "section symbols are already global"
PR 27102
	* symbols.c (S_SET_EXTERNAL): Revise section symbol warning
	message and register symbol error message.
2021-01-04 18:58:15 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Alan Modra
e37c930f9e gcc-4.4.7 warning fixes
* config/obj-elf.c (obj_elf_change_section): Rename variable to
	avoid shadowing warning.
	* symbols.c (symbol_entry_find): Init all symbol_flags fields.
2020-09-30 14:31:15 +09:30
Alan Modra
d8d6da137d PR26448 UBSAN: symbols.c:1586 left shift of negative value
Besides avoiding the UB, this also makes right shifts inside
expression symbols unsigned, consistent with the way gas evaluates
expressions in source.

	PR 26448
	* symbols.c: Include limits.h.
	(resolve_symbol_value <O_left_shift, O_right_shift>): Do an
	unsigned shift.  Warn if shift count larger than valueT size.
2020-08-26 23:23:44 +09:30
Alan Modra
30b940a097 PR26410, UBSAN: symbols.c:1818
Don't memset(0,0,0).

	PR 26410
	* symbols.c (dollar_label_count, dollar_label_max): Make size_t.
	(dollar_label_clear): Don't call memset with NULL pointer.
2020-08-25 23:07:10 +09:30
Alan Modra
85d14aaeb7 PR26526, 5014c2d22b breaks compiling the Linux kernel for ARM
PR 26526
	* symbols.c (local_symbol_convert): Clear out xtra.
2020-08-24 13:09:53 +09:30
Alan Modra
fe0e921f00 PR26513, 629310abec breaks assembling PowerPC Linux kernels
Inserting with replacement is wrong for some gas hash table uses.
This patch implements an htab_insert that conditionally replaces, and
similarly for str_hash_insert.  str_hash_insert with replace=0 is
roughly equivalent to the older hash_insert, and str_hash_insert with
replace=1 to the older hash_jam, but return values are different.  I
found it useful to know whether the slot was occupied prior to
inserting/replacing.  I've also reinstated the fatal errors on messing
up opcode tables with duplicates.

	PR 26513
	* hash.h (htab_insert): Update prototype and comment.
	(struct string_tuple): Make "value" a const void*.
	(string_tuple_alloc): Likewise.
	(str_hash_find, str_hash_find_n): Cast returned value.
	(str_hash_insert): Add "replace" parameter, and return slot pointer.
	Free alloc'd element when not inserted.
	* hash.c (htab_insert): Likewise.  Return slot when element exists,
	otherwise return NULL.
	* read.c (pop_insert): Insert into hash table without first searching.
	* config/tc-avr.c (md_begin): Likewise.
	* config/tc-msp430.c (md_begin): Likewise.
	* config/tc-nds32.c (nds32_init_nds32_pseudo_opcodes): Likewise.
	* config/tc-v850.c (md_begin): Likewise.
	* macro.c (do_formals, define_macro, macro_expand_body): Likewise.
	(delete_macro): Delete from hash table.
	* config/tc-tic54x.c (subsym_create_or_replace): Correct logic.

	* symbols.c (local_symbol_make, symbol_table_insert): Allow
	replacement of hash table entries.
	* config/obj-coff-seh.c (seh_hash_insert): Likewise.
	* config/obj-coff.c (tag_insert): Likewise.
	* config/tc-iq2000.c (iq2000_add_macro): Likewise.
	* config/tc-m68k.c (md_begin): Likewise for aliases.
	* config/tc-tic4x.c (tic4x_asg): Likewise.
	* config/tc-tic6x.c (md_begin): Likewise.

	* dw2gencfi.c (dwcfi_hash_find_or_make): Disallow replacement of
	hash table entries.
	* ecoff.c (add_string, get_tag): Likewise.
	* macro.c (expand_irp): Likewise.
	* config/obj-elf.c (build_additional_section_info): Likewise.
	* config/tc-aarch64.c (insert_reg_alias): Likewise.
	(checked_hash_insert): Likewise.
	* config/tc-alpha.c (get_alpha_reloc_tag, md_begin): Likewise.
	* config/tc-arc.c (arc_insert_opcode, declare_register): Likewise.
	(declare_addrtype, md_begin, arc_extcorereg): Likewise.
	* config/tc-arm.c (insert_reg_alias): Likewise.
	(arm_tc_equal_in_insn, md_begin): Likewise.
	* config/tc-cr16.c (initialise_reg_hash_table, md_begin): Likewise.
	* config/tc-cris.c (md_begin): Likewise.
	* config/tc-crx.c (md_begin): Likewise.
	* config/tc-csky.c (md_begin): Likewise.
	* config/tc-d10v.c (md_begin): Likewise.
	* config/tc-dlx.c (md_begin): Likewise.
	* config/tc-ft32.c (md_begin): Likewise.
	* config/tc-h8300.c (md_begin): Likewise.
	* config/tc-hppa.c (md_begin): Likewise.
	* config/tc-i386.c (md_begin): Likewise.
	* config/tc-ia64.c (dot_rot, dot_entry, declare_register): Likewise.
	(md_begin, dot_alias): Likewise.
	* config/tc-m68hc11.c (md_begin): Likewise.
	* config/tc-m68k.c (md_begin): Likewise.
	* config/tc-mcore.c (md_begin): Likewise.
	* config/tc-microblaze.c (md_begin): Likewise.
	* config/tc-mips.c (md_begin): Likewise.
	* config/tc-mmix.c (md_begin): Likewise.
	* config/tc-mn10200.c (md_begin): Likewise.
	* config/tc-mn10300.c (md_begin): Likewise.
	* config/tc-moxie.c (md_begin): Likewise.
	* config/tc-nds32.c (nds32_relax_hint, md_begin): Likewise.
	* config/tc-nios2.c (md_begin): Likewise.
	* config/tc-ns32k.c (md_begin): Likewise.
	* config/tc-pdp11.c (md_begin): Likewise.
	* config/tc-pj.c (fake_opcode, md_begin): Likewise.
	* config/tc-ppc.c (ppc_setup_opcodes): Likewise.
	* config/tc-pru.c (md_begin): Likewise.
	* config/tc-riscv.c (init_ext_version_hash): Likewise.
	(init_opcode_names_hash, hash_reg_name, init_opcode_hash): Likewise.
	(riscv_init_csr_hash): Likewise.
	* config/tc-s390.c (s390_setup_opcodes, md_begin): Likewise.
	* config/tc-score.c (s3_insert_reg): Likewise.
	(s3_build_score_ops_hsh, s3_build_dependency_insn_hsh): Likewise.
	* config/tc-score7.c (s7_build_score_ops_hsh): Likewise.
	(s7_build_dependency_insn_hsh, s7_insert_reg): Likewise.
	* config/tc-sh.c (md_begin): Likewise.
	* config/tc-sparc.c (md_begin): Likewise.
	* config/tc-spu.c (md_begin): Likewise.
	* config/tc-tic30.c (md_begin): Likewise.
	* config/tc-tic4x.c (tic4x_inst_insert): Likewise.
	* config/tc-tic54x.c (stag_add_field_symbols, md_begin): Likewise.
	(tic54x_endstruct, tic54x_var, tic54x_macro_info): Likewise.
	(subsym_substitute): Likewise.
	* config/tc-tilegx.c (md_begin): Likewise.
	* config/tc-tilepro.c (md_begin): Likewise.
	* config/tc-vax.c (vip_begin): Likewise.
	* config/tc-wasm32.c (md_begin): Likewise.
	* config/tc-xgate.c (md_begin): Likewise.
	* config/tc-z8k.c (md_begin): Likewise.
	* testsuite/gas/ppc/dcbt.d,
	* testsuite/gas/ppc/dcbt.s: New test.
	* testsuite/gas/ppc/ppc.exp: Run it.

	* ecoff.c (add_string): Report fatal error on duplicates.
	* config/tc-alpha.c (md_begin): Likewise.
	* config/tc-arc.c (arc_insert_opcode, declare_register): Likewise.
	(declare_addrtype, md_begin, arc_extcorereg): Likewise.
	* config/tc-cr16.c (initialise_reg_hash_table, md_begin): Likewise.
	* config/tc-cris.c (md_begin): Likewise.
	* config/tc-crx.c (md_begin): Likewise.
	* config/tc-dlx.c (md_begin): Likewise.
	* config/tc-hppa.c (md_begin): Likewise.
	* config/tc-i386.c (md_begin): Likewise.
	* config/tc-ia64.c (dot_rot, dot_entry, declare_register): Likewise.
	(md_begin): Likewise.
	* config/tc-m68k.c (md_begin): Likewise.
	* config/tc-mips.c (md_begin): Likewise.
	* config/tc-nios2.c (md_begin): Likewise.
	* config/tc-ns32k.c (md_begin): Likewise.
	* config/tc-ppc.c (ppc_setup_opcodes): Likewise.
	* config/tc-pru.c (md_begin): Likewise.
	* config/tc-riscv.c (init_ext_version_hash): Likewise.
	(init_opcode_names_hash, hash_reg_name, init_opcode_hash): Likewise.
	* config/tc-s390.c (s390_setup_opcodes, md_begin): Likewise.
	* config/tc-sparc.c (md_begin): Likewise.
	* config/tc-tic30.c (md_begin): Likewise.
	* config/tc-tic4x.c (tic4x_inst_insert): Likewise.
	* config/tc-tilegx.c (md_begin): Likewise.
	* config/tc-tilepro.c (md_begin): Likewise.
	* config/tc-vax.c (vip_begin): Likewise.

	* config/tc-alpha.c,
	* config/tc-arm.c,
	* config/tc-avr.c,
	* config/tc-cr16.c,
	* config/tc-csky.c,
	* config/tc-i386.c,
	* config/tc-m68hc11.c,
	* config/tc-m68k.c,
	* config/tc-microblaze.c,
	* config/tc-ns32k.c,
	* config/tc-pj.c,
	* config/tc-ppc.c,
	* config/tc-score.c,
	* config/tc-score7.c,
	* config/tc-tic4x.c,
	* config/tc-tic54x.c,
	* config/tc-tilegx.c,
	* config/tc-tilepro.c,
	* config/tc-xgate.c: Formatting.
2020-08-23 21:38:05 +09:30
Alan Modra
5014c2d22b Redo gas local symbol support
gas handles local symbols specially in order to save memory, but the
implementation using two separate hash tables is inefficient,
particularly the scheme of duplicating a struct local_symbol when it
needs to be converted to a full struct symbol.  Also, updating symbol
pointers with LOCAL_SYMBOL_CHECK is horrible and has led to some hard
to find bugs.

This changes the implementation to use a single hash table and avoids
another copy of the symbol name in symbol_entry_t.  When converting
local symbols the struct local_symbol memory is reused.  Not only
does that save memory, but there is no need to twiddle symbol pointers
with LOCAL_SYMBOL_CHECK.

Assembling gcc-10 -g -Og gold/powerpc.cc output shows the following:

old:
symbol table hash statistics:
	1371192 searches
	1290398 collisions
	143585 elements
	262139 table size
mini local symbol table hash statistics:
	2966204 searches
	2707489 collisions
	523533 elements
	1048573 table size
523533 mini local symbols created, 140453 converted

new:
symbol table hash statistics:
	2828883 searches
	2453138 collisions
	526665 elements
	1048573 table size
523533 mini local symbols created, 140453 converted

	* symbols.c (struct local_symbol): Add "hash" entry.  Reorder fields.
	Delete union.  Adjust code throughout file.
	(struct symbol): Add "hash", "name" and "x" entries.  Reorder fields.
	Split off some to..
	(struct xsymbol): ..this.  New struct.  Adjust code throughout file
	accessing these fields.
	(struct symbol_entry): Delete.
	(union symbol_entry): New.
	(hash_symbol_entry): Adjust for symbol_entry_t change.
	(symbol_entry_find): Likewise.
	(eq_symbol_entry): Compare hash values too.
	(symbol_entry_alloc): Delete.
	(local_symbol_converted_p, local_symbol_mark_converted): Delete.
	(local_symbol_get_real_symbol, local_symbol_set_real_symbol): Delete.
	(local_hash): Delete.
	(abs_symbol_x, dot_symbol_x): New static var.
	(symbol_init): New function.
	(symbol_create): Rewrite.
	(LOCAL_SYMBOL_CHECK): Delete.  Replace uses throughout with simple
	test of flags.local_symbol.
	(local_symbol_make): Adjust for struct local_symbol changes.
	(local_symbol_convert): Rewrite.  Adjust all callers.
	(symbol_table_insert): Simplify.
	(symbol_clone): Comment on local sym cloning.  Handle split symbol
	struct.
	(get_real_sym): Delete.  Remove all uses.
	(symbol_find_exact_noref): Simplify.
	(resolve_local_symbol): Don't resolve non-locals.
	(S_SET_SEGMENT): Don't special case reg_section.
	(S_SET_NAME): Set both name and bsym->name.
	(symbol_mark_resolved, symbol_resolved_p): Simplify.
	(symbol_symbolS): Update comment.
	(symbol_begin): Don't create local_hash.  Adjust abs_symbol setup.
	(dot_symbol_init): Adjust dot_symbol setup.
	(symbol_print_statistics): Delete local_hash stats.
2020-08-21 18:39:54 +09:30
Alan Modra
3c0d9d71db gas symbol struct field renaming
Get rid of sy_ prefix, and some unused fields.

	* symbols.c (struct symbol_flags): Rename sy_volatile to volatil,
	and remove sy_ from other field names.  Update throughout.
	(struct symbol): Remove sy_ from field names.  Delete unused
	TARGET_SYMBOL_FIELDS.  Update throughout file.  Move after..
	(struct local_symbol): ..here.  Remove lsy_ from field names.
	Delete unused TC_LOCAL_SYMFIELD_TYPE.  Update throughout file.
	(local_symbol_resolved_p, local_symbol_mark_resolved): Delete.
	Expand uses throughout file.
	(local_symbol_get_frag, local_symbol_set_frag): Likewise.
	(symbol_new): Move symbol_table_frozen test to..
	(symbol_append): ..here, and..
	(symbol_insert): ..here.
	(resolve_symbol_value, symbol_relc_make_expr): White space fixes.
	(HANDLE_XADD_OPT1, HANDLE_XADD_OPT2): Likewise.
	* config/obj-coff.h (RESOLVE_SYMBOL_REDEFINITION): Update.
2020-08-21 18:39:23 +09:30
Alan Modra
e01e1cee39 Rearrange symbol_create parameters
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-21 18:26:35 +09:30
Martin Liska
d3b740ca99 Use libiberty hash in gas/symbols.c.
* symbols.c (struct symbol_entry): New.
	(hash_symbol_entry): Likewise.
	(eq_symbol_entry): Likewise.
	(symbol_entry_alloc): Likewise.
	(symbol_entry_find): Likewise.
	(local_symbol_make): Use htab hash table.
	(local_symbol_convert): Likewise.
	(symbol_table_insert): Likewise.
	(symbol_find_exact_noref): Likewise.
	(resolve_local_symbol): Likewise.
	(resolve_local_symbol_values): Likewise.
	(symbol_begin): Likewise.
	(symbol_print_statistics): Likewise.
2020-08-20 10:56:07 +09:30
Alan Modra
9fbb53c7c8 Replace "if (x) free (x)" with "free (x)", gas
* atof-generic.c: Replace "if (x) free (x)" with "free (x)"
	throughout.
	* config/obj-elf.c: Likewise.
	* config/tc-aarch64.c: Likewise.
	* config/tc-arm.c: Likewise.
	* config/tc-m68k.c: Likewise.
	* config/tc-nios2.c: Likewise.
	* config/tc-tic30.c: Likewise.
	* ecoff.c: Likewise.
	* read.c: Likewise.
	* stabs.c: Likewise.
	* symbols.c: Likewise.
	* testsuite/gas/all/test-gen.c: Likewise.
2020-05-21 10:45:33 +09:30
Alan Modra
0e1d094e96 Clear all local_symbol.lsy_flags
* symbols.c (local_symbol_make): Init all of lsy_flags.
2020-05-19 10:51:04 +09:30
Alan Modra
d402189f2f Re: Fix tight loop on recursively-defined symbols
sy_resolving ought to not be set for a struct local_symbol, but it is
apparent from local_symbol_make that the field is not initialised.

	* symbols.c (resolve_symbol_value): Invoke LOCAL_SYMBOL_CHECK
	before looking at add_symbol->sy_flags.sy_resolving.
2020-05-18 13:46:27 +09:30
Alan Modra
2a50b40146 Fix tight loop on recursively-defined symbols
This patch fixes a bug in GAS where the assembler enters a tight loop
when attempting to resolve recursively-defined symbols, e.g. when
trying to assemble "a=a".

This is a regression introduced between binutils 2.32 and 2.33,
by commit 1903f1385b

	* symbols.c (struct local_symbol): Update comment.
	(resolve_symbol_value): For resolved symbols equated to other
	symbols, verify that the referenced symbol is not a local_symbol
	before accessing sy_value.  Don't leave symbol loops during
	finalize_syms resolution.
	* testsuite/gas/all/assign-bad-recursive.d: New test.
	* testsuite/gas/all/assign-bad-recursive.l: Error output for test.
	* testsuite/gas/all/assign-bad-recursive.s: Assembly for test.
	* testsuite/gas/all/gas.exp: Run it.
2020-05-15 18:21:07 +09:30
Alan Modra
dc1e8a474f Indent labels
Labels don't go in the first column according to standard emacs C
indent rules, and I got annoyed enough at seeing diff -p show a label
rather than the function name to fix this.

bfd/
	* aoutx.h: Indent labels correctly.  Format error strings.
	* archive.c: Likewise.
	* archive64.c: Likewise.
	* coff-arm.c: Likewise.
	* coff-rs6000.c: Likewise.
	* coff-stgo32.c: Likewise.
	* cpu-arm.c: Likewise.
	* dwarf2.c: Likewise.
	* elf-ifunc.c: Likewise.
	* elf-properties.c: Likewise.
	* elf-s390-common.c: Likewise.
	* elf-strtab.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-bfin.c: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-csky.c: Likewise.
	* elf32-i386.c: Likewise.
	* elf32-m68k.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-nds32.c: Likewise.
	* elf32-nios2.c: Likewise.
	* elf32-pru.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-ia64-vms.c: Likewise.
	* elf64-x86-64.c: Likewise.
	* elfcode.h: Likewise.
	* elfcore.h: Likewise.
	* elflink.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfnn-ia64.c: Likewise.
	* elfnn-riscv.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-x86.c: Likewise.
	* i386lynx.c: Likewise.
	* merge.c: Likewise.
	* pdp11.c: Likewise.
	* plugin.c: Likewise.
	* reloc.c: Likewise.
binutils/
	* elfedit.c: Indent labels correctly.
	* readelf.c: Likewise.
	* resres.c: Likewise.
gas/
	* config/obj-elf.c: Indent labels correctly.
	* config/obj-macho.c: Likewise.
	* config/tc-aarch64.c: Likewise.
	* config/tc-alpha.c: Likewise.
	* config/tc-arm.c: Likewise.
	* config/tc-cr16.c: Likewise.
	* config/tc-crx.c: Likewise.
	* config/tc-frv.c: Likewise.
	* config/tc-i386-intel.c: Likewise.
	* config/tc-i386.c: Likewise.
	* config/tc-ia64.c: Likewise.
	* config/tc-mn10200.c: Likewise.
	* config/tc-mn10300.c: Likewise.
	* config/tc-nds32.c: Likewise.
	* config/tc-riscv.c: Likewise.
	* config/tc-s12z.c: Likewise.
	* config/tc-xtensa.c: Likewise.
	* config/tc-z80.c: Likewise.
	* read.c: Likewise.
	* symbols.c: Likewise.
	* write.c: Likewise.
ld/
	* emultempl/cskyelf.em: Indent labels correctly.
	* ldfile.c: Likewise.
	* ldlang.c: Likewise.
	* plugin.c: Likewise.
opcodes/
	* aarch64-asm.c: Indent labels correctly.
	* aarch64-dis.c: Likewise.
	* aarch64-gen.c: Likewise.
	* aarch64-opc.c: Likewise.
	* alpha-dis.c: Likewise.
	* i386-dis.c: Likewise.
	* nds32-asm.c: Likewise.
	* nfp-dis.c: Likewise.
	* visium-dis.c: Likewise.
2020-02-26 10:37:25 +10:30
Alan Modra
b3adc24a07 Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
Christian Eggers
618265039f Introduce new section flag: SEC_ELF_OCTETS
All symbols, sizes and relocations in this section are octets instead of
bytes.  Required for DWARF debug sections as DWARF information is
organized in octets, not bytes.

bfd/
	* section.c (struct bfd_section): New flag SEC_ELF_OCTETS.
	* archures.c (bfd_octets_per_byte): New parameter sec.
	If section is not NULL and SEC_ELF_OCTETS is set, one octet es
	returned [ELF targets only].
	* bfd.c (bfd_get_section_limit): Provide section parameter to
	bfd_octets_per_byte.
	* bfd-in2.h: regenerate.
	* binary.c (binary_set_section_contents): Move call to
	bfd_octets_per_byte into section loop. Provide section parameter
	to bfd_octets_per_byte.
	* coff-arm.c (coff_arm_reloc): Provide section parameter
	to bfd_octets_per_byte.
	* coff-i386.c (coff_i386_reloc): likewise.
	* coff-mips.c (mips_reflo_reloc): likewise.
	* coff-x86_64.c (coff_amd64_reloc): likewise.
	* cofflink.c (_bfd_coff_link_input_bfd): likewise.
	(_bfd_coff_reloc_link_order): likewise.
	* elf.c (_bfd_elf_section_offset): likewise.
	(_bfd_elf_make_section_from_shdr): likewise.
	Set SEC_ELF_OCTETS for sections with names .gnu.build.attributes,
	.debug*, .zdebug* and .note.gnu*.
	* elf32-msp430.c (rl78_sym_diff_handler): Provide section parameter
	to bfd_octets_per_byte.
	* elf32-nds.c (nds32_elf_get_relocated_section_contents): likewise.
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): likewise.
	* elf32-pru.c (pru_elf32_do_ldi32_relocate): likewise.
	* elf32-s12z.c (opru18_reloc): likewise.
	* elf32-sh.c (sh_elf_reloc): likewise.
	* elf32-spu.c (spu_elf_rel9): likewise.
	* elf32-xtensa.c (bfd_elf_xtensa_reloc): likewise
	* elf64-ppc.c (ppc64_elf_brtaken_reloc): likewise.
	(ppc64_elf_addr16_ha_reloc): likewise.
	(ppc64_elf_toc64_reloc): likewise.
	* elflink.c (bfd_elf_final_link): likewise.
	(bfd_elf_perform_complex_relocation): likewise.
	(elf_fixup_link_order): likewise.
	(elf_link_input_bfd): likewise.
	(elf_link_sort_relocs): likewise.
	(elf_reloc_link_order): likewise.
	(resolve_section): likewise.
	* linker.c (_bfd_generic_reloc_link_order): likewise.
	(bfd_generic_define_common_symbol): likewise.
	(default_data_link_order): likewise.
	(default_indirect_link_order): likewise.
	* srec.c (srec_set_section_contents): likewise.
	(srec_write_section): likewise.
	* syms.c (_bfd_stab_section_find_nearest_line): likewise.
	* reloc.c (_bfd_final_link_relocate): likewise.
	(bfd_generic_get_relocated_section_contents): likewise.
	(bfd_install_relocation): likewise.
	For section which have SEC_ELF_OCTETS set, multiply output_base
	and output_offset with bfd_octets_per_byte.
	(bfd_perform_relocation): likewise.
include/
	* coff/ti.h (GET_SCNHDR_SIZE, PUT_SCNHDR_SIZE, GET_SCN_SCNLEN),
	(PUT_SCN_SCNLEN): Adjust bfd_octets_per_byte calls.
binutils/
	* objdump.c (disassemble_data): Provide section parameter to
	bfd_octets_per_byte.
	(dump_section): likewise
	(dump_section_header): likewise. Show SEC_ELF_OCTETS flag if set.
gas/
	* as.h: Define SEC_OCTETS as SEC_ELF_OCTETS if OBJ_ELF.
	* dwarf2dbg.c: (dwarf2_finish): Set section flag SEC_OCTETS for
	.debug_line, .debug_info, .debug_abbrev, .debug_aranges, .debug_str
	and .debug_ranges sections.
	* write.c (maybe_generate_build_notes): Set section flag
	SEC_OCTETS for .gnu.build.attributes section.
	* frags.c (frag_now_fix): Don't divide by OCTETS_PER_BYTE if
	SEC_OCTETS is set.
	* symbols.c (resolve_symbol_value): Likewise.
ld/
	* ldexp.c (fold_name): Provide section parameter to
	bfd_octets_per_byte.
	* ldlang (init_opb): New argument s. Set opb_shift to 0 if
	SEC_ELF_OCTETS for the current section is set.
	(print_input_section): Pass current section to init_opb.
	(print_data_statement,print_reloc_statement,
	print_padding_statement): Likewise.
	(lang_check_section_addresses): Call init_opb for each
	section.
	(lang_size_sections_1,lang_size_sections_1,
	lang_do_assignments_1): Likewise.
	(lang_process): Pass NULL to init_opb.
2019-11-25 14:32:19 +10:30
Christian Eggers
e2b9a97eda Reverts patches providing octet support in dwarf
Reverts "dwarf2: Align relocation within .debug_line section"
	commit 204f543cae,
Reverts "dwarf2: Pad size of .debug_line section."
	commit 145c4477d2,
Reverts "dwarf2: Use octets for .debug_line prologue"
	commit 38c24f42c9,
Mostly reverts "dwarf2: Use octets for dwarf2 headers"
	commit 7235427998,
Mostly reverts "Symbols with octets value"
	commit d18d199917.

	* dwarf2dbg.c (out_set_addr): Revert 2019-03-13 change.
	(out_debug_line, out_debug_aranges, out_debug_info): Likewise.
	* symbols.h (symbol_set_value_now_octets, symbol_octets_p): Remove.
	* symbols.c (struct symbol_flags): Remove member sy_octets.
	(symbol_temp_new_now_octets): Don't set symbol_flags::sy_octets.
	(resolve_symbol_value): Revert: Return octets instead of bytes if
	sy_octets is set.
	(symbol_set_value_now_octets): Remove.
	(symbol_octets_p): Remove.
2019-11-25 14:32:20 +10:30
Alan Modra
e6f7f6d14f bfd_asymbol_* macros
The main point of this patch is to give bfd_get_section a better name,
bfd_asymbol_section.

bfd/
	* bfd-in.h (bfd_asymbol_section): Rename from bfd_get_section.
	(bfd_get_output_section): Delete.
	(bfd_asymbol_base): Delete.
	(bfd_asymbol_section, bfd_asymbol_value, bfd_asymbol_name),
	(bfd_asymbol_bfd, bfd_asymbol_flavour): Tidy.
	(bfd_set_asymbol_name): New macro.
	* bfd-in2.h: Regenerate.
	* aout-cris.c: Update throughout to use bfd_asymbol_section.
	* aoutx.h: Likewise.
	* cofflink.c: Likewise.
	* dwarf2.c: Likewise.
	* ecoff.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-mips.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elfn32-mips.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* elf64-mmix.c (mmix_elf_reloc): Expand bfd_get_output_section.
binutils/
	* nm.c: Update bfd_get_section to bfd_asymbol_section throughout.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* rdcoff.c: Likewise.
	* objcopy.c (create_new_symbol): Use bfd_set_asymbol_name.
	(filter_symbols): Likewise.
gas/
	* symbols.c (S_IS_LOCAL): Update bfd_get_section to
	bfd_asymbol_section.
gdb/
	* arm-tdep.c (arm_record_special_symbol): Update bfd_get_section
	to bfd_asymbol_section.
ld/
	* ldcref.c (check_reloc_refs): Update bfd_get_section to
	bfd_asymbol_section.
2019-09-18 23:07:31 +09:30
Alan Modra
0f1309c8f7 Tidy use_complex_relocs_for
Since I was looking at this I decided to fix the formatting, and
used an old C switch statements trick to factor out common code.

	* symbols.c (use_complex_relocs_for): Formatting.  Factor out
	X_add_symbol tests.
2019-05-07 15:35:53 +09:30