Skip to content
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

macOS test failure with LLVM >= 10 #479

Closed
elliottslaughter opened this issue Jan 22, 2021 · 5 comments · Fixed by #481
Closed

macOS test failure with LLVM >= 10 #479

elliottslaughter opened this issue Jan 22, 2021 · 5 comments · Fixed by #481

Comments

@elliottslaughter
Copy link
Member

Even after you fix #478 , you will still get test failures on macOS with LLVM >= 10. Errors seem to look like:

/Applications/Xcode_12.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/usr/include/libkern/_OSByteOrder.h:97:1: error: unknown type name '__DARWIN_OS_INLINE'

I was hoping to revert to the macOS 10.15 SDK but it appears not to be installed on Github Actions.

Example failure: https://github.com/terralang/terra/runs/1751733849

Archive of the build log:
build_log.txt

elliottslaughter added a commit that referenced this issue Jan 23, 2021
As of this merge there are the following known issues with the LLVM 10 and 11 support:

  * #476 cannot include immintrin.h
  * #477 test failures in LLVM 11 when dynamically linked
  * #479 tests fail on macOS with LLVM >= 10
@elliottslaughter
Copy link
Member Author

LLVM 10 got rid of the default definition of __GNUC__. I'm not quite sure why LLVM 10 isn't able to work with Apple's headers without this, but at any rate, the following reproducer demonstrates that putting this back solves the issue:

local C = terralib.includecstring [[
#ifndef __GNUC__
#define __GNUC__ 4
#endif
#include <stdlib.h>
]]

If you comment out the #define then you hit the error reported the original issue (reproduced below for clarity):

In file included from <buffer>:2:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:66:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/wait.h:186:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/machine/endian.h:35:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/i386/endian.h:99:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_endian.h:130:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libkern/_OSByteOrder.h:97:1: error: unknown type name '__DARWIN_OS_INLINE'
__DARWIN_OS_INLINE
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libkern/_OSByteOrder.h:98:9: error: expected ';' after top level declarator
uint16_t
        ^
        ;

@elliottslaughter
Copy link
Member Author

elliottslaughter commented Feb 20, 2021

The release notes for Clang 10 mention this:

The -fgnuc-version= flag now controls the value of __GNUC__ and related macros. This flag does not enable or disable any GCC extensions implemented in Clang. Setting the version to zero causes Clang to leave __GNUC__ and other GNU-namespaced macros, such as __GXX_WEAK__, undefined.

https://releases.llvm.org/10.0.0/tools/clang/docs/ReleaseNotes.html

I'm still trying to figure out what the default value of this flag is.

Edit: there's also some rationale in https://reviews.llvm.org/D68055

@elliottslaughter
Copy link
Member Author

elliottslaughter commented Feb 22, 2021

I've been playing some more with the Clang frontend. I'm a bit confused because -fgnuc-version doesn't seem to be necessary in practice, but meanwhile I do see that SDKROOT does seem to matter now in Clang 11.

Contents of test_gnuc.c:

#include <stdio.h>
int main(int argc, char *argv[]) {
#ifdef __GNUC__
  int gnuc = __GNUC__;
  printf("yep %d\n", gnuc);
#else 
  printf("nope.\n");
#endif
  return 0;
}

Apple Clang:

$ ./test_gnuc 
yep 4
$ which clang
/usr/bin/clang
$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

LLVM Clang 9 from binary:

$ ./llvm/llvm-9/clang+llvm-9.0.1-x86_64-apple-darwin/bin/clang test_gnuc.c -o test_gnuc
test_gnuc.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
$ ./llvm/llvm-9/clang+llvm-9.0.1-x86_64-apple-darwin/bin/clang test_gnuc.c -o test_gnuc -I "$(xcrun --sdk macosx --show-sdk-path)/usr/include"
...
(lots of warnings, but compiles)
$ ./test_gnuc 
yep 4

LLVM Clang 11 from binary:

$ ./llvm/llvm-11/clang+llvm-11.0.0-x86_64-apple-darwin/bin/clang test_gnuc.c -o test_gnuc
test_gnuc.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
$ ./llvm/llvm-11/clang+llvm-11.0.0-x86_64-apple-darwin/bin/clang test_gnuc.c -o test_gnuc -I "$(xcrun --sdk macosx --show-sdk-path)/usr/include"
...
(lots of warnings, then one error):
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:220:5: error: 'TARGET_OS_IPHONE' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
#if TARGET_OS_IPHONE
    ^
$ SDKROOT="$(xcrun --sdk macosx --show-sdk-path)" ./llvm/llvm-11/clang+llvm-11.0.0-x86_64-apple-darwin/bin/clang test_gnuc.c -o test_gnuc
$ ./test_gnuc 
yep 4

This last bit is interesting... I wasn't expecting that part. Maybe I need to fiddle with the SDKROOT value for Terra. That didn't used to matter, so I'm a bit surprised.

@elliottslaughter
Copy link
Member Author

Ok, so I found the place where SDKROOT is parsed in Clang:

https://github.com/llvm/llvm-project/blob/f77c948d56b09b839262e258af5c6ad701e5b168/clang/lib/Driver/ToolChains/Darwin.cpp#L1786

It does look like it's being turned directly into an -isysroot flag. So there doesn't seem to be any processing of the SDKROOT aside from that flag itself.

Still trying to figure out how Clang the frontend has -fgnuc-version set by default while our internally constructed Clang fails to do so.

@elliottslaughter
Copy link
Member Author

The default value of -fgnuc-version=4.2.1 seems to be coming from here:

https://github.com/llvm/llvm-project/blob/f77c948d56b09b839262e258af5c6ad701e5b168/clang/lib/Driver/ToolChains/Clang.cpp#L5750-L5753

I guess as long as we track that we should be fine, or else we could dig more into why we're not able to take advantage of this code path through the CompilerInvokation in tcwrapper.cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant