[llvm] r217930 - [llvm-objdump] properly use c_str() with format("%s"). Improve getLibraryShortNameByIndex() error handling.
Rafael EspĂndola
rafael.espindola at gmail.com
Tue Sep 16 21:02:13 PDT 2014
testcase for the error handling?
On 16 September 2014 20:25, Nick Kledzik <kledzik at apple.com> wrote:
> Author: kledzik
> Date: Tue Sep 16 19:25:22 2014
> New Revision: 217930
>
> URL: http://llvm.org/viewvc/llvm-project?rev=217930&view=rev
> Log:
> [llvm-objdump] properly use c_str() with format("%s"). Improve getLibraryShortNameByIndex() error handling.
>
>
>
>
> Modified:
> llvm/trunk/lib/Object/MachOObjectFile.cpp
> llvm/trunk/test/tools/llvm-objdump/macho-bind.test
> llvm/trunk/test/tools/llvm-objdump/macho-lazy-bind.test
> llvm/trunk/tools/llvm-objdump/MachODump.cpp
>
> Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=217930&r1=217929&r2=217930&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/MachOObjectFile.cpp Tue Sep 16 19:25:22 2014
> @@ -1184,27 +1184,22 @@ std::error_code MachOObjectFile::getLibr
> if (Index >= Libraries.size())
> return object_error::parse_failed;
>
> - MachO::dylib_command D =
> - getStruct<MachO::dylib_command>(this, Libraries[Index]);
> - if (D.dylib.name >= D.cmdsize)
> - return object_error::parse_failed;
> -
> // If the cache of LibrariesShortNames is not built up do that first for
> // all the Libraries.
> if (LibrariesShortNames.size() == 0) {
> for (unsigned i = 0; i < Libraries.size(); i++) {
> MachO::dylib_command D =
> getStruct<MachO::dylib_command>(this, Libraries[i]);
> - if (D.dylib.name >= D.cmdsize) {
> - LibrariesShortNames.push_back(StringRef());
> - continue;
> - }
> + if (D.dylib.name >= D.cmdsize)
> + return object_error::parse_failed;
> const char *P = (const char *)(Libraries[i]) + D.dylib.name;
> StringRef Name = StringRef(P);
> + if (D.dylib.name+Name.size() >= D.cmdsize)
> + return object_error::parse_failed;
> StringRef Suffix;
> bool isFramework;
> StringRef shortName = guessLibraryShortName(Name, isFramework, Suffix);
> - if (shortName == StringRef())
> + if (shortName.empty())
> LibrariesShortNames.push_back(Name);
> else
> LibrariesShortNames.push_back(shortName);
>
> Modified: llvm/trunk/test/tools/llvm-objdump/macho-bind.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/macho-bind.test?rev=217930&r1=217929&r2=217930&view=diff
> ==============================================================================
> --- llvm/trunk/test/tools/llvm-objdump/macho-bind.test (original)
> +++ llvm/trunk/test/tools/llvm-objdump/macho-bind.test Tue Sep 16 19:25:22 2014
> @@ -6,6 +6,6 @@
> # CHECK:__DATA __data 0x00001028 pointer 0 flat-namespace _any
> # CHECK:__DATA __data 0x00001020 pointer 0 main-executable _fromApp
> # CHECK:__DATA __data 0x00001018 pointer 0 this-image _myfunc
> -# CHECK:__DATA __data 0x00001000 pointer 0 libfoo.dylib _foo
> -# CHECK:__DATA __data 0x00001008 pointer 0 libbar.dylib _bar
> -# CHECK:__DATA __data 0x00001010 pointer 0 libSystem.B.dylib _malloc
> +# CHECK:__DATA __data 0x00001000 pointer 0 libfoo _foo
> +# CHECK:__DATA __data 0x00001008 pointer 0 libbar _bar
> +# CHECK:__DATA __data 0x00001010 pointer 0 libSystem _malloc
>
> Modified: llvm/trunk/test/tools/llvm-objdump/macho-lazy-bind.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/macho-lazy-bind.test?rev=217930&r1=217929&r2=217930&view=diff
> ==============================================================================
> --- llvm/trunk/test/tools/llvm-objdump/macho-lazy-bind.test (original)
> +++ llvm/trunk/test/tools/llvm-objdump/macho-lazy-bind.test Tue Sep 16 19:25:22 2014
> @@ -3,6 +3,6 @@
> # RUN: && FileCheck %s < %t || cat %t
>
>
> -# CHECK: __DATA __la_symbol_ptr 0x100001010 libfoo.dylib _foo
> -# CHECK: __DATA __la_symbol_ptr 0x100001018 libbar.dylib _bar
> -# CHECK: __DATA __la_symbol_ptr 0x100001020 libSystem.B.dylib _malloc
> +# CHECK: __DATA __la_symbol_ptr 0x100001010 libfoo _foo
> +# CHECK: __DATA __la_symbol_ptr 0x100001018 libbar _bar
> +# CHECK: __DATA __la_symbol_ptr 0x100001020 libSystem _malloc
>
> Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=217930&r1=217929&r2=217930&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
> +++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Tue Sep 16 19:25:22 2014
> @@ -2482,7 +2482,7 @@ void llvm::printMachOBindTable(const obj
> Address,
> Entry.typeName().str().c_str(),
> Entry.addend(),
> - ordinalName(Obj, Entry.ordinal()))
> + ordinalName(Obj, Entry.ordinal()).str().c_str())
> << Entry.symbolName();
> if (Entry.flags() & MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT)
> outs() << " (weak_import)\n";
> @@ -2514,7 +2514,7 @@ void llvm::printMachOLazyBindTable(const
> SegmentName.str().c_str(),
> SectionName.str().c_str(),
> Address,
> - ordinalName(Obj, Entry.ordinal()))
> + ordinalName(Obj, Entry.ordinal()).str().c_str())
> << Entry.symbolName() << "\n";
> }
> }
>
>
> _______________________________________________
> 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