Commit Graph

145 Commits

Author SHA1 Message Date
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
Nick Clifton
6f56739807 Allow the use of SOURCE_DATE_EPOCH in the timestamps for members of static archives.
(For some reason this commit was not applied at the time that the patch was approved).
2023-09-26 14:07:23 +01:00
Alan Modra
e416bd75c3 warn unused result for bfd IO functions
This patch fixes all the warnings I found in bfd, binutils and ld,
plus some bitrotted COFF_GO32 code that tried to allocate -168ul
bytes.  When the malloc fail was reported these testsuite fails
resulted:

i386-go32  +FAIL: go32 stub
i386-go32  +ERROR: tcl error sourcing /home/alan/src/binutils-gdb/ld/testsuite/ld-i386/i386.exp.
i386-go32  +ERROR: couldn't open "tmpdir/go32stub": no such file or directory
i386-go32  +FAIL: ld-scripts/sane1
i386-go32  +FAIL: ld-scripts/assign-loc
i386-go32  +FAIL: ld-scripts/pr18963

This does result in some warnings in gdb which are fixed in a followup
patch.

bfd/
	* bfdio.c (bfd_read, bfd_write): Add ATTRIBUTE_WARN_UNUSED_RESULT.
	(bfd_tell, bfd_stat, bfd_seek, bfd_mmap): Likewise.
	* bfd-in2.h: Regenerate.
	* coff-rs6000.c (xcoff_write_armap_big) Don't ignore bfd_write
	return value.
	(xcoff_generate_rtinit): Likewise.  Also free data_buffer and
	string_table before returning.
	* coff64-rs6000.c (xcoff64_generate_rtinit): Likewise.
	* coff-stgo32.c (go32exe_check_format): Don't ignore bfd_seek
	return value.
	* coffcode.h (coff_apply_checksum): Don't ignore bfd_write return.
	(coff_write_object_contents <COFF_GO32>): Likewise, and bfd_malloc.
	Fix bitrotted code to look for first section with non-zero filepos.
	* elf64-ia64-vms.c (elf64_vms_write_shdrs_and_ehdr): Don't ignore
	bfd_seek or bfd_write return values.
	* pef.c (bfd_pef_scan_section): Likewise.
	(bfd_pef_read_header, bfd_pef_xlib_read_header): Likewise.
	* vms-misc.c (_bfd_vms_output_end): Likewise.  Return status.
	* vms.h (_bfd_vms_output_end): Update prototype.
	* vms-alpha.c: Pass _bfd_vms_output_end status up call chains.
	* wasm-module.c (wasm_compute_custom_section_file_position): Don't
	ignore bfd_seek or bfd_write return values.
	(wasm_compute_section_file_positions): Likewise.
	* xsym.c (bfd_sym_scan): Don't ignore bfd_seek return value.
	(bfd_sym_read_name_table): Likewise.
binutils/
	* ar.c (print_contents, extract_file): Don't ignore bfd_seek
	return value.
ld/
	* pdb.c (create_section_contrib_substream): Don't ignore bfd_seek
	return value.
	(create_section_header_stream): Likewise.
	* pe-dll.c (pe_get16, pe_get32): Add fail param to return results
	from bfd_seek and bfd_read.
	(pe_implied_import_dll): Handle these fails, and other bfd_seek
	and bfd_read return values.
2023-08-11 16:36:11 +09:30
Alan Modra
226f9f4fad Rename bfd_bread and bfd_bwrite
These were renamed from bfd_read and bfd_write back in 2001 when they
lost an unnecessary parameter.  Rename them back, and get rid of a few
casts that are only needed without prototyped functions (K&R C).
2023-08-09 08:48:09 +09:30
Alan Modra
7ed4ad59e9 Delete PROGRESS macros
I don't see much point in cluttering the source with the PROGRESS
macros, which of course do nothing at all with the definitions in
progress.h.  progress.h is unchanged apart from the copyright comment
since commit d4d4c53c68 in 1994.

binutils/
	* ar.c: Don't include progress.h, or invoke PROGRESS macros.
	* nm.c: Likewise.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
gas/
	* as.h: Don't include progress.h.
	* as.c: Don't invoke PROGRESS macros.
	* write.c: Likewise.
include/
	* progress.h: Delete.
ld/
	* ldmain.c: Don't include progress.h, or invoke PROGRESS macros.
2023-02-16 21:00:50 +10:30
Alan Modra
6296342ec4 PR 30060, ASAN error in bfd_cache_close
After bfd_close nothing should access bfd memory.  Now that bfd_close
always tidies up even after an error, attempting to tidy the cached
bfd list by calling bfd_cache_close is wrong and not needed.

	PR 30060
	* ar.c (remove_output): Don't call bfd_cache_close.
	(output_bfd): Delete.
	* arsup.c (ar_end): Call bfd_close_all_done, not bfd_cache_close.
2023-01-31 15:18:04 +10:30
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
Alan Modra
370426d0da Always free matching vector from bfd_check_format_matches
At least one place calling list_matching_formats failed to free the
"matching" vector from bfd_check_format_matches afterwards.  Fix that
by calling free inside list_matching_formats.

binutils/
	* bucomm.c (list_matching_formats): Free arg.
	* addr2line.c (process_file): Adjust to suit.
	* ar.c (open_inarch, ranlib_touch): Likewise.
	* coffdump.c (main): Likewise.
	* nm.c (display_archive, display_file): Likewise.
	* objcopy.c (copy_file): Likewise.
	* objdump.c (display_object_bfd): Likewise.
	* size.c (display_bfd): Likewise.
	* srconv.c (main): Likewise.
ld/
	* ldlang.c (load_symbols): Free "matching".
2022-06-16 15:01:14 +09:30
Alan Modra
fa44522195 PR29142, segv in ar with empty archive and libdeps specified
PR 29142
	* ar.c (main): Properly handle libdeps for zero file_count.
2022-05-12 11:49:45 +09:30
Fangrui Song
d1b69c506f ar: Add --thin for creating thin archives
In many ar implementations (FreeBSD, elfutils, etc), -T has the X/Open
System Interface specified semantics. Therefore -T for thin archives is
not recommended for portability. -T is deprecated without diagnostics.

    PR binutils/28759
    * ar.c (long_options): Add --thin.
    (usage) Add --thin. Deprecate -T without diagnostics.
    * doc/binutils.texi: Add doc.
    * NEWS: Mention --thin.
    * binutils/testsuite/binutils-all/ar.exp: Add tests.
2022-01-11 08:59:40 -08:00
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
Gleb Fotengauer-Malinovskiy
0d62064867 PR28391, strip/objcopy --preserve-dates *.a: cannot set time
After commit 985e026451 copy_archive function began to pass invalid
values to the utimensat(2) function when it tries to preserve
timestamps in ar archives.  This happens because the bfd_stat_arch_elt
implementation for ar archives fills only the st_mtim.tv_sec part of
the st_mtim timespec structure, but leaves the st_mtim.tv_nsec part
and the whole st_atim timespec untouched leaving them uninitialized

	PR 28391
	* ar.c (extract_file): Clear buf for preserve_dates.
	* objcopy.c (copy_archive): Likewise.
2021-09-28 20:18:48 +09:30
Alan Modra
87b9f2556d C99 binutils configury
* configure.ac: Assume long long is available.  Don't test for
	strings.h, stdlib.h, limits.h, locale.h, or wchar.h.  Check
	inttypes.h, stdint.h, sys/stat.h and sys/types.h. Don't check for
	strcoll, setlocale, setmode or location of time_t.  Don't check
	for fprintf, getenv, snprintf, strnlen, strstr or vsnprintf decls.
	(AC_ISC_POSIX, AXC_HEADER_STRING, AC_FUNC_ALLOCA): Don't invoke.
	* sysdep.h: Don't include alloca-conf.h, include config.h instead.
	Test HAVE_SYS_TYPES_H and reorder includes.  Include limits.h,
	locale.h, string.h and stdlib.h unconditionally.  Remove various
	fallback declarations.  Assume long long is available.
	* addr2line.c: Don't test HAVE_SETLOCALE.
	* ar.c: Likewise.
	* coffdump.c: Likewise.
	* dlltool.c: Likewise.
	* dllwrap.c: Likewise.
	* elfedit.c: Likewise.
	* nm.c: Likewise.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* readelf.c: Likewise.
	* size.c: Likewise.
	* srconv.c: Likewise.
	* strings.c: Likewise.
	* sysdump.c: Likewise.
	* windmc.c: Likewise.
	* windres.c: Likewise.
	* bucomm.c: Don't test HAVE_TIME_T_IN_TIME_H or HAVE_TIME_T_IN_TYPES_H.
	* dwarf.c: Include limits.h unconditionally.  Assume long long
	is available.
	* nm.c: Don't test HAVE_STRCOLL.
	* readelf.c: Don't test HAVE_WCHAR_H.
	* strings.c: Assume long long is available.
	* syslex.l: Include string.h unconditionally.
	* aclocal.m4: Regenerate.
	* config.in: Regenerate.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
	* doc/Makefile.in: Regenerate.
2021-04-05 15:30:22 +09:30
Alan Modra
015dc7e1f8 Use bool in binutils
* sysdep.h (POISON_BFD_BOOLEAN): Define.
	* addr2line.c, * ar.c, * arsup.c, * bfdtest2.c, * binemul.c,
	* binemul.h, * bucomm.c, * bucomm.h, * budbg.h, * coffgrok.c,
	* debug.c, * debug.h, * dlltool.c, * dwarf.c, * dwarf.h,
	* elfedit.c, * emul_aix.c, * mclex.c, * nm.c, * objcopy.c,
	* objdump.c, * od-macho.c, * prdbg.c, * rdcoff.c, * rddbg.c,
	* readelf.c, * rename.c, * stabs.c, * strings.c, * windint.h,
	* windmc.c, * windmc.h, * windres.c, * winduni.c,
	* wrstabs.c: Replace bfd_boolean with bool, FALSE with false,
	and TRUE with true throughout.
2021-03-31 10:49:23 +10:30
Alan Modra
c42c71a152 Use make_tempname file descriptor in smart_rename
This patch makes use of the temp file descriptor in smart_rename
rather than reopening the file.  I don't believe there is a security
issue in reopening the file, but this way is one less directory
operation.  The patch also attempts to preserve S_ISUID and S_ISGID.

	PR 27456
	* bucomm.h (smart_rename): Update prototype.
	* rename.c (smart_rename): Add fromfd and preserve_dates params.
	Pass fromfd and target_stat to simple_copy.  Call set_times
	when preserve_dates.
	(simple_copy): Accept fromfd rather than from filename.  Add
	target_stat param.  Rewind fromfd rather than opening.  Open
	"to" file without O_CREAT.  Try to preserve S_ISUID and S_ISGID.
	* ar.c (write_archive): Rename ofd to tmpfd.  Dup tmpfd before
	closing output temp file, and pass tmpfd to smart_rename.
	* arsup.c (temp_fd): Rename from real_fd.
	(ar_save): Dup temp_fd and pass to smart_rename.
	* objcopy.c (strip_main, copy_main): Likewise, and pass
	preserve_dates.
2021-02-24 09:34:42 +10:30
Siddhesh Poyarekar
3685de750e binutils: Avoid renaming over existing files
Renaming over existing files needs additional care to restore
permissions and ownership, which may not always succeed.
Additionally, other properties of the file such as extended attributes
may be lost, making the operation flaky.

For predictable results, resort to rename() only if the file does not
exist, otherwise copy the file contents into the existing file.  This
ensures that no additional tricks are needed to retain file
properties.

This also allows dropping of the redundant set_times on the tmpfile in
objcopy/strip since now we no longer rename over existing files.

binutils/

	* ar.c (write_archive): Remove TARGET_STAT.  Adjust call to
	SMART_RENAME.
	* arsup.c (ar_save): Likewise.
	* objcopy (strip_main): Don't copy TMPFD.  Don't set times on
	temporary file and adjust call to SMART_RENAME.
	(copy_main): Likewise.
	* rename.c [!S_ISLNK]: Remove definitions.
	(try_preserve_permissions): Remove function.
	(smart_rename): Remove FD, PRESERVE_DATES arguments.  Use
	rename system call only if TO does not exist.
	* bucomm.h (smart_rename): Adjust declaration.
2021-02-19 08:05:33 +05:30
Alan Modra
95b91a043a pr27270 and pr27284, ar segfaults and wrong file mode
PR 27270
	PR 27284
	PR 26945
	* ar.c: Don't include libbfd.h.
	(write_archive): Replace xmalloc+strcpy with xstrdup.  Use
	bfd_stat rather than fstat on iostream.  Move stat and fd tests
	outside of _WIN32 ifdef.  Delete skip_stat variable.
	* arsup.c (temp_name, real_ofd): New static variables.
	(ar_open): Use make_tempname and bfd_fdopenw.
	(ar_save): Adjust to suit ar_open changes.  Move stat output
	of _WIN32 ifdef.
	* objcopy.c: Don't include libbfd.h.
	(copy_file): Use bfd_stat.
2021-02-03 13:30:28 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Sebastian Huber
b143e2d506 Fix a build problem when using FreeBSD 12.
* ar.c (write_archive): Cast iostream pointer to FILE *.
	* arsup.c (ar_save): Likewise.
	* objcopy.c (copy_file): Likewise.
2020-12-11 13:27:45 +00:00
Siddhesh Poyarekar
014cc7f849 binutils: Make smart_rename safe too
smart_rename is capable of handling symlinks by copying and it also
tries to preserve ownership and permissions of files when they're
overwritten during the rename.  This is useful in objcopy where the
file properties need to be preserved.

However because smart_rename does this using file names, it leaves a
race window between renames and permission fixes.  This change removes
this race window by using file descriptors from the original BFDs that
were used to manipulate these files wherever possible.

The file that is to be renamed is also passed as a file descriptor so
that we use fchown/fchmod on the file descriptor, thus making sure
that we only modify the file we have opened to write.  Further, in
case the file is to be overwritten (as is the case in ar or objcopy),
the permissions that need to be restored are taken from the file
descriptor that was opened for input so that integrity of the file
status is maintained all the way through to the rename.

binutils/

	* rename.c
	* ar.c
	(write_archive) [!defined (_WIN32) || defined (__CYGWIN32__)]:
	Initialize TARGET_STAT and OFD to pass to SMART_RENAME.
	* arsup.c
	(ar_save) [defined (_WIN32) || defined (__CYGWIN32__)]:
	Likewise.
	* bucomm.h (smart_rename): Add new arguments to declaration.
	* objcopy.c
	(strip_main)[defined (_WIN32) || defined (__CYGWIN32__)]:
	Initialize COPYFD and pass to SMART_RENAME.
	(copy_main) [defined (_WIN32) || defined (__CYGWIN32__)]:
	Likewise.
	* rename.c (try_preserve_permissions): New function.
	(smart_rename): Use it and add new arguments.
2020-12-07 20:48:33 +05:30
Siddhesh Poyarekar
365f5fb6d0 binutils: Use file descriptors from make_tempname
The purpose of creating a temporary file securely using mkstemp is
defeated if it is closed in make_tempname and reopened later for use;
it is as good as using mktemp.  Get the file descriptor instead and
then use it to create the BFD object.

bfd/

	* opncls.c (bfd_fdopenw): New function.
	* bfd-in2.h: Regenerate.

binutils/

	* bucomm.c (make_tempname): Add argument to return file
	descriptor.
	* bucomm.h (make_tempname): Likewise.
	* ar.c: Include libbfd.h.
	(write_archive): Adjust for change in make_tempname.  Call
	bfd_fdopenw instead of bfd_openw.
	* objcopy.c: Include libbfd.h.
	(copy_file): New argument OFD.  Use bfd_fdopenw instead of
	bfd_openw.
	(strip_main): Adjust for change in make_tempname and
	copy_file.
	(copy_main): Likewise.
2020-12-07 20:48:23 +05:30
Howard Chu
0833984dda Place the libdeps record in the second archive slot.
* ar.c (main): Place the libdeps record in the second archive
	slot.
2020-11-17 14:00:08 +00:00
Howard Chu
c9af384513 Re: dependency list for static libraries
This feature doesn't actually require plugin support, that was a
mistake in the previous patch.  Fixes these fails:

hppa-hp-hpux10  +FAIL: ar adding library dependencies
i386-bsd  +FAIL: ar adding library dependencies
i386-msdos  +FAIL: ar adding library dependencies
ns32k-netbsd  +FAIL: ar adding library dependencies
ns32k-pc532-mach  +FAIL: ar adding library dependencies
pdp11-dec-aout  +FAIL: ar adding library dependencies

	* ar.c (main): Use plugin_target rather than "target" when
	resetting libdeps_bfd target.
2020-11-09 14:07:19 +10:30
Howard Chu
f3016d6ce1 Add an option to the archiver to add a section recording library dependencies.
* ar.c (long_options): Add --record-libdeps.
	(usage): Mention the new option.
	(decode_options): Handle the new option.
	(replace_members): If necessary, create a bfd to hold the libdeps
	description.
	* binemul.c (ar_emul_append_bfd): New function.
	(ar_emul_replace_bfd): New function.
	(ar_emul_default_append): Replace file_name and target arguments
	with new_bfd argument.
	(ar_emul_default_replace): Likewise.
	* binemul.h: Update prototypes.
	(struct bin_emulation_xfer_struct): Update fields.
	* doc/binutils.texi: Document the new option.
	* NEWS: Mention the new feature.
	* emul_aix.c (ar_emul_aix_append): Update.
	(ar_emul_aix_replace): Likewise.
	* testsuite/binutils-all/ar.exp: Add test of new feature.
2020-11-03 15:12:47 +00:00
Alan Modra
c177f3771c Use bfd_get_filename throughout binutils
* ar.c (map_over_members, get_pos_bfd, delete_members, move_members),
	(replace_members): Use bfd_get_filename rather than accessing
	bfd->filename directly.
	* arsup.c (map_over_list, ar_delete, ar_replace, ar_extract): Likewise.
	* binemul.c (do_ar_emul_append): Likewise.
	* coffgrok.c (coff_grok): Likewise.
2020-05-19 12:35:56 +09:30
H.J. Lu
3d98c46092 plugin: Don't invoke LTO-wrapper
Don't invoke LTO-wrapper since the LTO wrapper approach is not only
slow but also unreliable.  For GCC 10 or newer, LDPT_ADD_SYMBOLS_V2
will be used.

bfd/

	* configure.ac (HAVE_EXECUTABLE_SUFFIX): Removed.
	(EXECUTABLE_SUFFIX): Likewise.
	* config.in: Regenerated.
	* configure: Likewise.
	* plugin.c (bfd_plugin_close_and_cleanup): Defined as
	_bfd_generic_close_and_cleanup.
	(plugin_list_entry): Remove resolution_file, resolution_option,
	real_bfd, real_nsyms, real_syms, lto_nsyms, lto_syms, gcc,
	lto_wrapper, gcc_env and initialized,
	(need_lto_wrapper_p): Removed.
	(get_lto_wrapper): Likewise.
	(setup_lto_wrapper_env): Likewise.
	(register_all_symbols_read): Likewise.
	(egister_cleanup): Likewise.
	(get_symbols): Likewise.
	(add_input_file): Likewise.
	(bfd_plugin_set_program_name): Remove need_lto_wrapper.
	(add_symbols): Updated.
	(try_claim): Likewise.
	(try_load_plugin): Likewise.
	(bfd_plugin_canonicalize_symtab): Likewise.
	* plugin.h (bfd_plugin_set_program_name): Remove int argument.
	(plugin_data_struct): Remove real_bfd, real_nsyms and real_syms.

binutils/

	* ar.c (main): Update bfd_plugin_set_program_name call.
	* nm.c (main): Likewise.

ld/

	* testsuite/ld-plugin/lto.exp (lto_link_tests): Run PR ld/25355
	test only for GCC 10 or newer.
2020-03-20 03:55:30 -07:00
H.J. Lu
ecda90163e Don't call lto-wrapper for ar and ranlib
Since ar and ranlib don't need to know symbol types to work properly,
we should avoid calling lto-wrapper for them to speed them up.

bfd/

	PR binutils/25584
	* plugin.c (need_lto_wrapper_p): New.
	(bfd_plugin_set_program_name): Add an int argument to set
	need_lto_wrapper_p.
	(get_lto_wrapper): Return FALSE if need_lto_wrapper_p isn't
	set.
	* plugin.h (bfd_plugin_set_program_name): Add an int argument.

binutils/

	PR binutils/25584
	* ar.c (main): Pass 0 to bfd_plugin_set_program_name.
	* nm.c (main): Pass 1 to bfd_plugin_set_program_name.
2020-02-25 03:31:40 -08:00
Alan Modra
b3adc24a07 Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
Nick Clifton
e264b5b7a5 Allow the --output option of the "ar" prorgam to extract files to locations outside of the current directory.
* ar.c (open_output_file): Check for filename validity before
	prefixing with output directory.
	Display the constructed output filename if in verbose mode.
	(extract_file): Let open_output_file display the filename.
2019-11-07 11:56:54 +00:00
Fangrui Song
197245e341 Add a --output=<DIR> option to ar to allow the specifying of an output directory.
* ar.c (emum long option numbers): Declare.  Use to provide
	numerical values for long options.
	(long_options): Add --output option.
	(usage): Mention the --output option.
	(open_output_file): New function.  Create a filepath for an output
	file and open it.
	(extract_file): Use open_output_file().
	(open_output_file):
	* testsuite/binutils-all/ar.exp: Add a test of the new feature.
	* doc/binutils.texi: Document the new feature.
	* NEWS: Mention the new feature.
2019-10-30 10:50:23 +00:00
Alan Modra
95cc7c169c ar P support
This patch extends "ar P" to allow creation of normal (as distinct
from thin) archives with full path names.

	PR 452
	PR 25104
bfd/
	* archive.c (normalize): Return file unchanged when
	BFD_ARCHIVE_FULL_PATH.
	(_bfd_construct_extended_name_table): Pass abfd, the output
	bfd, to normalize.
	(_bfd_archive_bsd44_construct_extended_name_table): Likewise.
	* bfd.c (struct bfd): Make flags a full flagword.
	(BFD_ARCHIVE_FULL_PATH): Define.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Set BFD_ARCHIVE_FULL_PATH.
	* doc/binutils.texi (extract from archive): Mention
	restrictions when extracting from archives with full paths.
	(ar P): Update to current P support.
	(ar -X32_64): Fix spelling.
2019-10-21 16:13:39 +10:30
Alan Modra
b7d9d3ee59 PR25079, "ar s" stopped working
's' is both a command and a modifier.  If given as a command then we
aren't lacking an operation.  I think the same goes when mri mode is
selected: any following command line used to be ignored.

	PR 25079
	* ar.c (decode_options): Don't try for command options if
	write_armap or mri_mode is selected.
2019-10-09 00:20:28 +10:30
Alan Modra
00f93c4492 bfd macro conversion to inline functions
This converts some of the macros that access struct bfd fields to
inline functions.

bfd/
	* archive.c (bfd_generic_archive_p): Use bfd_set_thin_archive.
	* bfd-in.h (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_target, bfd_get_flavour, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian, bfd_header_little_endian),
	(bfd_get_file_flags, bfd_applicable_file_flags),
	(bfd_applicable_section_flags, bfd_has_map, bfd_is_thin_archive),
	(bfd_valid_reloc_types, bfd_usrdata, bfd_get_start_address),
	(bfd_get_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_get_dynamic_symcount, bfd_get_symbol_leading_char): Delete.
	* bfd/bfd.c (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_file_flags, bfd_get_start_address, bfd_get_symcount),
	(bfd_get_dynamic_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_has_map, bfd_is_thin_archive, bfd_set_thin_archive),
	(bfd_usrdata, bfd_set_usrdata): New inline functions.
	* targets.c (bfd_get_target, bfd_get_flavour),
	(bfd_applicable_file_flags, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian),
	(bfd_header_little_endian, bfd_applicable_section_flags),
	(bfd_get_symbol_leading_char): New inline functions.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Use bfd_set_thin_archive.
gdb/
	* gdb_bfd.c (gdb_bfd_ref, gdb_bfd_unref): Use bfd_set_usrdata.
	* dwarf2read.c (dwarf2_read_gdb_index, dwarf2_read_debug_names),
	(read_indirect_string_from_dwz): Use bfd accessor.
	* dwarf2read.h (struct dwz_file <filename>): Likewise.
	* machoread.c (macho_symfile_read_all_oso): Likewise.
	* solib.c (solib_bfd_open): Likewise.
ld/
	* ldelf.c (ldelf_after_open, ldelf_place_orphan
	* ldlang.c (walk_wild_file, lang_process): Use bfd_usrdata.
	(load_symbols, ldlang_add_file): Use bfd_set_usrdata.
	* ldmain.c (add_archive_element): Use bfd_usrdata.
	* ldlang.h (bfd_input_just_syms): New inline function.
	* emultempl/aarch64elf.em (build_section_lists): Use it.
	* emultempl/mmo.em (mmo_place_orphan): Likewise.
	* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/ppc64elf.em (build_section_lists): Likewise.
sim/
	* ppc/emul_generic.c (emul_add_tree_options): Delete old bfd code.
2019-09-20 18:04:02 +09:30
Nick Clifton
2f86d55940 Fix ar so that it can correctly detect non-dash prefixed options that appear after dash prefixed options.
PR 13256
	* ar.c (decode_options): Restart option scanning if no operation
	is detected and argument remain to be scanned.
2019-07-24 12:17:37 +01:00
Alan Modra
827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
Alan Modra
bf2dd8d7cf BFD_INIT_MAGIC
This patch performs a run-time test that a shared libbfd.so has been
compiled with the same size bfd_vma as that of apps using the library.
On a 32-bit host it is easily possible to have one libbfd.so compiled
to support 64-bit targets (or configured with --enable-64-bit-bfd)
while another only supports 32-bit targets.  The two libraries will
have differently sized bfd_vma types, and if the wrong one is loaded
all sorts of weird behaviour might be seen.

bfd/
	PR 23534
	* init.c (BFD_INIT_MAGIC): Define.
	(bfd_init): Return BFD_INIT_MAGIC.
	bfd-in2.h: Regenerate.
binutils/
	PR 23534
	* addr2line.c (main): Exit with fatal error if bfd_init
	returns an unexpected value.
	* ar.c (main): Likewise.
	* dlltool.c (identify_dll_for_implib): Likewise.
	* nm.c (main): Likewise.
	* objcopy.c (main): Likewise.
	* objdump.c (main): Likewise.
	* size.c (main): Likewise.
	* strings.c (main): Likewise.
	* windmc.c (main): Likewise.
	* windres.c (main): Likewise.
gas/
	PR 23534
	* as.c (main): Exit with fatal error if bfd_init returns an
	unexpected value.
ld/
	PR 23534
	* ldmain.c (main): Exit with fatal error if bfd_init returns
	an unexpected value.
2018-10-15 22:11:58 +10:30
Ant Bikeneev
1869e86f2e Add option to ar's 't' command to display the offset of elements within the archive.
PR 23107
	* ar.c (display_offsets): New variable.
	(usage): Add description of 'O' operator.
	(decode_option): Handle 'O' operator.
	(print_descr): Pass display_offsets to print_arelt_descr.
	* arsup.c: Update call to printy_arelt_descr.
	* objdump.c: Likewise.
	* bucomm.c (print_arelt_descr): If offsets parameter is true then
	display offset of archive element within the archive.
	* bucomm.h: Update prototype for print_arelt_descr.
	* doc/binutils.texi: Update description of ar command.
	* NEWS: Mention the new feature.
	* testsuite/binutils-all/ar.exp: Add text of new feature.
2018-05-30 17:08:03 +01:00
Alan Modra
219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
Nick Clifton
3cfd3dd095 Fix a memory leak when processing archives.
PR 22449
	* ar.c (write_archive): Free the temporary file name.
2017-11-17 12:46:07 +00:00
Nick Clifton
2a925816fc Correct previous fix for an absence of input files on the ar command line, so that a complaint is not issued in MRI mode.
PR 21433
	* ar.c (main): Skip check for no files on the command line when
	running in MRI mode.
2017-07-17 10:51:45 +01:00
Nick Clifton
740a463062 Fix invocation of stat() on a NULL pointer.
PR binutils/21407
	* bucomm.c (get_file_size): Return -1 if file_name is NULL.
	* ar.c (main): Fail with usage() invocation if no file names are
	provided.
2017-04-26 15:42:03 +01:00
Alan Modra
42354845ae PR 21418, ar -N lacks arg check
PR 21418
	* ar.c (main): Check -a, -b, -i and -N args are given.
2017-04-23 20:33:35 +09:30
Alan Modra
7034215fd6 PR 21417, ar arg check failure
PR 21417
	* ar.c (main): Check that an archive file is given after options.
2017-04-23 20:33:35 +09:30
Alan Modra
2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Alan Modra
7d0b9ebc1e Don't include libbfd.h outside of bfd, part 6
Some messing with plugin code in order to not need arelt_size in
ld code.  File descriptor handling in ld/plugin.c is tidied too,
simply duping the open fd rather than opening the file again.

bfd/
	* elflink.c: Include plugin-api.h.
	* plugin.c (bfd_plugin_open_input): New function, extracted from..
	(try_claim): ..here.
	* plugin.h: Don't include bfd.h.
	(bfd_plugin_open_input): Declare.
binutils/
	* ar.c: Include plugin-api.h.
	* nm.c: Likewise.
ld/
	* plugin.c: Don't include libbfd.h.  Include plugin-api.h
	before bfd/plugin.h.
	(plugin_object_p): Use bfd_plugin_open_input.
2016-07-16 19:09:00 +09:30
Alan Modra
76e7a75123 Don't include libbfd.h outside of bfd, part 1
Make BFD_ALIGN available to objcopy.  Fix assertions.  Don't use
bfd_log2 in ppc32elf.em or bfd_malloc in xtensaelf.em and bucomm.c.

bfd/
	* libbfd-in.h (BFD_ALIGN): Move to..
	* bfd-in.h: ..here.
	* elf32-ppc.h (struct ppc_elf_params): Add pagesize.
	* elf32-ppc.c (default_params): Adjust init.
	(ppc_elf_link_params): Set pagesize_p2.
	* libbfd.h: Regenerate.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c: Don't include libbfd.h.
	* objcopy.c: Likewise.
	* bucomm.c (bfd_get_archive_filename): Use xmalloc rather than
	bfd_malloc.
gas/
	* config/bfin-parse.y: Don't include libbfd.h.
	* config/tc-bfin.c: Likewise.
	* config/tc-rl78.c: Likewise.
	* config/tc-rx.c: Likewise.
	* config/tc-metag.c: Likewise.
	(create_dspreg_htabs, create_scond_htab): Use gas_assert not BFD_ASSERT.
	* Makefile.am: Update dependencies.
	* Makefile.in: Regenerate.
ld/
	* ldlang.c: Don't include libbfd.h.
	* emultempl/nds32elf.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/ppc32elf.em: Likewise.
	(pagesize): Delete.
	(params): Update init.
	(ppc_after_open_output): Use params.pagesize.  Don't call bfd_log2.
	(PARSE_AND_LIST_ARGS_CASES): Use params.pagesize.
	* emultempl/sh64elf.em: Don't include libbfd.h.
	(after_allocation): Use ASSERT, not BFD_ASSERT.
	* emultempl/xtensaelf.em: Don't include libbfd.h.
	(replace_insn_sec_with_prop_sec): Use xmalloc, not bfd_malloc.
	* Makefile.am: Update dependencies.
	* Makefile.in: Regenerate.
2016-07-16 13:25:11 +09:30
Alan Modra
3860d2b4b7 Delete bfd_my_archive macro
Many more places use abfd->my_archive rather than bfd_my_archive (abfd),
so let's make the code consistently use the first idiom.

bfd/
	* bfd-in.h (bfd_my_archive): Delete.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c: Expand uses of bfd_my_archive.
	* size.c: Likewise.
ld/
	* ldlang.c: Expand uses of bfd_my_archive.
	* ldmain.c: Likewise.
	* ldmisc.c: Likewise.
	* plugin.c: Likewise.
2016-06-14 13:24:37 +09:30
Alan Modra
6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
H.J. Lu
3aade68889 Remove trailing spaces in binutils 2015-08-12 04:42:37 -07:00
Nick Clifton
4e13f8fb05 Fix memory leak in ar if it encounters an invalid path whilst extracting files.
* ar.c (extract_file): Free cbuf if the path is invalid.
2015-08-04 14:50:40 +01:00