History log of /freebsd-current/usr.bin/ar/write.c
Revision Date Author Comments
# b1d0cf28 07-Jan-2024 LO WEN-CHIEN <s111062113@m111.nthu.edu.tw>

ar(1): Fix grammar error in write.c

Event: Advanced UNIX Programming Course (Fall’23) at NTHU
Pull Request: https://github.com/freebsd/freebsd-src/pull/1013


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 57aaefdc 13-Aug-2021 Ed Maste <emaste@FreeBSD.org>

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 d20e9e02db3d 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


# 086f0908 12-Aug-2021 Ed Maste <emaste@FreeBSD.org>

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 d20e9e02db3d / review D31496.

Obtained from: ELF Tool Chain
Sponsored by: The FreeBSD Foundation


# c5bf58ad 12-Aug-2021 Ed Maste <emaste@FreeBSD.org>

Revert "ar: diff reduction against ELF Tool Chain"

This reverts commit d20e9e02db3dde383c3de1ce8cec3a8c35b3eee6.
It caused port build failures.

Reported by: cy


# d20e9e02 04-Aug-2021 Ed Maste <emaste@FreeBSD.org>

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


# 09319f7d 11-Aug-2021 Ed Maste <emaste@FreeBSD.org>

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


# 38911b3c 03-Aug-2021 Ed Maste <emaste@FreeBSD.org>

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


# 5666643a 13-Mar-2021 Gordon Bergling <gbe@FreeBSD.org>

Fix some common typos in comments

- occured -> occurred
- normaly -> normally
- controling -> controlling
- fileds -> fields
- insterted -> inserted
- outputing -> outputting

MFC after: 1 week


# 597d9b40 01-Sep-2019 Ed Maste <emaste@FreeBSD.org>

ar: use more correct size_t type for loop index

Submitted by: cem
MFC after: 1 week


# 1dffcf9f 22-Apr-2019 Ed Maste <emaste@FreeBSD.org>

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


# 687c0904 22-Apr-2019 Ed Maste <emaste@FreeBSD.org>

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


# e5228a95 22-Apr-2019 Ed Maste <emaste@FreeBSD.org>

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


# fabed6b2 10-Apr-2019 Ed Maste <emaste@FreeBSD.org>

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


# ac8e9381 28-Dec-2018 Ed Maste <emaste@FreeBSD.org>

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


# 699f1801 28-Dec-2018 Ed Maste <emaste@FreeBSD.org>

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


# ccd8660b 23-Oct-2018 Ed Maste <emaste@FreeBSD.org>

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


# 25f82d56 19-Jun-2018 Ed Maste <emaste@FreeBSD.org>

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


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# 3f71a0c9 24-Jul-2017 Ed Maste <emaste@FreeBSD.org>

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


# 09a11349 26-May-2016 Ed Schouten <ed@FreeBSD.org>

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


# bd9302d8 29-Oct-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Check archive_entry_new() result.

Coverity CID: 1331341


# 01715d8c 29-Jun-2015 Ed Maste <emaste@FreeBSD.org>

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


# ebb8fc42 22-Mar-2013 Martin Matuska <mm@FreeBSD.org>

Replace deprecated (or remove obsolete) libarchive 2.8 functions
with libarchive 3.0 counterparts


# cf933f5b 04-Aug-2011 Ed Maste <emaste@FreeBSD.org>

Don't try to free() an address returned by mmap(). This appears to be
triggered by the same .o being included twice on the command line.

Found by: Nima Misaghian at Sandvine
Reviewed by: kientzle, kaiw
Approved by: re
MFC after: 1 week


# 6bef5d28 20-May-2011 Benedict Reuschling <bcr@FreeBSD.org>

Correct typos in comments, no functional changes.

Found by: codespell
Reviewed by: kaiw
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 0e479ac8 08-Oct-2010 Tim Kientzle <kientzle@FreeBSD.org>

Add -D (deterministic) option to ar.
When set, it forces all timestamps and owners to zero and
modes to 0644. Useful for producing libraries that are
bitwise identical across multiple build runs.

Submitted by: Erik Cederstrand
Reviewed by: Kai Wang


# 5dfab45b 17-May-2010 Kai Wang <kaiw@FreeBSD.org>

Removed ar(1)'s support for compressed archives. This change removes
ar(1)'s dependencies on compressor libraries -lz, -lbz2 and -llzma and
fixes building HEAD on some versions of FreeBSD[78]. Option -j and -z
is now accepted but ignored.

Compressed ar(1) archives are not useful without a ld(1) that can read
them. Also, the current ar(1) compression scheme prevents random
access of archive members and needs to be redesigned anyway.

Submitted by: kientzle (original patch)
Reviewed by: delphij
Discussed on: -current mailing list


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 0c099281 20-Sep-2008 Kai Wang <kaiw@FreeBSD.org>

Add support for option "-M", which is used to operate ar(1) in a
script mode like the MRI(Microtec Research Inc.) "librarian" program.

Originally this option is provided by Binutils ar(1) to ease the
transition for developers who are used to writing "librarian" scripts.

We added this option to BSD ar(1) because:

1. Further improve the compatibility with Binutils ar(1).
2. There are still a few software using this -M option. (at least one
in our ports collection)

Suggested by: rink & erwin


# cb0dad38 11-Mar-2008 Kai Wang <kaiw@FreeBSD.org>

GNU ar did NOT implment option -q as a synonym of -r as the manual
page stated, thus BSD ar(1) option -q, which was implemented based on
the GNU ar manual page, turns out to be incompatible with GNU ar -q.

This change will make BSD ar(1) -q a *REAL* GNU ar -q:

1. It will update symbol table. (same as unfixed version)
2. It will NOT compare new members spcified in the command line args
with existing members, instead, append them directly.

Reported by: Johannes 5 Joemann <joemann@beefree.free.de>
Reported by: Timothy Bourke <timbob@bigpond.com>
Tested by: Johannes 5 Joemann <joemann@beefree.free.de>
Reviewed by: jkoshy
Approved by: jkoshy (mentor)


# 517dbe2e 02-Mar-2008 Kai Wang <kaiw@FreeBSD.org>

- Do not malloc buffer for 0-size member when reading from archive.
- Fix a malloc buffer overrun: Use a while loop to check whether
the string buffer is big enough after resizing, since doubling
once might not be enough when a very long member name or symbol
name is provided.
- Fix typo.

Reported by: Michael Plass <mfp49_freebsd@plass-family.net>
Tested by: Michael Plass <mfp49_freebsd@plass-family.net>
Reviewed by: jkoshy
Approved by: jkoshy


# 39358b4e 24-Feb-2008 Kai Wang <kaiw@FreeBSD.org>

style(9) whitespace fix: A space is mandated after keyword 'return'.

Submitted by: jkoshy
Approved by: jkoshy (mentor)


# 47203048 24-Feb-2008 Kai Wang <kaiw@FreeBSD.org>

Handle properly when insert zero size objects into the archive:
Do not mmap 0-size objects and do not try to extract symbol from
0-size objects, but do treat 0-size objects as qualified objects and
accept them as an archive member. (A member with only the header part)

Note that GNU binutils ar on FreeBSD ignores 0-size objects, but on
Linux it accepts them. [1] But, since this is a rare usage, we can
safely ignore the compatibility issue.

Reported by: Michael Plass <mfp49_freebsd [AT] plass-family [DOT] net>
Pointed out by: Michael Plass <mfp49_freebsd [AT] plass-family [DOT] net> [1]
Reviewed by: Michael Plass <mfp49_freebsd [AT] plass-family [DOT] net>
Reviewed by: jkoshy
Approved by: jkoshy (mentor)


# d192f3d3 21-Feb-2008 Kai Wang <kaiw@FreeBSD.org>

Import ar(1) front-end. (aka 'BSD' ar)

Reviewed by: jkoshy
Approved by: jkoshy (mentor)
Tested by: erwin (ports build test on pointyhat)
Sponsored by: Google Summer of Code 2007
Reviewed by (earlier version): Jaakko Heinonen <jh[AT]saunalahti.fi>
Tested by (earlier version): Steve Kargl <sgk[AT]troutmask.apl.washington.edu>
Tested by (earlier version): Martin Voros <martin_voros[AT]yahoo.com>
Tested by (earlier version): swell.k[AT]gmail.com
Tested by (earlier version): joel
Tested by (earlier version): Alexey Shuvaev <shuvaev[AT]physik.uni-wuerzburg.de>
Tested by (earlier version): Arjan van Leeuwen <avleeuwen[AT]gmail.com>

Thanks to gabor@ for building ports for it.
Thanks to erwin@ and kris@ for scheduling the ports build test on pointyhat.
And thanks to many others for their feedback.