[LLVMbugs] [Bug 13013] New: ELF Type identification fails for MSB type ELF files

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 1 20:47:02 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13013

             Bug #: 13013
           Summary: ELF Type identification fails for MSB type ELF files
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Support Libraries
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: stefan at stefant.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Running llvm-objdump on a MSB encoded ELF file fails with an 'not a recognized
file format' error. This is due to the code in lib/Support/Path.cpp which does
not distinguish between MSB and LSB encoding.

Here is a small patch to fix this issue:

--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -60,8 +60,11 @@ sys::IdentifyFileType(const char *magic, unsigned length) {

     case '\177':
       if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') {
-        if (length >= 18 && magic[17] == 0)
-          switch (magic[16]) {
+        bool MSB = (magic[5] == 2);
+        unsigned high = MSB ? 16 : 17;
+        unsigned low  = MSB ? 17 : 16;
+        if (length >= 18 && magic[high] == 0)
+          switch (magic[low]) {
             default: break;
             case 1: return ELF_Relocatable_FileType;
             case 2: return ELF_Executable_FileType;

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list