35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38
39 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
41 import org.graalvm.compiler.options.OptionValues;
42 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
43
44 import jdk.tools.jaotc.binformat.Symbol.Binding;
45 import jdk.tools.jaotc.binformat.Symbol.Kind;
46 import jdk.tools.jaotc.binformat.elf.JELFRelocObject;
47 import jdk.tools.jaotc.binformat.macho.JMachORelocObject;
48 import jdk.tools.jaotc.binformat.pecoff.JPECoffRelocObject;
49
50 /**
51 * A format-agnostic container class that holds various components of a binary.
52 *
53 * <p>
54 * This class holds information necessary to create platform-specific binary containers such as
55 * ELFContainer for Linux and Solaris operating systems or MachOContainer for Mac OS or PEContainer
56 * for MS Windows operating systems.
57 *
58 * <p>
59 * Method APIs provided by this class are used to construct and populate platform-independent
60 * contents of a binary as the first step to create a binary representation of code generated by a
61 * compiler backend such as Graal.
62 *
63 * <p>
64 * Methods to record and access code section contents, symbols and relocations are provided.
65 */
66 public final class BinaryContainer implements SymbolTable {
67 private final OptionValues graalOptions;
68
69 private final int codeSegmentSize;
70
71 private final int codeEntryAlignment;
72
73 private final boolean threadLocalHandshakes;
74
75 /**
535 String s = "got." + name;
536 Symbol gotSymbol = extLinkageGOTContainer.createGotSymbol(s);
537 extLinkageGOTContainer.createSymbol(gotSymbol.getOffset(), Kind.OBJECT, Binding.GLOBAL, 8, name);
538 }
539
540 /**
541 * Create a platform-specific binary file representing the content of the
542 * {@code BinaryContainer} object.
543 *
544 * This method is called after creating and performing any necessary changes to the contents of
545 * code stream, symbol tables and relocation tables is completely finalized
546 *
547 * @param outputFileName name of output file
548 *
549 * @throws IOException in case of file creation failure
550 */
551 public void createBinary(String outputFileName) throws IOException {
552 String osName = System.getProperty("os.name");
553 switch (osName) {
554 case "Linux":
555 case "SunOS":
556 JELFRelocObject elfobj = JELFRelocObject.newInstance(this, outputFileName);
557 elfobj.createELFRelocObject(relocationTable, symbolTable.values());
558 break;
559 case "Mac OS X":
560 JMachORelocObject machobj = new JMachORelocObject(this, outputFileName);
561 machobj.createMachORelocObject(relocationTable, symbolTable.values());
562 break;
563 default:
564 if (osName.startsWith("Windows")) {
565 JPECoffRelocObject pecoffobj = new JPECoffRelocObject(this, outputFileName);
566 pecoffobj.createPECoffRelocObject(relocationTable, symbolTable.values());
567 break;
568 } else {
569 throw new InternalError("Unsupported platform: " + osName);
570 }
571 }
572 }
573
574 /**
575 * Add symbol to the symbol table. If the existing symbol is undefined and the specified symbol
|
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38
39 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
41 import org.graalvm.compiler.options.OptionValues;
42 import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
43
44 import jdk.tools.jaotc.binformat.Symbol.Binding;
45 import jdk.tools.jaotc.binformat.Symbol.Kind;
46 import jdk.tools.jaotc.binformat.elf.JELFRelocObject;
47 import jdk.tools.jaotc.binformat.macho.JMachORelocObject;
48 import jdk.tools.jaotc.binformat.pecoff.JPECoffRelocObject;
49
50 /**
51 * A format-agnostic container class that holds various components of a binary.
52 *
53 * <p>
54 * This class holds information necessary to create platform-specific binary containers such as
55 * ELFContainer for Linux or MachOContainer for Mac OS or PEContainer
56 * for MS Windows operating systems.
57 *
58 * <p>
59 * Method APIs provided by this class are used to construct and populate platform-independent
60 * contents of a binary as the first step to create a binary representation of code generated by a
61 * compiler backend such as Graal.
62 *
63 * <p>
64 * Methods to record and access code section contents, symbols and relocations are provided.
65 */
66 public final class BinaryContainer implements SymbolTable {
67 private final OptionValues graalOptions;
68
69 private final int codeSegmentSize;
70
71 private final int codeEntryAlignment;
72
73 private final boolean threadLocalHandshakes;
74
75 /**
535 String s = "got." + name;
536 Symbol gotSymbol = extLinkageGOTContainer.createGotSymbol(s);
537 extLinkageGOTContainer.createSymbol(gotSymbol.getOffset(), Kind.OBJECT, Binding.GLOBAL, 8, name);
538 }
539
540 /**
541 * Create a platform-specific binary file representing the content of the
542 * {@code BinaryContainer} object.
543 *
544 * This method is called after creating and performing any necessary changes to the contents of
545 * code stream, symbol tables and relocation tables is completely finalized
546 *
547 * @param outputFileName name of output file
548 *
549 * @throws IOException in case of file creation failure
550 */
551 public void createBinary(String outputFileName) throws IOException {
552 String osName = System.getProperty("os.name");
553 switch (osName) {
554 case "Linux":
555 JELFRelocObject elfobj = JELFRelocObject.newInstance(this, outputFileName);
556 elfobj.createELFRelocObject(relocationTable, symbolTable.values());
557 break;
558 case "Mac OS X":
559 JMachORelocObject machobj = new JMachORelocObject(this, outputFileName);
560 machobj.createMachORelocObject(relocationTable, symbolTable.values());
561 break;
562 default:
563 if (osName.startsWith("Windows")) {
564 JPECoffRelocObject pecoffobj = new JPECoffRelocObject(this, outputFileName);
565 pecoffobj.createPECoffRelocObject(relocationTable, symbolTable.values());
566 break;
567 } else {
568 throw new InternalError("Unsupported platform: " + osName);
569 }
570 }
571 }
572
573 /**
574 * Add symbol to the symbol table. If the existing symbol is undefined and the specified symbol
|