This is an archive of the discontinued LLVM Phabricator instance.

[llvm-ar] Add --thin for creating a thin archive
ClosedPublic

Authored by MaskRay on Jan 10 2022, 3:15 PM.

Details

Summary

In GNU ar (since 2008), the modifier 'T' means creating a thin archive.
In many other ar implementations (FreeBSD, macOS, elfutils, etc), -T
means "allow filename truncation of extracted files", as specified by
X/Open System Interface.

For portability, 'T' with thin archive semantics should be avoided.

See https://sourceware.org/bugzilla/show_bug.cgi?id=28759 binutils 2.38
will deprecate 'T' (without diagnostic) and add --thin.

Diff Detail

Event Timeline

MaskRay created this revision.Jan 10 2022, 3:15 PM
MaskRay requested review of this revision.Jan 10 2022, 3:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2022, 3:15 PM
compnerd added inline comments.
llvm/tools/llvm-ar/llvm-ar.cpp
122
MaskRay updated this revision to Diff 398764.Jan 10 2022, 3:49 PM
MaskRay marked an inline comment as done.

fix typo

MaskRay updated this revision to Diff 398766.Jan 10 2022, 3:51 PM

update doc

jhenderson added inline comments.Jan 11 2022, 1:45 AM
llvm/docs/CommandGuide/llvm-ar.rst
204–206

"from" isn't the right word here, and because of that, I'm struggling to understand the meaning of this sentence. I'd suggest rewording.

I'm also somewhat opposed to deprecating the existing form. We have many users who are using thin archives, and will be using the T form to generate their archives. Deprecation implies that the option will be removed in a few releases time, but that would break all those users. Yes, it's a small change for them to make, but I don't really see the benefit. Most people probably don't care about the portability aspects of their build scripts.

Another related issue is that T is a modifier that is grouped with other operations and modifiers like 'r' and 'c', to form Trc or similar, whereas --thin is a long-form option. I suspect most llvm-ar users are more familiar with the short-form versions, and don't even know that llvm-ar has a long-form.

284–287

Text isn't wrapped properly.

MaskRay updated this revision to Diff 398972.Jan 11 2022, 8:53 AM
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision. (Show Details)

Reworking documentation

llvm/docs/CommandGuide/llvm-ar.rst
204–206

Reworded.

The deprecation semantic here is soft - no diagnostics. I think it will keep this way for a while. The Linux kernel uses it (kbuild: allow architectures to use thin archives instead of ld -r) since 2016.

elfutils has had the XSI -T since 2007. FreeBSD's and macOS's may be earlier. elfutils is used a lot on Linux, too, though its usage, compared with binutils, is fairly small. The thin/XSI conflict is unfortunate, and llvm-ar taking 'T' has some issues outside Linux (https://github.com/llvm/llvm-project/issues/25899#issuecomment-1009388242). If you find packages using T for thin archives, I'd still suggest that you try migrating away, if the available version (binutils>=2.38, llvm-ar>=14) is not a problem.

If you still think "Deprecated alias for --thin" is a problem, how about "Alias for --thin for compatibility"?

llvm/tools/llvm-ar/llvm-ar.cpp
122

Thanks!

I understand your hesitation @jhenderson regarding the loss of the short option, maybe a replacement short option could be found?

jhenderson added inline comments.Jan 12 2022, 1:44 AM
llvm/docs/CommandGuide/llvm-ar.rst
204–206

Rather than deprecating the llvm-ar meaning of -T, perhaps the elfutils version should be deprecated? Truncating the filename hardly seems like useful functionality to me... I noticed that @emaste has turned off the -T functionality in FreeBSD ar, which means there's only macOS and elfutils remaining as other archivers (and including our proprietary archiver, I know of three current archivers that use T for thin archives - our version, llvm-ar and GNU ar).

llvm-ar is designed primarily to be a drop-in replacement for GNU ar. I guess I'm okay if we deprecate the option, if the GNU binutils community wish to deprecate it on their side (though I would question if that community has really considered this heavily), and we can then decide whether to remove it in the future, if they choose to. If they don't there's no point in deprecating it in llvm-ar.

MaskRay added inline comments.Jan 12 2022, 1:57 AM
llvm/docs/CommandGuide/llvm-ar.rst
204–206

The 2004 edition of https://pubs.opengroup.org/onlinepubs/009696899/utilities/ar.html mentioned -T, so this was indeed a binutils created portability issue. I think it is unfair to say that elfutils T is the one to be deprecated....

As of binutils 2.38, T has been deprecated (just without diagnostic). I hope folks can find users of T for thin archives can help migrate them to --thin. After a while, binutils T can introduce a warning and perhaps after few years T can be removed.

jhenderson accepted this revision.Feb 1 2022, 2:22 AM

I'm still not particularly happy with either the interface (double dash options in archivers are pretty unusual) or wording (I'm not convinced we should be deprecating a useful option due to it clashing with one that has no particular benefit, although I acknowledge the Open Group publication), but I don't think it's enough to block this change. LGTM.

This revision is now accepted and ready to land.Feb 1 2022, 2:22 AM

Hi @MaskRay, apologies for the wait in this review. I think James brought up a good point regarding gnu ar still using T. I realise that when moving towards consistency someone has to go first, but it maybe worth us waiting until they make the change so we maintain compatibility. Do we know if they have plans to move over to --thin?

MaskRay added a comment.EditedFeb 1 2022, 9:47 AM

@jhenderson Thanks!

Hi @MaskRay, apologies for the wait in this review. I think James brought up a good point regarding gnu ar still using T. I realise that when moving towards consistency someone has to go first, but it maybe worth us waiting until they make the change so we maintain compatibility. Do we know if they have plans to move over to --thin?

GNU ar's -T has been deprecated. The problem is whether any project is using T. These projects cannot straightforwardly migrate if llvm-ar does not have T.
The T problem may also be the reason that other implementations cannot change their T.

I think GNU ar T for thin may be removed, but that may take several years...

For double-dash options, GNU ar now has more such options:

 --target=BFDNAME - specify the target object format as BFDNAME
 --output=DIRNAME - specify the output directory for extraction operations
 --record-libdeps=<text> - specify the dependencies of this library
optional:
 --plugin <p> - load the specified plugin

It's indeed rare in other tools. (POSIX doesn't specify --; -- may be a GNU thing)

MaskRay updated this revision to Diff 404978.Feb 1 2022, 9:55 AM

Don't say 'T' is deprecated

This revision was landed with ongoing or failed builds.Feb 1 2022, 9:57 AM
This revision was automatically updated to reflect the committed changes.

@MaskRay Thanks for clarifying.