Object/COFF: Fix off-by-one error for object having lots of relocations
authorRui Ueyama <ruiu@google.com>
Wed, 26 Nov 2014 22:17:25 +0000 (22:17 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 26 Nov 2014 22:17:25 +0000 (22:17 +0000)
llvm-objdump printed out an error message for this off-by-one error,
but because it always exits with 0 whether or not it found an error,
the test (llvm-objdump/coff-many-relocs.test) succeeded.
I made llvm-objdump exit with EXIT_FAILURE when an error is found.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222852 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/COFFObjectFile.cpp
tools/llvm-objdump/llvm-objdump.cpp

index 04cd61698c600ce500d7e08488cfad5bac31c305..92f920da1fad9efe9873acd6d583304994f02d06 100644 (file)
@@ -414,7 +414,8 @@ static uint32_t getNumberOfRelocations(const coff_section *Sec,
     if (getObject(FirstReloc, M, reinterpret_cast<const coff_relocation*>(
         base + Sec->PointerToRelocations)))
       return 0;
-    return FirstReloc->VirtualAddress;
+    // -1 to exclude this first relocation entry.
+    return FirstReloc->VirtualAddress - 1;
   }
   return Sec->NumberOfRelocations;
 }
index 8903bff8f97fdb00da154724d8bfb9059e144730..c62922e4c5e83285be5f9ca6e524185941bcf907 100644 (file)
@@ -149,6 +149,7 @@ PrivateHeadersShort("p", cl::desc("Alias for --private-headers"),
                     cl::aliasopt(PrivateHeaders));
 
 static StringRef ToolName;
+static int ReturnValue = EXIT_SUCCESS;
 
 bool llvm::error(std::error_code EC) {
   if (!EC)
@@ -156,6 +157,7 @@ bool llvm::error(std::error_code EC) {
 
   outs() << ToolName << ": error reading file: " << EC.message() << ".\n";
   outs().flush();
+  ReturnValue = EXIT_FAILURE;
   return true;
 }
 
@@ -895,5 +897,5 @@ int main(int argc, char **argv) {
   std::for_each(InputFilenames.begin(), InputFilenames.end(),
                 DumpInput);
 
-  return 0;
+  return ReturnValue;
 }