-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: incomplete Clang detection #10453
Comments
I would expect the overhead from unconditionally running "$CC -v" or "$CC --version" would be minimal, so that seems like the easiest way to fix this. If we did want to avoid invoking the compiler unnecessarily though, we could add "-v" in gccDefines and check if the first line of stderr contains "clang version". (I'd need to double check that this string works for historical Clang versions too, but I would expect so.) gccDefines is the first place we run the compiler, and it doesn't currently need any clang-specific logic. |
@trombonehero Can you see if https://go-review.googlesource.com/#/c/9090/ helps with cc==clang on FreeBSD? After implementing that fix, I noticed that cmd/go and cmd/internal/ld also have similar strings.Contains(gcc, "clang") checks. Those should probably be fixed too, but at least they only control diagnostic output formatting and additional warnings, so hopefully CL 9090 is still an improvement. |
This issue will also manifest on OS X, where cc is clang. |
@davidchisnall If there's a specific problem you're aware of on OS X with cc==clang, please file a new issue. |
When cgo invokes Clang, it needs to set
-ferror-limit=0
in order to see a complete set of error messages (rather than a truncated list of 20). This works whenever cgo can tell that it's using Clang rather than GCC, but the detection logic is incomplete on modern versions of FreeBSD.The current check, located at line 765 of
cmd/cgo/gcc.go
, tests:but on FreeBSD,
/usr/bin/cc
is Clang. We could detect this with OS-specific checks, such as:but I'm not sure how to distinguish an older-but-still-supported version of FreeBSD (where
/usr/bin/cc
is GCC) with a simple string comparison. A more general approach would be to invokecc --version
to see what comes back:This is a more heavyweight approach, but given that we're going to execute the C compiler anyway, maybe the performance cost is worth the increase in robustness? The extra exec could be guarded with some
runtime.GOOS == "freebsd"
logic, but as Clang gets adopted in more and more places, it might make sense to just Do The Right Thing rather than rely on heuristics.The text was updated successfully, but these errors were encountered: