This is an archive of the discontinued LLVM Phabricator instance.

[llvm-ar] Flatten thin archives.
ClosedPublic

Authored by rupprecht on Jan 9 2019, 11:33 AM.

Details

Summary

Normal behavior for GNU ar is to flatten thin archives when adding them to another thin archive, i.e. add the members directly instead of nesting the archive.

Some refactoring done as part of this patch to ease things:

  • Consolidate addMember/addLibMember methods
  • Rename addMember to addChildMember to make it more visibly different at the call site that an archive child is passed instead of a regular member
  • Pass in a separate vector and splice it back into position instead of passing a vector + optional Pos (which makes expanding libs tricky)

This fixes PR37530 as raised by https://github.com/ClangBuiltLinux/linux/issues/279.

Diff Detail

Event Timeline

rupprecht created this revision.Jan 9 2019, 11:33 AM
This revision is now accepted and ready to land.Jan 12 2019, 4:00 AM
This revision was automatically updated to reflect the committed changes.
ruiu added a comment.Jan 14 2019, 1:29 PM

LGTM

It looks like that behavior is a bit odd, but that's exactly what GNU ar does according to GNU's man page.

void added a subscriber: void.EditedFeb 13 2019, 2:11 PM

This fails if the archives are nested. E.g.:

$ mkdir -p foo/bar
$ cat > foo/bar/a.c <<EOF
int bar() { return 42; }
EOF
$ rm -f built-in.o foo/built-in.o foo/bar/built-in.o ; llvm-ar rcSTD foo/bar/built-in.o foo/bar/a.o ; llvm-ar rcSTD foo/built-in.o foo/bar/built-in.o ; llvm-ar rcSTD built-in.o foo/built-in.o
./llvm.opt.install/bin/llvm-ar: error: 'a.o': No such file or directory.

What's happening is that it's trying to find a.o in foo/ when it's really in foo/bar/.

Herald added a project: Restricted Project. · View Herald TranscriptFeb 13 2019, 2:11 PM

This fails if the archives are nested. E.g.:

$ mkdir -p foo/bar
$ cat > foo/bar/a.c <<EOF
int bar() { return 42; }
EOF
$ rm -f built-in.o foo/built-in.o foo/bar/built-in.o ; llvm-ar rcSTD foo/bar/built-in.o foo/bar/a.o ; llvm-ar rcSTD foo/built-in.o foo/bar/built-in.o ; llvm-ar rcSTD built-in.o foo/built-in.o
./llvm.opt.install/bin/llvm-ar: error: 'a.o': No such file or directory.

What's happening is that it's trying to find a.o in foo/ when it's really in foo/bar/.

That should be fixed by D57842, which I'm planning to submit soon -- I want to poke a few more test cases first.

void added a comment.Feb 13 2019, 2:24 PM

That should be fixed by D57842, which I'm planning to submit soon -- I want to poke a few more test cases first.

Great! Thank you.