[llvm] 1c991f9 - [Object/ELF] - Fix the offset type used in ELFFile<ELFT>::getEntry().

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 01:34:02 PST 2020


Author: Georgii Rymar
Date: 2020-03-04T12:33:10+03:00
New Revision: 1c991f907a43d7a56e82dd67a76514843841ed9a

URL: https://github.com/llvm/llvm-project/commit/1c991f907a43d7a56e82dd67a76514843841ed9a
DIFF: https://github.com/llvm/llvm-project/commit/1c991f907a43d7a56e82dd67a76514843841ed9a.diff

LOG: [Object/ELF] - Fix the offset type used in ELFFile<ELFT>::getEntry().

We use size_t for a file offset what is wrong, because size_t is 32-bit
value on 32-bit platforms.

I was reported that after my 0b511c23021
"[llvm-readobj] - Report warnings instead of errors for broken relocations."

The following error is observed on 32-bit Arch Linux:

[100%] Running all regression tests
FAIL: LLVM :: tools/llvm-readobj/ELF/relocation-errors.test (52954 of 54768)
******************** TEST 'LLVM :: tools/llvm-readobj/ELF/relocation-errors.test' FAILED ***

...
llvm-project/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test:9:14:error: LLVM-NEXT: expected string not found in input
# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in section 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
             ^
<stdin>:9:1: note: scanning from here
/llvm-project/build/bin/llvm-readobj: warning: 'llvm-project/build/test/tools/llvm-readobj/ELF/Output/relocation-errors.test.tmp64': unable to print relocation 1 in section 3: unable to access section [index 6] data at 0xe7e7e8b0: offset goes past the end of file

This patch should fix the issue.

Added: 
    

Modified: 
    llvm/include/llvm/Object/ELF.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index cc7abf9812fa..eb670c3e7560 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -573,7 +573,7 @@ Expected<const T *> ELFFile<ELFT>::getEntry(const Elf_Shdr *Section,
     return createError("section " + getSecIndexForError(this, Section) +
                        " has invalid sh_entsize: expected " + Twine(sizeof(T)) +
                        ", but got " + Twine(Section->sh_entsize));
-  size_t Pos = Section->sh_offset + Entry * sizeof(T);
+  uint64_t Pos = Section->sh_offset + Entry * sizeof(T);
   if (Pos + sizeof(T) > Buf.size())
     return createError("unable to access section " +
                        getSecIndexForError(this, Section) + " data at 0x" +


        


More information about the llvm-commits mailing list