Search in sources :

Example 1 with ElfDynamicSection

use of com.oracle.truffle.llvm.parser.elf.ElfDynamicSection in project sulong by graalvm.

the class LLVMScanner method parse.

public static ModelModule parse(Source source, ByteBuffer bytes) {
    final ModelModule model = new ModelModule();
    ByteBuffer b = bytes.duplicate();
    b.order(ByteOrder.LITTLE_ENDIAN);
    ByteBuffer bitcode;
    long magicWord = Integer.toUnsignedLong(b.getInt());
    if (Long.compareUnsigned(magicWord, BC_MAGIC_WORD) == 0) {
        bitcode = b;
    } else if (magicWord == WRAPPER_MAGIC_WORD) {
        // Version
        b.getInt();
        // Offset32
        long offset = b.getInt();
        // Size32
        long size = b.getInt();
        b.position((int) offset);
        b.limit((int) (offset + size));
        bitcode = b.slice();
    } else if (magicWord == ELF_MAGIC_WORD) {
        ElfFile elfFile = ElfFile.create(b);
        Entry llvmbc = elfFile.getSectionHeaderTable().getEntry(".llvmbc");
        if (llvmbc == null) {
            throw new RuntimeException("ELF File does not contain an .llvmbc section.");
        }
        ElfDynamicSection dynamicSection = elfFile.getDynamicSection();
        if (dynamicSection != null) {
            List<String> libraries = dynamicSection.getDTNeeded();
            List<String> paths = dynamicSection.getDTRPath();
            model.addLibraries(libraries);
            model.addLibraryPaths(paths);
        }
        long offset = llvmbc.getOffset();
        long size = llvmbc.getSize();
        b.position((int) offset);
        b.limit((int) (offset + size));
        bitcode = b.slice();
    } else {
        throw new RuntimeException("Not a valid input file!");
    }
    parseBitcodeBlock(source, bitcode, model);
    return model;
}
Also used : ModelModule(com.oracle.truffle.llvm.parser.model.ModelModule) Entry(com.oracle.truffle.llvm.parser.elf.ElfSectionHeaderTable.Entry) ElfFile(com.oracle.truffle.llvm.parser.elf.ElfFile) ElfDynamicSection(com.oracle.truffle.llvm.parser.elf.ElfDynamicSection) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ElfDynamicSection (com.oracle.truffle.llvm.parser.elf.ElfDynamicSection)1 ElfFile (com.oracle.truffle.llvm.parser.elf.ElfFile)1 Entry (com.oracle.truffle.llvm.parser.elf.ElfSectionHeaderTable.Entry)1 ModelModule (com.oracle.truffle.llvm.parser.model.ModelModule)1 ByteBuffer (java.nio.ByteBuffer)1