Commit Graph

167 Commits

Author SHA1 Message Date
NAKAMURA Takumi
6af8781854 llvm-ar: Let opening a directory failed in llvm-ar.
Linux cannot open directories with open(2), although cygwin and *bsd can.

Motivation: The test, Object/directory.ll, had been failing with --target=cygwin on Linux. XFAIL was improper for host issues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194257 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-08 12:35:56 +00:00
Rafael Espindola
54818dc746 Support names like llvm-ar-3.4 and llvm-ranlib-3.4.
They are used in some packages. For example:
http://packages.ubuntu.com/saucy/i386/llvm-3.4/filelist

This fixes pr17721.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193612 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-29 14:25:43 +00:00
Rafael Espindola
98b5be8062 Fix name matching to work on windows.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189517 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-28 21:00:03 +00:00
Rafael Espindola
aeb0f0cdd2 Add a minimal implementation of ranlib.
This is just enough to get "llvm-ranlib foo.a" working and tested. Making
llvm-ranlib a symbolic link to llvm-ar doesn't work so well with llvm's option
parsing, but ar's option parsing is mostly custom anyway.

This patch also removes the -X32_64 option. Looks like it was just added in
r10297 as part of implementing the current command line parsing. I can add it
back (with a test) if someone really has AIX portability problems without it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189489 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-28 16:22:16 +00:00
Rafael Espindola
cf48cf23de Add support for the 's' operation to llvm-ar.
If no other operation is specified, 's' becomes an operation instead of an
modifier. The s operation just creates a symbol table. It is the same as
running ranlib.

We assume the archive was created by a sane ar (like llvm-ar or gnu ar) and
if the symbol table is present, then it is current. We use that to optimize
the most common case: a broken build system that thinks it has to run ranlib.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187353 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-29 12:40:31 +00:00
Rafael Espindola
70c7e48545 Split getOpenFile into getOpenFile and getOpenFileSlice.
The main observation is that we never need both the filesize and the map size.
When mapping a slice of a file, it doesn't make sense to request a null
terminator and that would be the only case where the filesize would be used.

There are other cleanups that should be done in this area:

* A client should not have to pass the size (even an explicit -1) to say if
  it wants a null terminator or not, so we should probably swap the argument
  order.
* The default should be to not require a null terminator. Very few clients
  require this, but many end up asking for it just because it is the default.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186984 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-23 20:25:01 +00:00
Rafael Espindola
af02bf4a58 Fix the build in c++03 mode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186935 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-23 11:02:16 +00:00
Rafael Espindola
26b10da9c2 Add an initial implementation of archive symbol table generation.
The symbol table has forward references in the file. Instead of allocating
a temporary buffer or counting the size and then writing, this implementation
writes a dummy value first and patches it once the final value is known.

There is room for performance improvement. I will implement them as soon as I
get some other features (like a ranlib mode) in.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186934 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-23 10:47:01 +00:00
Rafael Espindola
51392a079e Replace archive members in the old position.
This matches gnu archive behavior and since archive member order can change
which member is used, not changing the order on replacement looks like the
right thing to do.

This patch also refactors the logic for which archive member to keep and
whether to move it to a helper function (computeInsertAction). The
nesting in computeNewArchiveMembers was getting a bit confusing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186829 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-22 15:11:51 +00:00
Rafael Espindola
02a1364bf8 Handle replacement into a position past the original member.
We were incorrectly computing where to insert a member if it was replacing
a previous member that was before the insert point.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186792 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-21 12:58:07 +00:00
Rafael Espindola
b55dcfe47f Fix inserting new elements in a specified location.
We were only handling the 'a' and 'b' options during moves before.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186721 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-19 21:23:28 +00:00
NAKAMURA Takumi
946dbd83df llvm-ar: doExtract(): Write extracted files with F_Binary. It should fix llvm/test/Object/extract.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186503 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-17 12:31:50 +00:00
Rafael Espindola
c1b49b56d4 Add a wrapper for open.
This centralizes the handling of O_BINARY and opens the way for hiding more
differences (like how open behaves with directories).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186447 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16 19:44:17 +00:00
Rafael Espindola
95779b65cf On error, close the temporary file descriptor.
With this change llvm-ar can remove the temporary file on windows too.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186423 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16 16:00:32 +00:00
Rafael Espindola
bd6cb260b9 Use open+fstat instead of stat+open.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186381 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16 03:34:31 +00:00
Rafael Espindola
289e241d77 Remember that we have a null terminated string.
This is a micro optimization. Instead of going char*->StringRef->Twine->char*,
go char*->Twine->char* and avoid having to copy the filename on the stack.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186380 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-16 03:30:10 +00:00
Rafael Espindola
718af78920 Try to open the file before use data from stat.
Looks like on mingw we get bogus last modification times on directories.
Should fix the mingw bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186240 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-13 05:07:22 +00:00
Rafael Espindola
ee795f35f7 Remove unused file. Thanks to Sean Silva for noticing it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186239 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-13 04:24:33 +00:00
Rafael Espindola
c951651894 Add r186216 back, but make the test tolerant of different uids and gids.
original message:
Fix a off by one error about which members need to use the string table.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186238 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-13 04:14:13 +00:00
Chandler Carruth
1dedabdfad Revert commit r186216 -- it's breaking bots:
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/6897/steps/check-all/logs/LLVM%3A%3Aarchive-format.test

Original commit log:
  Fix a off by one error about which members need to use the string
  table.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186232 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-13 00:42:56 +00:00
Rafael Espindola
6383ef98fa Fix a off by one error about which members need to use the string table.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186216 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-12 22:22:34 +00:00
Rafael Espindola
f745d95347 fix autoconf build
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186200 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-12 20:45:01 +00:00
Rafael Espindola
33ccfb2d26 Fix the build with c++03.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186198 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-12 20:28:02 +00:00
Rafael Espindola
34ac52d937 Change llvm-ar to use lib/Object.
This fixes two bugs is lib/Object that the use in llvm-ar found:
* In OS X created archives, the name can be padded with nulls. Strip them.
* In the constructor, remember the first non special member and use that in
  begin_children. This makes sure we skip all special members, not just the
  first one.

The change to llvm-ar itself consist of
* Using lib/Object for reading archives instead of ArchiveReader.cpp.
* Writing the modified archive directly, instead of creating an in memory
  representation.

The old Archive library was way more general than what is needed, as can
be seen by the diffstat of this patch.

Having llvm-ar using lib/Object now opens the way for creating regular symbol
tables for both native objects and bitcode files so that we can use those
archives for LTO.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186197 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-12 20:21:39 +00:00
Rafael Espindola
2494dfcf17 Add static.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186170 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-12 16:29:27 +00:00
Benjamin Kramer
7172b38af7 llvm-ar: Clean up memory management with OwningPtr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186131 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 23:15:05 +00:00
Rafael Espindola
4d5b0da81b Use %llu to print a 64 bit number. Should fix the ARM bots.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186113 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 20:01:30 +00:00
Rafael Espindola
1b3e3eef1f InsertBefore is the same as AddBefore. Delete it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186094 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 15:54:53 +00:00
Rafael Espindola
71857ccdb8 Fix a FIXME about the format and add a test.
While at it, use strftime on Unix too and use the thread safe versions
of localtime.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186090 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 15:35:23 +00:00
Rafael Espindola
1b0dc64919 Remove the 'N' modifier from llvm-ar.
* It is not present on OS X.
* It is untested.
* It is not needed for using ar in a build system.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186080 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 13:03:27 +00:00
Rafael Espindola
55804a089e Delete dead code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186079 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 12:54:11 +00:00
Rafael Espindola
ab7348f8b1 Remove support for truncating names in archives.
* All systems we support have some form of long name support.
* The options has different names and semantics in different implementations
  ('f' on gnu, 'T' on OS X), which makes it unlikely it is normally used on
  build systems.
* It was completely untested.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186078 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 12:38:02 +00:00
Rafael Espindola
4f2779b809 Sync llvm-ar's help string with the options it supports.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186076 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-11 12:28:36 +00:00
Rafael Espindola
35637fc623 Create files with the correct permission instead of changing it afterwards.
No intended functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185832 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-08 16:16:51 +00:00
Manuel Klimek
a012a66688 Fixes problem when calling llvm-ar from an unmodifiable directory.
This fixes a regression introduced by r185726: the new call to get
a unique file does not prepend the system temporary directory, so
we need to anchor on the file that the temporary file gets moved
to to ensure we're on the same file system.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185825 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-08 14:44:57 +00:00
Michael Gottesman
2be430d251 [llvm-ar] Added llvm_unreachable to quiet -Wreturn-type warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185751 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-06 02:39:51 +00:00
Rafael Espindola
200c748a86 Add a createUniqueFile function and switch llvm's users of unique_file.
This function is complementary to createTemporaryFile. It handles the case were
the unique file is *not* temporary: we will rename it in the end. Since we
will rename it, the file has to be in the same filesystem as the final
destination and we don't prepend the system temporary directory.

This has a small semantic difference from unique_file: the default mode is 0666.
This matches the behavior of most unix tools. For example, with this change
lld now produces files with the same permissions as ld. I will add a test
of this change when I port clang over to createUniqueFile (next commit).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185726 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-05 21:01:08 +00:00
Rafael Espindola
61de142984 Don't create an archive if, for example, we are asked to print the index.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185697 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-05 13:03:07 +00:00
Rafael Espindola
ef2703a1fb Use simpler version of exists.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185695 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-05 12:44:49 +00:00
Rafael Espindola
87b8a7f999 Remove NoOperation.
parseCommandLine prints and error and exists if no operation is specified, so
it never returns NoOperation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185691 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-05 12:12:43 +00:00
Rafael Espindola
24663f69cc Don't treat bitcode files specially in llvm-ar.
We really want bitcode files to behave as regular object files in archives, so
we don't need to track that a member is bitcode.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185681 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-05 04:19:32 +00:00
Rafael Espindola
97c2a0a110 Use enums instead of raw octal values.
Patch by 罗勇刚(Yonggang Luo).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184971 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-26 17:28:04 +00:00
Rafael Espindola
19ead5a9f1 Create the file with the right permissions instead of setting it afterwards.
Removes the last use of PathV1.h in llvm-ar.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184630 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-22 02:34:24 +00:00
Rafael Espindola
995017caf9 Convert some uses of PathV1.h in ArchiveWriter.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184599 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-21 22:11:36 +00:00
Rafael Espindola
8874cc242b Add a fixme.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184486 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-20 22:04:56 +00:00
Rafael Espindola
bdae6fa82c Remove last use of PathV1.h from Archive.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184484 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-20 22:02:10 +00:00
Rafael Espindola
11ca2e508c Add a setLastModificationAndAccessTime to PathV2.
With this we can remove the last use of PathV1 from llvm-ar.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184464 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-20 20:56:14 +00:00
Rafael Espindola
f9f44f3d5a Use a raw_fd_ostream instead of a std::ofstream.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184460 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-20 19:50:39 +00:00
Rafael Espindola
201c66c9b0 Remove a trivial use of sys::Path.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184455 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-20 18:55:44 +00:00
Rafael Espindola
29c17db650 Add support for getting the last modification time from a file_status.
Use that in llvm-ar.cpp to replace a use of sys::PathWithStatus.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184450 91177308-0d34-0410-b5e6-96231b3b80d8
2013-06-20 18:42:04 +00:00