Search in sources :

Example 1 with LinkerInvocation

use of com.oracle.svm.core.LinkerInvocation in project graal by oracle.

the class ExecutableViaCCBootImage method getLinkerInvocation.

@Override
LinkerInvocation getLinkerInvocation(Path outputDirectory, Path tempDirectory, String imageName) {
    String mainSymbolNameStem = NativeBootImage.globalSymbolNameForMethod(mainEntryPoint);
    // HACK: guess main symbol name using hacked-up knowledge of object file format
    String mainSymbolAlias = (ObjectFile.getNativeFormat() == ObjectFile.Format.MACH_O) ? "_main" : "main";
    String mainSymbolName = (ObjectFile.getNativeFormat() == ObjectFile.Format.MACH_O) ? "_" + mainSymbolNameStem : mainSymbolNameStem;
    LinkerInvocation inv = super.getLinkerInvocation(outputDirectory, tempDirectory, imageName);
    inv.addSymbolAlias(mainSymbolAlias, mainSymbolName);
    return inv;
}
Also used : LinkerInvocation(com.oracle.svm.core.LinkerInvocation)

Example 2 with LinkerInvocation

use of com.oracle.svm.core.LinkerInvocation in project graal by oracle.

the class NativeBootImageViaCC method write.

@Override
@SuppressWarnings("try")
public Path write(DebugContext debug, Path outputDirectory, Path tempDirectory, String imageName, BeforeImageWriteAccessImpl config) {
    String cmdstr = "";
    String outputstr = "";
    try (Indent indent = debug.logAndIndent("Writing native image")) {
        // 1. write the relocatable file
        write(tempDirectory.resolve(imageName + ObjectFile.getFilenameSuffix()));
        // 2. run a command to make an executable of it
        int status;
        try {
            /*
                 * To support automated stub generation, we first search for a libsvm.a in the
                 * images directory. FIXME: make this a per-image directory, to avoid clobbering on
                 * multiple runs. It actually doesn't matter, because it's a .a file which will get
                 * absorbed into the executable, but avoiding clobbering will help debugging.
                 */
            LinkerInvocation inv = getLinkerInvocation(outputDirectory, tempDirectory, imageName);
            for (Function<LinkerInvocation, LinkerInvocation> fn : config.getLinkerInvocationTransformers()) {
                inv = fn.apply(inv);
            }
            List<String> cmd = inv.getCommand();
            StringBuilder sb = new StringBuilder("Running command:");
            for (String s : cmd) {
                sb.append(' ');
                sb.append(s);
            }
            cmdstr = sb.toString();
            try (DebugContext.Scope s = debug.scope("InvokeCC")) {
                debug.log("%s", sb);
                if (NativeImageOptions.MachODebugInfoTesting.getValue()) {
                    System.out.printf("Testing Mach-O debuginfo generation - SKIP %s%n", cmdstr);
                } else {
                    Process p = new ProcessBuilder().command(cmd).redirectErrorStream(true).start();
                    ByteArrayOutputStream output = new ByteArrayOutputStream();
                    FileUtils.drainInputStream(p.getInputStream(), output);
                    status = p.waitFor();
                    outputstr = output.toString();
                    debug.log("%s", output);
                    if (status != 0) {
                        throw new RuntimeException("returned " + status);
                    }
                }
            }
            return inv.getOutputFile();
        } catch (Exception ex) {
            throw new RuntimeException("host C compiler or linker does not seem to work: " + ex.toString() + "\n\n" + cmdstr + "\n\n" + outputstr);
        }
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) LinkerInvocation(com.oracle.svm.core.LinkerInvocation) DebugContext(org.graalvm.compiler.debug.DebugContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

LinkerInvocation (com.oracle.svm.core.LinkerInvocation)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 Indent (org.graalvm.compiler.debug.Indent)1