Added support for $(LD) for genrule() and ld_executable for Skylark

I added support for exposing the GNU linker (ld) for genrule() and Skylark.

For reference: https://stackoverflow.com/questions/45560314/building-kernel-module-with-bazel

Closes #3557.

PiperOrigin-RevId: 165600633
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index 5fb4589..56ed29d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -1288,9 +1288,15 @@
   }
 
   /**
-   * Returns the execution path to the linker binary to use for this build.
-   * Relative paths are relative to the execution root.
+   * Returns the execution path to the linker binary to use for this build. Relative paths are
+   * relative to the execution root.
    */
+  @SkylarkCallable(name = "ld_executable", structField = true, doc = "Path to the linker binary.")
+  public String getLdExecutableForSkylark() {
+    PathFragment ldExecutable = getLdExecutable();
+    return ldExecutable != null ? ldExecutable.getPathString() : "";
+  }
+
   public PathFragment getLdExecutable() {
     return ldExecutable;
   }
@@ -1821,6 +1827,7 @@
     // Make variables provided by crosstool/gcc compiler suite.
     globalMakeEnvBuilder.put("AR", getArExecutable().getPathString());
     globalMakeEnvBuilder.put("NM", getNmExecutable().getPathString());
+    globalMakeEnvBuilder.put("LD", getLdExecutable().getPathString());
     PathFragment objcopyTool = getObjCopyExecutable();
     if (objcopyTool != null) {
       // objcopy is optional in Crosstool