Page MenuHomePhabricator

[llvm-libtool-darwin] Allow flattening archives

Authored by sameerarora101 on Jul 9 2020, 3:55 PM.



Add support for flattening archives while creating static libraries. As
per cctools' libtool's behavior, llvm-libtool-darwin does not flatten
archives recursively. Depends on D83002.

Diff Detail

Unit TestsFailed

460 mslinux > SanitizerCommon-asan-x86_64-Linux.Linux::Unknown Unit Message ("")
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=address -m64 -ldl -std=c++11 -O0 -g /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Linux/Output/protoent.cpp.tmp && /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/asan-x86_64-Linux/Linux/Output/protoent.cpp.tmp 2>&1 | FileCheck /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
290 mslinux > SanitizerCommon-lsan-x86_64-Linux.Linux::Unknown Unit Message ("")
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=leak -m64 -ldl -std=c++11 -O0 -g /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/lsan-x86_64-Linux/Linux/Output/protoent.cpp.tmp && /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/lsan-x86_64-Linux/Linux/Output/protoent.cpp.tmp 2>&1 | FileCheck /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
390 mslinux > SanitizerCommon-msan-x86_64-Linux.Linux::Unknown Unit Message ("")
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=memory -m64 -ldl -std=c++11 -O0 -g /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/msan-x86_64-Linux/Linux/Output/protoent.cpp.tmp && /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/msan-x86_64-Linux/Linux/Output/protoent.cpp.tmp 2>&1 | FileCheck /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
430 mslinux > SanitizerCommon-tsan-x86_64-Linux.Linux::Unknown Unit Message ("")
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=thread -m64 -ldl -std=c++11 -O0 -g /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/tsan-x86_64-Linux/Linux/Output/protoent.cpp.tmp && /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/tsan-x86_64-Linux/Linux/Output/protoent.cpp.tmp 2>&1 | FileCheck /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp
330 mslinux > SanitizerCommon-ubsan-x86_64-Linux.Linux::Unknown Unit Message ("")
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=undefined -m64 -ldl -std=c++11 -O0 -g /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/ubsan-x86_64-Linux/Linux/Output/protoent.cpp.tmp && /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/sanitizer_common/ubsan-x86_64-Linux/Linux/Output/protoent.cpp.tmp 2>&1 | FileCheck /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/protoent.cpp

Event Timeline

sameerarora101 created this revision.Jul 9 2020, 3:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2020, 3:55 PM
sameerarora101 retitled this revision from [llvm-libtool-darwin] Allow flatenning archives to [llvm-libtool-darwin] Allow flattening archives.Jul 9 2020, 4:15 PM

Updating type and comments

verifyDarwinObject -> verifyMachOObject

MachO -> Mach-O in comments

jhenderson added inline comments.Jul 15 2020, 1:38 AM

Instead of using a separate Inputs file, you might want to consider using echo to create the input file on the fly. That has the advantage of keeping the test self-contained - you don't have to go looking elsewhere to understand what exactly is going on.


I take it this behaviour is taken from the original libtool?


Are you deliberately trying to add the archive symbol index here? That is done implicitly by llvm-ar anyway, so cr is sufficient.


This needs fixing (you are deleting the archive from the previous case, not the two archives from this case).




Consider using a different archive file name here, so that you don't overwrite the archive from the earlier case. This can be useful in some debugging situations.


I'd rename this test archive-flattening.test. You should also fold in the invalid cases into it, as there's no need to keep them separate.


What's the reasoning for deleting %t.lib explicitly here?


Don't use auto here. It's not obvious what the type is.

sameerarora101 marked 11 inline comments as done.Jul 15 2020, 8:00 AM
sameerarora101 added inline comments.

Yup, cctools' libtool also throws an error for this case


Oh yeah, I don't need to do that as llvm-libtool-darwin overwrites it. Removed now. Thanks

sameerarora101 marked 2 inline comments as done.

Merge tests into archive-flattening.test

jhenderson accepted this revision.Jul 16 2020, 12:37 AM

LGTM, with the test case reordering. If you want to wait for D83834 too, then that's fine by me.

6 ↗(On Diff #278193)

I'd reverse the order - put the positive cases before the negative ones.

7–8 ↗(On Diff #278193)

It's not committed at the time of writing, but D83834 adds a utility to split an input file into smaller pieces. It might be an even nicer way than using echo to emit the archive.

This revision is now accepted and ready to land.Jul 16 2020, 12:37 AM
sameerarora101 marked 3 inline comments as done.Jul 16 2020, 7:13 AM
sameerarora101 added inline comments.
7–8 ↗(On Diff #278193)

Ok, I can wait for it (while I also need to wait for few others to review this diff) Thanks!

sameerarora101 marked an inline comment as done.

Putting positive tests before negative ones.

smeenai accepted this revision.Jul 20 2020, 10:21 AM


27 ↗(On Diff #278469)

The archive format is more properly referred to as "Darwin" (at least that's the terminology LLVM uses); the object file format is Mach-O.

sameerarora101 marked 2 inline comments as done.Jul 20 2020, 12:20 PM
sameerarora101 added inline comments.
27 ↗(On Diff #278469)

ok, got it! Thanks

sameerarora101 marked an inline comment as done.

Mach-O -> Darwin for archive format in comments

smeenai added inline comments.Jul 20 2020, 12:57 PM

Thinking through this a little more, Err is passed to the iterator to indicate iteration issues, so you should be checking it inside the loop in each iteration (probably before you call addChildMember). You still need to do an explicit check of Err afterward, so that in the case where the loop didn't iterate at all, the Error is still considered checked (it's guaranteed to be a success in that case, but you still need to do an explicit boolean check to mark it as checked). Perhaps the following would suffice for that? I'm not sure what pattern other parts of the codebase use for this.

smeenai added inline comments.Jul 20 2020, 3:10 PM

Ah, never mind. The iteration will stop in case of an error, so having the error check after the loop is perfectly fine. (See llvm/include/llvm/ADT/fallible_iterator.)

jhenderson added inline comments.Jul 21 2020, 12:53 AM

I had basically this same thought originally too, but this is the pattern for looping through archive members elsewhere, so I realised it was safe.

This revision was automatically updated to reflect the committed changes.