[llvm] r189489 - Add a minimal implementation of ranlib.
Alexey Samsonov
samsonov at google.com
Thu Aug 29 02:37:58 PDT 2013
Hi Rafael!
I get the following error when running check-llvm locally:
Failing Tests (1):
LLVM :: Object/archive-symtab.test
<...>
Invalid alignment for ELF file!
UNREACHABLE executed at /llvm/lib/Object/ELFObjectFile.cpp:67
llvm-nm crashes after we create the symbol table for archive with
llvm-ranlib.
Does the latter enforces the correct alignment of archive members?
On Wed, Aug 28, 2013 at 8:22 PM, Rafael Espindola <
rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Wed Aug 28 11:22:16 2013
> New Revision: 189489
>
> URL: http://llvm.org/viewvc/llvm-project?rev=189489&view=rev
> Log:
> 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.
>
> Modified:
> llvm/trunk/test/Object/archive-symtab.test
> llvm/trunk/tools/llvm-ar/CMakeLists.txt
> llvm/trunk/tools/llvm-ar/Makefile
> llvm/trunk/tools/llvm-ar/llvm-ar.cpp
>
> Modified: llvm/trunk/test/Object/archive-symtab.test
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/archive-symtab.test?rev=189489&r1=189488&r2=189489&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Object/archive-symtab.test (original)
> +++ llvm/trunk/test/Object/archive-symtab.test Wed Aug 28 11:22:16 2013
> @@ -48,3 +48,12 @@ CORRUPT-NEXT: 00000016 T main
> check that the we *don't* update the symbol table.
> RUN: llvm-ar s %t.a
> RUN: llvm-nm -s %t.a | FileCheck %s --check-prefix=CORRUPT
> +
> +repeate the test with llvm-ranlib
> +
> +RUN: rm -f %t.a
> +RUN: llvm-ar rcS %t.a %p/Inputs/trivial-object-test.elf-x86-64
> %p/Inputs/trivial-object-test2.elf-x86-64
> +RUN: llvm-nm -s %t.a | FileCheck %s --check-prefix=NOMAP
> +
> +RUN: llvm-ranlib %t.a
> +RUN: llvm-nm -s %t.a | FileCheck %s
>
> Modified: llvm/trunk/tools/llvm-ar/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/CMakeLists.txt?rev=189489&r1=189488&r2=189489&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-ar/CMakeLists.txt (original)
> +++ llvm/trunk/tools/llvm-ar/CMakeLists.txt Wed Aug 28 11:22:16 2013
> @@ -4,4 +4,22 @@ add_llvm_tool(llvm-ar
> llvm-ar.cpp
> )
>
> +# FIXME: this is duplicated from the clang CMakeLists.txt
> +# FIXME: bin/llvm-ranlib is not a valid build target with this setup
> (pr17024)
> +
> +if(UNIX)
> + set(LLVM_LINK_OR_COPY create_symlink)
> + set(llvm_ar_binary "llvm-ar${CMAKE_EXECUTABLE_SUFFIX}")
> +else()
> + set(LLVM_LINK_OR_COPY copy)
> + set(llvm_ar_binary
> "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}")
> +endif()
> +
> +set(llvm_ranlib
> "${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX}")
> +add_custom_command(TARGET llvm-ar POST_BUILD
> + COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${llvm_ar_binary}"
> "${llvm_ranlib}")
> +
> +set_property(DIRECTORY APPEND
> + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${llvm_ranlib})
> +
> # TODO: Support check-local.
>
> Modified: llvm/trunk/tools/llvm-ar/Makefile
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/Makefile?rev=189489&r1=189488&r2=189489&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-ar/Makefile (original)
> +++ llvm/trunk/tools/llvm-ar/Makefile Wed Aug 28 11:22:16 2013
> @@ -9,6 +9,7 @@
>
> LEVEL := ../..
> TOOLNAME := llvm-ar
> +TOOLALIAS = llvm-ranlib
> LINK_COMPONENTS := bitreader support object
>
> # This tool has no plugins, optimize startup time.
>
> Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=189489&r1=189488&r2=189489&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
> +++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Aug 28 11:22:16 2013
> @@ -63,20 +63,13 @@ static void failIfError(error_code EC, T
> fail(Context + ": " + EC.message());
> }
>
> -// Option for compatibility with AIX, not used but must allow it to be
> present.
> -static cl::opt<bool>
> -X32Option ("X32_64", cl::Hidden,
> - cl::desc("Ignored option for compatibility with AIX"));
> -
> -// llvm-ar operation code and modifier flags. This must come first.
> -static cl::opt<std::string>
> -Options(cl::Positional, cl::Required,
> cl::desc("{operation}[modifiers]..."));
> -
> -// llvm-ar remaining positional arguments.
> +// llvm-ar/llvm-ranlib remaining positional arguments.
> static cl::list<std::string>
> RestOfArgs(cl::Positional, cl::OneOrMore,
> cl::desc("[relpos] [count] <archive-file> [members]..."));
>
> +std::string Options;
> +
> // MoreHelp - Provide additional help output explaining the operations and
> // modifiers of llvm-ar. This object instructs the CommandLine library
> // to print the text of the constructor when the --help option is given.
> @@ -156,6 +149,13 @@ static void getRelPos() {
> RestOfArgs.erase(RestOfArgs.begin());
> }
>
> +static void getOptions() {
> + if(RestOfArgs.size() == 0)
> + show_help("Expected options");
> + Options = RestOfArgs[0];
> + RestOfArgs.erase(RestOfArgs.begin());
> +}
> +
> // getArchive - Get the archive file name from the command line
> static void getArchive() {
> if(RestOfArgs.size() == 0)
> @@ -175,6 +175,7 @@ static void getMembers() {
> // operation specified. Process all modifiers and check to make sure that
> // constraints on modifier/operation pairs have not been violated.
> static ArchiveOperation parseCommandLine() {
> + getOptions();
>
> // Keep track of number of operations. We can only specify one
> // per execution.
> @@ -857,6 +858,9 @@ static void performOperation(ArchiveOper
> llvm_unreachable("Unknown operation.");
> }
>
> +static int ar_main(char **argv);
> +static int ranlib_main();
> +
> // main - main program for llvm-ar .. see comments in the code
> int main(int argc, char **argv) {
> ToolName = argv[0];
> @@ -872,15 +876,35 @@ int main(int argc, char **argv) {
> " This program archives bitcode files into single libraries\n"
> );
>
> + if (ToolName.endswith("ar"))
> + return ar_main(argv);
> + if (ToolName.endswith("ranlib"))
> + return ranlib_main();
> + fail("Not ranlib or ar!");
> +}
> +
> +static int performOperation(ArchiveOperation Operation);
> +
> +int ranlib_main() {
> + if (RestOfArgs.size() != 1)
> + fail(ToolName + "takes just one archive as argument");
> + ArchiveName = RestOfArgs[0];
> + return performOperation(CreateSymTab);
> +}
> +
> +int ar_main(char **argv) {
> // Do our own parsing of the command line because the CommandLine
> utility
> // can't handle the grouped positional parameters without a dash.
> ArchiveOperation Operation = parseCommandLine();
> + return performOperation(Operation);
> +}
>
> +static int performOperation(ArchiveOperation Operation) {
> // Create or open the archive object.
> OwningPtr<MemoryBuffer> Buf;
> error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false);
> if (EC && EC != llvm::errc::no_such_file_or_directory) {
> - errs() << argv[0] << ": error opening '" << ArchiveName
> + errs() << ToolName << ": error opening '" << ArchiveName
> << "': " << EC.message() << "!\n";
> return 1;
> }
> @@ -889,7 +913,7 @@ int main(int argc, char **argv) {
> object::Archive Archive(Buf.take(), EC);
>
> if (EC) {
> - errs() << argv[0] << ": error loading '" << ArchiveName
> + errs() << ToolName << ": error loading '" << ArchiveName
> << "': " << EC.message() << "!\n";
> return 1;
> }
> @@ -904,7 +928,7 @@ int main(int argc, char **argv) {
> } else {
> if (!Create) {
> // Produce a warning if we should and we're creating the archive
> - errs() << argv[0] << ": creating " << ArchiveName << "\n";
> + errs() << ToolName << ": creating " << ArchiveName << "\n";
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130829/e6c78616/attachment.html>
More information about the llvm-commits
mailing list