Skip to content

Commit

Permalink
[llvm-ar] Support multiple dashed options
Browse files Browse the repository at this point in the history
This allows syntax like:
$ llvm-ar -c -r -u file.a file.o

This is in addition to the other formats that are already supported:
$ llvm-ar cru file.a file.o
$ llvm-ar -cru file.a file.o

Patch by Tom Anderson!

Differential Revision: https://reviews.llvm.org/D44452

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328716 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
pcc committed Mar 28, 2018
1 parent 240b840 commit 59aa450
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 114 deletions.
22 changes: 13 additions & 9 deletions lib/Object/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@

using namespace llvm;

// The SYM64 format is used when an archive's member offsets are larger than
// 32-bits can hold. The need for this shift in format is detected by
// writeArchive. To test this we need to generate a file with a member that has
// an offset larger than 32-bits but this demands a very slow test. To speed
// the test up we use this flag to pretend like the cutoff happens before
// 32-bits and instead happens at some much smaller value.
static cl::opt<int> Sym64Threshold("sym64-threshold", cl::Hidden,
cl::init(32));

NewArchiveMember::NewArchiveMember(MemoryBufferRef BufRef)
: Buf(MemoryBuffer::getMemBuffer(BufRef, false)),
MemberName(BufRef.getBufferIdentifier()) {}
Expand Down Expand Up @@ -490,6 +481,19 @@ Error llvm::writeArchive(StringRef ArcName,
// We assume 32-bit symbols to see if 32-bit symbols are possible or not.
MaxOffset += M.Symbols.size() * 4;
}

// The SYM64 format is used when an archive's member offsets are larger than
// 32-bits can hold. The need for this shift in format is detected by
// writeArchive. To test this we need to generate a file with a member that
// has an offset larger than 32-bits but this demands a very slow test. To
// speed the test up we use this environment variable to pretend like the
// cutoff happens before 32-bits and instead happens at some much smaller
// value.
const char *Sym64Env = std::getenv("SYM64_THRESHOLD");
int Sym64Threshold = 32;
if (Sym64Env)
StringRef(Sym64Env).getAsInteger(10, Sym64Threshold);

// If LastOffset isn't going to fit in a 32-bit varible we need to switch
// to 64-bit. Note that the file can be larger than 4GB as long as the last
// member starts before the 4GB offset.
Expand Down
2 changes: 1 addition & 1 deletion test/Object/archive-GNU64-write.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# RUN: dd if=%t of=%t bs=1 count=0 seek=1M
# RUN: rm -f %t.lib
# RUN: cp %t %t2
# RUN: llvm-ar -sym64-threshold=19 cr %t.lib %t %t2 %p/Inputs/trivial-object-test.elf-x86-64
# RUN: SYM64_THRESHOLD=19 llvm-ar cr %t.lib %t %t2 %p/Inputs/trivial-object-test.elf-x86-64
# RUN: llvm-nm --print-armap %t.lib | FileCheck %s
# RUN: grep SYM64 %t.lib

Expand Down
16 changes: 16 additions & 0 deletions test/tools/llvm-ar/default-add.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,21 @@ RUN: not grep -q __.SYMDEF %t.ar
RUN: llvm-ar crs %t.ar %t-macho.o
RUN: not grep -q __.SYMDEF %t.ar

RUN: rm -f %t.ar
Test that multiple dashed options works.
RUN: llvm-ar -c -r -s %t.ar %t-macho.o
RUN: grep -q __.SYMDEF %t.ar
Test with duplicated options.
RUN: llvm-ar -c -r -s -c -s %t.ar %t-coff.o
RUN: grep -q __.SYMDEF %t.ar

RUN: rm -f %t.ar
Test with the options in a different order.
RUN: llvm-ar rsc %t.ar %t-macho.o
RUN: grep -q __.SYMDEF %t.ar
Test with options everywhere.
RUN: llvm-ar rsc -cs -sc %t.ar %t-coff.o -cs -sc
RUN: grep -q __.SYMDEF %t.ar

Ensure that we select the existing format when updating.

Loading

0 comments on commit 59aa450

Please sign in to comment.