Exemple #1
0
def FileType(filename):
    # Auto-detect bitcode files, since we can't rely on extensions
    ext = filename.split('.')[-1]

    # TODO(pdox): We open and read the the first few bytes of each file
    #             up to 4 times, when we only need to do it once. The
    #             OS cache prevents us from hitting the disk, but this
    #             is still slower than it needs to be.
    if IsArchive(filename):
        return artools.GetArchiveType(filename)

    if elftools.IsELF(filename):
        return GetELFType(filename)

    # If this is LLVM bitcode, we don't have a good way of determining if it
    # is an object file or a non-finalized program, so just say 'po' for now.
    if IsLLVMBitcode(filename):
        return 'po'

    if IsPNaClBitcode(filename):
        return 'pexe'

    if ldtools.IsLinkerScript(filename):
        return 'ldscript'

    # Use the file extension if it is recognized
    if ext in ExtensionMap:
        return ExtensionMap[ext]

    driver_log.Log.Fatal('%s: Unrecognized file type', filename)
Exemple #2
0
def GetELFType(filename):
  """ ELF type as determined by ELF metadata """
  assert(elftools.IsELF(filename))
  elfheader = elftools.GetELFHeader(filename)
  elf_type_map = {
    'EXEC': 'nexe',
    'REL' : 'o',
    'DYN' : 'so'
  }
  return elf_type_map[elfheader.type]
Exemple #3
0
def IsELF(filename):
    return elftools.IsELF(filename)