diff options
-rw-r--r-- | compiler_wrapper/clang_flags.go | 12 | ||||
-rw-r--r-- | compiler_wrapper/clang_flags_test.go | 10 |
2 files changed, 17 insertions, 5 deletions
diff --git a/compiler_wrapper/clang_flags.go b/compiler_wrapper/clang_flags.go index b4dbfb88..1d540909 100644 --- a/compiler_wrapper/clang_flags.go +++ b/compiler_wrapper/clang_flags.go @@ -6,6 +6,7 @@ package main import ( "bytes" + "os" "path/filepath" "strings" ) @@ -181,7 +182,16 @@ func getLinkerPath(env env, linkerCmd string, rootPath string) string { // i686-pc-linux-gnu-ld, so we need to add this to help clang find the right // linker. for _, path := range strings.Split(env.getenv("PATH"), ":") { - if linkerPath, err := filepath.EvalSymlinks(filepath.Join(path, linkerCmd)); err == nil { + linkerPath := filepath.Join(path, linkerCmd) + // FIXME: We are not using filepath.EvalSymlinks to only unpack + // one layer of symlinks to match the old wrapper. Investigate + // why this is important or simplify to filepath.EvalSymlinks. + if fi, err := os.Lstat(linkerPath); err == nil { + if fi.Mode()&os.ModeSymlink != 0 { + if linkPath, err := os.Readlink(linkerPath); err == nil { + linkerPath = linkPath + } + } return filepath.Dir(linkerPath) } } diff --git a/compiler_wrapper/clang_flags_test.go b/compiler_wrapper/clang_flags_test.go index 1d56b1f0..6dda35f1 100644 --- a/compiler_wrapper/clang_flags_test.go +++ b/compiler_wrapper/clang_flags_test.go @@ -226,13 +226,15 @@ func TestClangLinkerPathEvaluatesSymlinksForBinariesOnPath(t *testing.T) { withTestContext(t, func(ctx *testContext) { realLinkerPath := filepath.Join(ctx.tempDir, "a/original/path/somelinker") ctx.writeFile(realLinkerPath, "") - linkedLinkerPath := filepath.Join(ctx.tempDir, "a/linked/path/x86_64-cros-linux-gnu-ld") - ctx.symlink(realLinkerPath, linkedLinkerPath) + firstLinkLinkerPath := filepath.Join(ctx.tempDir, "a/first/somelinker") + ctx.symlink(realLinkerPath, firstLinkLinkerPath) + secondLinkLinkerPath := filepath.Join(ctx.tempDir, "a/second/x86_64-cros-linux-gnu-ld") + ctx.symlink(firstLinkLinkerPath, secondLinkLinkerPath) - ctx.env = []string{"PATH=nonExistantPath:" + filepath.Dir(linkedLinkerPath)} + ctx.env = []string{"PATH=nonExistantPath:" + filepath.Dir(secondLinkLinkerPath)} cmd := ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand("./x86_64-cros-linux-gnu-clang", mainCc))) - if err := verifyArgOrder(cmd, "-Ba/original/path"); err != nil { + if err := verifyArgOrder(cmd, "-Ba/first"); err != nil { t.Error(err) } }) |