Commit Graph

146 Commits

Author SHA1 Message Date
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
Warner Losh
c6063d0da8 Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.
2014-05-06 04:22:01 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Jung-uk Kim
9c5a52cf88 Work around build breakages with GCC 4.2.
Reported by:	tinderbox
2013-05-23 05:42:35 +00:00
Jung-uk Kim
a7880d59c9 Improve compatibility with recent flex from flex.sourceforge.net. 2013-05-03 23:51:32 +00:00
Ed Schouten
7e659f9491 Add the Clang specific -Wmissing-variable-declarations to WARNS=6.
This compiler flag enforces that that people either mark variables
static or use an external declarations for the variable, similar to how
-Wmissing-prototypes works for functions.

Due to the fact that Yacc/Lex generate code that cannot trivially be
changed to not warn because of this (lots of yy* variables), add a
NO_WMISSING_VARIABLE_DECLARATIONS that can be used to turn off this
specific compiler warning.

Announced on:	toolchain@
2013-04-19 19:45:00 +00:00
Simon J. Gerraty
89e0f621b2 New/updated dependencies 2013-04-14 01:22:39 +00:00
Simon J. Gerraty
69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Martin Matuska
acc60b03c1 MFV r248590,248594:
Update libarchive to 3.1.2

Some of new features:
  - support for lrzip and grzip compression
  - support for writing tar v7 format
  - b64encode and uuencode filters
  - support for __MACOSX directory in Zip archives
  - support for lzop compresion (external utility)
2013-03-22 13:36:03 +00:00
Martin Matuska
ebb8fc42be Replace deprecated (or remove obsolete) libarchive 2.8 functions
with libarchive 3.0 counterparts
2013-03-22 10:17:42 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Eitan Adler
5d08632eba Mark bsdar_errc as __dead2 to help code analysis tools.
PR:		bin/172636
Submitted by:	Erik Cederstrand <erik@cederstrand.dk>
Approved by:	cperciva
MFC after:	3 days
2012-10-22 02:12:06 +00:00