[llvm-commits] [llvm] r140627 - in /llvm/trunk: test/Object/TestObjectFiles/archive-test.a-bitcode test/Object/TestObjectFiles/archive-test.a-coff-i386 test/Object/nm-archive.test tools/llvm-nm/llvm-nm.cpp

Chad Rosier mcrosier at apple.com
Mon Oct 24 18:41:43 PDT 2011


Hi Michael,
Would it be possible for you to rework this test case so that it can generate the archive on the fly, rather than reading in the archive-test.a-* files?  I'm going to begin work on the bitcode reader/writer very soon that will break backward compatibility and in turn break this test case.  See r142896 for examples of what was necessary for a few other test cases.

 Regards,
  Chad


On Sep 27, 2011, at 12:37 PM, Michael J. Spencer wrote:

> Author: mspencer
> Date: Tue Sep 27 14:37:18 2011
> New Revision: 140627
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=140627&view=rev
> Log:
> Add binary archive support to llvm-nm.
> 
> Added:
>    llvm/trunk/test/Object/TestObjectFiles/archive-test.a-bitcode
>    llvm/trunk/test/Object/TestObjectFiles/archive-test.a-coff-i386
>    llvm/trunk/test/Object/nm-archive.test
> Modified:
>    llvm/trunk/tools/llvm-nm/llvm-nm.cpp
> 
> Added: llvm/trunk/test/Object/TestObjectFiles/archive-test.a-bitcode
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/TestObjectFiles/archive-test.a-bitcode?rev=140627&view=auto
> ==============================================================================
> Binary files llvm/trunk/test/Object/TestObjectFiles/archive-test.a-bitcode (added) and llvm/trunk/test/Object/TestObjectFiles/archive-test.a-bitcode Tue Sep 27 14:37:18 2011 differ
> 
> Added: llvm/trunk/test/Object/TestObjectFiles/archive-test.a-coff-i386
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/TestObjectFiles/archive-test.a-coff-i386?rev=140627&view=auto
> ==============================================================================
> Binary files llvm/trunk/test/Object/TestObjectFiles/archive-test.a-coff-i386 (added) and llvm/trunk/test/Object/TestObjectFiles/archive-test.a-coff-i386 Tue Sep 27 14:37:18 2011 differ
> 
> Added: llvm/trunk/test/Object/nm-archive.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-archive.test?rev=140627&view=auto
> ==============================================================================
> --- llvm/trunk/test/Object/nm-archive.test (added)
> +++ llvm/trunk/test/Object/nm-archive.test Tue Sep 27 14:37:18 2011
> @@ -0,0 +1,17 @@
> +RUN: llvm-nm %p/TestObjectFiles/archive-test.a-coff-i386 \
> +RUN:         | FileCheck %s -check-prefix COFF
> +RUN: llvm-nm %p/TestObjectFiles/archive-test.a-bitcode \
> +RUN:         | FileCheck %s -check-prefix BITCODE
> +
> +
> +COFF: trivial-object-test.coff-i386:
> +COFF-NEXT: 00000000 d .data
> +COFF-NEXT: 00000000 t .text
> +COFF-NEXT: 00000000 d L_.str
> +COFF-NEXT:          U _SomeOtherFunction
> +COFF-NEXT: 00000000 T _main
> +COFF-NEXT:          U _puts
> +
> +BITCODE:          U SomeOtherFunction
> +BITCODE-NEXT:          T main
> +BITCODE-NEXT:          U puts
> 
> Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=140627&r1=140626&r2=140627&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
> +++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Tue Sep 27 14:37:18 2011
> @@ -20,6 +20,7 @@
> #include "llvm/Module.h"
> #include "llvm/Bitcode/ReaderWriter.h"
> #include "llvm/Bitcode/Archive.h"
> +#include "llvm/Object/Archive.h"
> #include "llvm/Object/ObjectFile.h"
> #include "llvm/Support/CommandLine.h"
> #include "llvm/Support/FileSystem.h"
> @@ -318,18 +319,34 @@
>       errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
> 
>   } else if (aPath.isArchive()) {
> -    std::string ErrMsg;
> -    Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), Context,
> -                                            &ErrorMessage);
> -    if (!archive)
> -      errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
> -    std::vector<Module *> Modules;
> -    if (archive->getAllModules(Modules, &ErrorMessage)) {
> -      errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
> +    OwningPtr<Binary> arch;
> +    if (error_code ec = object::createBinary(aPath.str(), arch)) {
> +      errs() << ToolName << ": " << Filename << ": " << ec.message() << ".\n";
>       return;
>     }
> -    MultipleFiles = true;
> -    std::for_each (Modules.begin(), Modules.end(), DumpSymbolNamesFromModule);
> +    if (object::Archive *a = dyn_cast<object::Archive>(arch.get())) {
> +      for (object::Archive::child_iterator i = a->begin_children(),
> +                                           e = a->end_children(); i != e; ++i) {
> +        OwningPtr<Binary> child;
> +        if (error_code ec = i->getAsBinary(child)) {
> +          // Try opening it as a bitcode file.
> +          MemoryBuffer *buff = i->getBuffer();
> +          Module *Result = 0;
> +          if (buff)
> +            Result = ParseBitcodeFile(buff, Context, &ErrorMessage);
> +
> +          if (Result) {
> +            DumpSymbolNamesFromModule(Result);
> +            delete Result;
> +          }
> +          continue;
> +        }
> +        if (object::ObjectFile *o = dyn_cast<ObjectFile>(child.get())) {
> +          outs() << o->getFileName() << ":\n";
> +          DumpSymbolNamesFromObject(o);
> +        }
> +      }
> +    }
>   } else if (aPath.isObjectFile()) {
>     OwningPtr<Binary> obj;
>     if (error_code ec = object::createBinary(aPath.str(), obj)) {
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list