8174863: AOT: jaotc should provide an option to specify the path to the platform linker
authorbobv
Wed, 22 Feb 2017 12:33:36 -0500
changeset 46275 d27ab535d88c
parent 46268 cb4459e22f7a
child 46276 b223ed3405bf
8174863: AOT: jaotc should provide an option to specify the path to the platform linker Reviewed-by: kvn
hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java
--- a/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Tue Feb 14 11:26:27 2017 -0500
+++ b/hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Main.java	Wed Feb 22 12:33:36 2017 -0500
@@ -203,6 +203,11 @@
         void process(Main task, String opt, String arg) {
             task.options.version = true;
         }
+    }, new Option("  --linker-path              Full path to linker executable", true, "--linker-path") {
+        @Override
+        void process(Main task, String opt, String arg) {
+            task.options.linkerpath = arg;
+        }
     }, new Option("  -J<flag>                   Pass <flag> directly to the runtime system", false, "-J") {
         @Override
         void process(Main task, String opt, String arg) {
@@ -216,6 +221,7 @@
         public String outputName = "unnamed.so";
         public String methodList;
         public String classpath = ".";
+        public String linkerpath = null;
 
         /**
          * We don't see scaling beyond 16 threads.
@@ -460,7 +466,8 @@
             // tests are fixed.
             String libraryFileName = name;
 
-            String ldCmd;
+            String linkerCmd;
+            String linkerPath;
             String osName = System.getProperty("os.name");
 
             if (name.endsWith(".so")) {
@@ -477,27 +484,31 @@
                 case "Linux":
                     // libraryFileName = options.outputName + ".so";
                     objectFileName = objectFileName + ".o";
-                    ldCmd = "ld -shared -z noexecstack -o " + libraryFileName + " " + objectFileName;
+                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerCmd = linkerPath + " -shared -z noexecstack -o " + libraryFileName + " " + objectFileName;
                     break;
                 case "SunOS":
                     // libraryFileName = options.outputName + ".so";
                     objectFileName = objectFileName + ".o";
-                    ldCmd = "ld -shared -o " + libraryFileName + " " + objectFileName;
+                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerCmd = linkerPath + " -shared -o " + libraryFileName + " " + objectFileName;
                     break;
                 case "Mac OS X":
                     // libraryFileName = options.outputName + ".dylib";
                     objectFileName = objectFileName + ".o";
-                    ldCmd = "ld -dylib -o " + libraryFileName + " " + objectFileName;
+                    linkerPath = (options.linkerpath != null) ?  options.linkerpath : "ld";
+                    linkerCmd = linkerPath + " -dylib -o " + libraryFileName + " " + objectFileName;
                     break;
                 default:
                     if (osName.startsWith("Windows")) {
                         // libraryFileName = options.outputName + ".dll";
                         objectFileName = objectFileName + ".obj";
-                        String linkpath = getWindowsLinkPath();
-                        if (linkpath == null) {
+                        linkerPath = (options.linkerpath != null) ?
+                            options.linkerpath : getWindowsLinkPath();
+                        if (linkerPath == null) {
                             throw new InternalError("Can't locate Microsoft Visual Studio amd64 link.exe");
                         }
-                        ldCmd = linkpath + " /DLL /OPT:NOREF /NOLOGO /NOENTRY" + " /OUT:" + libraryFileName + " " + objectFileName;
+                        linkerCmd = linkerPath + " /DLL /OPT:NOREF /NOLOGO /NOENTRY" + " /OUT:" + libraryFileName + " " + objectFileName;
                         break;
                     }
                     else
@@ -516,7 +527,7 @@
             }
 
             try (Timer t = new Timer(this, "Creating shared library: " + libraryFileName)) {
-                Process p = Runtime.getRuntime().exec(ldCmd);
+                Process p = Runtime.getRuntime().exec(linkerCmd);
                 final int exitCode = p.waitFor();
                 if (exitCode != 0) {
                     InputStream stderr = p.getErrorStream();