Commit Graph

159 Commits

Author SHA1 Message Date
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Mark Johnston
41e6398f9b ar: Avoid overwriting the stdout file stream pointer
This doesn't work with musl, which defines stdout as FILE * const.
Instead, explicitly pass the desired output stream to ar_read_archive().

No functional change intended.

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34064
2022-01-27 17:10:17 -05:00
Ed Maste
1a0a41b105 ar: accept but ignore 'T' option
In previous versions of BSD ar -T was an alias for -f -- use only the
first 15 characters of archive member names.  In GNU ar and LLVM ar -T
creates a thin archive.

The -f / old BSD ar -T functionality is not particularly useful, and
ignoring -T still results in a usable and compatible (but not thin)
archive.

An exp-run found a few ports invoking ar -T but they all expect thin
archives.  In addition, -T will be used to specify thin archives after
a migration to LLVM-ar.

PR:             260523 [exp-run]
Reviewed by:	markj
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D33553
2022-01-03 11:42:59 -05:00
Ed Maste
edadbb4606 ar: deprecate -T option
Other ar implementations (GNU, LLVM) use -T to mean thin archive
rather than use only the first fifteen characters of the archive member
name.  We support both -T and -f for this, with -f documented as an
alias of -T.

An exp-run showed that the ports invoking `ar -T` expect thin archives,
not truncated names.  Switch -f to be the documented flag for this
behaviour, and emit a warning when -T is used.

The warning will be changed to an error in the future (in main), once
ports no longer use -T.

PR:		260523 [exp-run]
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-12-29 15:14:06 -05:00
Ed Maste
866c807472 ar: remove duplicate function declaration in header
Sponsored by:	The FreeBSD Foundation
2021-08-13 16:58:18 -04:00
Ed Maste
57aaefdcec ar: diff reduction against ELF Tool Chain
Remove ar_mode_* wrappers and call ar_read_archive / ar_write_archive
directly.

(This was originally committed in d20e9e02db but reverted due to a
regression, now fixed with an update from cy@.)

Obtained from:	ELF Tool Chain
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31496
2021-08-13 11:17:46 -04:00
Ed Maste
086f090877 ar: diff reduction against ELF Tool Chain
Drop exit status from bsdar_errc.  ELF Tool Chain always returns
EXIT_FAILURE in bsdar_errc.

Recommit of one part of d20e9e02db / review D31496.

Obtained from:	ELF Tool Chain
Sponsored by:	The FreeBSD Foundation
2021-08-13 10:39:44 -04:00
Ed Maste
c5bf58add0 Revert "ar: diff reduction against ELF Tool Chain"
This reverts commit d20e9e02db.
It caused port build failures.

Reported by:	cy
2021-08-12 14:26:37 -04:00
Ed Maste
d20e9e02db ar: diff reduction against ELF Tool Chain
- Drop exit status from bsdar_errc.  ELF Tool Chain always returns
  EXIT_FAILURE in bsdar_errc.

- Remove ar_mode_* wrappers and call ar_read_archive / ar_write_archive
  directly.

Obtained from:	ELF Tool Chain
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31496
2021-08-11 19:12:46 -04:00
Ed Maste
09319f7d3f ar: remove invalid extra param in bsdar_warnc calls
A number of warnings passed an exit status code to bsdar_warnc, but it
does not take exit status (as a warning, it does not exit).

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-08-11 13:27:19 -04:00
Ed Maste
38911b3c2c ar: provide error exit status upon failure
Previously ar and ranlib returned with exit status 0 (success) in the
case of a missing file or other error.  Update to use error handling
similar to that added by ELF Tool Chain after that project forked
FreeBSD's ar.

PR:		PR257599 [exp-run]
Reported by:	Shawn Webb, gehmehgeh (on HardenedBSD IRC)
Reviewed by:	markj
Obtained from:	elftoolchain
MFC after:	2 months
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31402
2021-08-10 17:08:10 -04:00
Gordon Bergling
5666643a95 Fix some common typos in comments
- occured -> occurred
- normaly -> normally
- controling -> controlling
- fileds -> fields
- insterted -> inserted
- outputing -> outputting

MFC after:	1 week
2021-03-13 18:26:15 +01:00
Ed Maste
597d9b4008 ar: use more correct size_t type for loop index
Submitted by:	cem
MFC after:	1 week
2019-09-01 16:51:25 +00:00
Ed Maste
1dffcf9f2d ar: shuffle symbol offsets during conversion for 32-bit ar archives
During processing we maintain symbol offsets in the 64-bit s_so array,
and when writing the archive convert to 32-bit if no offsets are greater
than 4GB.  However, this was somewhat inefficient as we looped over the
array twice: first, converting to big endian and second, writing each
32-bit value one at a time (and incorrectly so on big-endian platforms).

Instead, when writing a 32-bit archive shuffle convert symbol data to
big endian (as required by the ar format) and shuffle to the beginning
of the allocation at the same time.

Also correct emission of the symbol count on big endian platforms.

Further changes are planned, but this should fix powerpc64.

Reported by:	jhibbits, mlinimon
Reviewed by:	jhibbits, Gerald Aryeetey (earlier)
Tested by:	jhibbits
MFC after:	10 days
MFC with:	r346079
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20007
2019-04-22 19:55:47 +00:00
Ed Maste
687c09042f ar: use array notation to access s_so
This is somewhat more readable than pointer arithmetic.  Also remove an
unnecessary cast while here.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2019-04-22 17:29:26 +00:00
Ed Maste
e5228a95c6 ar: test for writing 64-bit format only if symbol count is nonzero
This is a minor simplification; if we do not have any symbols the empty
symbol table can be in 32-bit format.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2019-04-22 17:25:00 +00:00
Ed Maste
fabed6b2bd ar: implement support for /SYM64/ 64-bit archives
PR:		234454
Submitted by:	Gerald Aryeetey <aryeeteygerald_rogers.com>
Reviewed by:	imp (earlier)
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D18793
2019-04-10 13:13:34 +00:00
Ed Maste
ac8e938122 ar: detect and error out on 32-bit symbol table overflow
BSD ar currently does not support the /SYM64/ 64-bit symbol table, and
previously truncated to 32-bits, silently producing corrupted archives
larger than 4GB.

This is another overflow case in addtion to r342575.

PR:		234454
Reported by:	Aijaz Baig, imp
MFC after:	2 weeks
MFC with:	r342575
Sponsored by:	The FreeBSD Foundation
2018-12-28 22:47:55 +00:00
Ed Maste
699f180198 ar: detect and error out on 32-bit symbol table overflow
BSD ar currently does not support the /SYM64/ 64-bit symbol table, and
previously truncated to 32-bits, silently producing corrupted archives
larger than 4GB.

Note that this is only a partial fix; additional checks will come.

PR:		234454
Reported by:	Aijaz Baig, imp
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2018-12-28 17:00:12 +00:00
Ed Maste
ccd8660b86 ar: report errno on warning/error
Previously ar would report an error like "ar: fatal: Write error"
without including additional errno information.  Change warnings and
errors to include archive_errno() so that the user may have some idea
of the reason for the failure.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17650
2018-10-23 13:07:03 +00:00
Ed Maste
be72428e54 usr.bin/ar: use standard 2-Clause FreeBSD license
Many licenses on ar files contained small variations from the standard
FreeBSD license text. To avoid license proliferation switch to the usual
2-clause FreeBSD license after obtaining permission from all copyright
holders.

Approved by:	jkoshy, kaiw, kientzle
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D14561
2018-06-20 18:43:17 +00:00
Ed Maste
9befbe457c usr.bin/ar: remove incorrect SPDX tags
Three ar files have a non-standard variation of the BSD license, so
remove their SPDX tags.

Sponsored by:	The FreeBSD Foundation
2018-06-19 17:30:11 +00:00
Ed Maste
25f82d56c7 usr.bin/ar: use standard 2-Clause FreeBSD license
Many licenses on ar files contained small variations from the standard
FreeBSD license text. To avoid license proliferation switch to the usual
standard 2-clause FreeBSD license for those files where I have obtained
permission from all of the listed copyright holders.

Approved by:	jkoshy, kaiw
Differential Revision:	https://reviews.freebsd.org/D14561
2018-06-19 17:28:05 +00:00
Pedro F. Giffuni
1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.
2017-11-27 15:37:16 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Ed Maste
3f71a0c918 ar: handle partial writes from archive_write_data
libarchive may limit a single archive_write_data call to handling
0x7fffffff bytes. Add a loop to handle partial writes.

Reviewed by:	kib, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D11715
2017-07-24 21:25:49 +00:00
Ed Maste
11c4d924e1 ar: enable reproducible output by default when invoked as 'ar -s'
ar output is already deterministic by default for ar -q and ar -r, and
when invoked as ranlib. Make ar -s equivalent to ranlib and enable
deterministic output by default in that case too.

PR:		210330
Reviewed by:	bdrewery
Approved by:	re (gjb)
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D6871
2016-06-16 21:22:26 +00:00
Ed Schouten
09a113491c Make code compile when basename() is POSIX compliant.
In addition to the previous change I made to ar.c, pull in another
basename() related fix. This change is similar to the one made to the
ELF Toolchain version of ar, with the difference that the ELF Toolchain
version lacks error handling for the strdup() call.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D6467
2016-05-26 13:49:40 +00:00
Ed Schouten
c76f604ee9 Make code compile when basename() is POSIX compliant.
If basename() uses "char *", we shouldn't do the intermediate
assignment, as that field is of type "const char *". Simply call
basename() on the command line argument directly.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D6463
2016-05-19 20:03:01 +00:00
Bryan Drewery
bd18fd57db DIRDEPS_BUILD: Regenerate without local dependencies.
These are no longer needed after the recent 'beforebuild: depend' changes
and hooking DIRDEPS_BUILD into a subset of FAST_DEPEND which supports
skipping 'make depend'.

Sponsored by:	EMC / Isilon Storage Division
2016-02-24 17:20:11 +00:00
Bryan Drewery
bd9302d862 Check archive_entry_new() result.
Coverity CID:	1331341
2015-10-29 19:28:21 +00:00
Ed Maste
a84c4d189b ar: Deobfuscate a while loop 2015-08-31 18:07:17 +00:00
Ed Maste
a64a36e280 ar: fix deterministic mode when running as ranlib
This was broken by r286024.

PR:		202741
Submitted by:	fk@fabiankeil.de
Obtained from:	ElectroBSD
2015-08-31 12:28:13 +00:00
Ed Maste
a80ac30b2d ar: Fix deterministic mode default with options other than -q or -r
Reported by:	jhibbits
Reviewed by:	jhibbits
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3237
2015-07-29 17:34:26 +00:00
Ed Maste
fc964cbf4e ar: enable deterministic mode by default
Ar cannot handle UIDs with more than 6 digits, and storing the mtime,
uid, gid and mode provides little to negative value anyhow for ar's
uses. Turn on deterministic (-D) mode by default; it can be disabled by
the user with -U.

PR:		196929
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3190
2015-07-29 13:36:17 +00:00
Ed Maste
7072861cd0 ar: add -U (unique) option to disable -D (deterministic) mode
This is required in order for us to support deterministic mode by
default.  If multiple -D or -U options are specified on the command
line, the final one takes precedence.  GNU ar also uses -U for this.

An equivalent change will be applied to ELF Tool Chain's version of ar.

PR:		196929
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D3175
2015-07-24 17:46:43 +00:00
Ed Maste
01715d8cd1 speed up ar(1) on UFS file systems
Fault in the buffer prior to writing to workaround poor performance due
to interaction with kernel fs deadlock avoidance code. See the comment
prior to vn_io_fault_doio() in sys/kern/vfs_vnops.c for details of the
issue.

On my stable/10 desktop with a 16MB obj.o and "ar r out.a obj.o" I see
the following run times (seconds):

x ar.r284891
+ ar.patched
+----------------------------------------------------------------------+
|+                                                                     |
|+                                                                    x|
|+                                                                   xx|
|A                                                                   |A|
+----------------------------------------------------------------------+
    N         Min          Max        Median           Avg        Stddev
x   3       1.307        1.321         1.315     1.3143333  0.0070237692
+   3       0.020        0.023         0.022   0.021666667  0.0015275252
Difference at 95.0% confidence
        -1.29267 +/- 0.0115203
        -98.3515% +/- 0.876513%
        (Student's t, pooled s = 0.00508265)

Thanks to kib for diagnosing and explaining the issue and suggesting
the workaround.

Reviewed by:	eadler, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D2933
2015-06-29 13:48:44 +00:00
Simon J. Gerraty
2ef6d5a7b9 new depends 2015-06-16 23:37:19 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Ed Maste
0f9b4b57c1 Avoid escaping EOL for line continuation
Reported by:	kib
2015-04-09 15:08:39 +00:00
Ed Maste
56ad941995 ar: Disallow directory traversal
Set ARCHIVE_EXTRACT_SECURE_SYMLINKS and ARCHIVE_EXTRACT_SECURE_NODOTDOT
as in bsdtar to prevent extraction of archive entries whose pathnames
contain .. or whose target directory would be altered by a symlink.
Also disallow absolute pathnames.

We don't currently provide an option to disable this behaviour (as
bsdtar's -P does). It is unlikely to be a problem in practice for ar(1),
but the -P option is not currently used and available if we want to
consider it for this purpose.

Differential Revision:	https://reviews.freebsd.org/D1524
Reported by:	Alexander Cherepanov <cherepan@mccme.ru>
Approved by:	delphij
Obtained from:	ELF tool chain ar, Ticket #474
MFC after:	1 week
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
2015-04-09 13:45:17 +00:00
Ed Maste
63bf16a1c4 ar: Avoid null pointer deref while reading corrupt archives
ELF Tool Chain ticket #467

Reported by:	Alexander Cherepanov <cherepan@mccme.ru>
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2015-01-07 01:51:02 +00:00
Baptiste Daroussin
3e11bd9e2a Convert to usr.bin/ to LIBADD
Reduce overlinking
2014-11-25 14:29:10 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Baptiste Daroussin
2b7af31cf5 use .Mt to mark up email addresses consistently (part3)
PR:		191174
Submitted by:	Franco Fichtner  <franco at lastsummer.de>
2014-06-23 08:23:05 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00