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

Compile fails with clang 16 #171

Open
jmontleon opened this issue Aug 4, 2023 · 7 comments
Open

Compile fails with clang 16 #171

jmontleon opened this issue Aug 4, 2023 · 7 comments
Labels

Comments

@jmontleon
Copy link

I am seeing the following trying to build on Fedora 38 ppc64;e and s390x. I do not have this problem on x86_64 or aarch64.

I believe it is coming from the change in behavior to Wimplicit-function-declaration.
https://www.redhat.com/en/blog/new-warnings-and-errors-clang-16

[ 11%] Building C object confu-deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/api.c.o
cd /builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/redhat-linux-build/confu-deps/cpuinfo && /usr/bin/clang -DCPUINFO_LOG_LEVEL=2 -I/builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/third_party/cpuinfo/src -I/builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/third_party/cpuinfo/include -I/builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/third_party/cpuinfo/deps/clog/include -O2 -flto=thin -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong   -m64 -march=z13 -mtune=z14 -fasynchronous-unwind-tables -fstack-clash-protection -DNDEBUG -std=c99 -fPIC -MD -MT confu-deps/cpuinfo/CMakeFiles/cpuinfo.dir/src/api.c.o -MF CMakeFiles/cpuinfo.dir/src/api.c.o.d -o CMakeFiles/cpuinfo.dir/src/api.c.o -c /builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/third_party/cpuinfo/src/api.c
/builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/third_party/cpuinfo/src/api.c:319:23: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                if CPUINFO_UNLIKELY(syscall(__NR_getcpu, &cpu, NULL, NULL) != 0) {
                                    ^
/builddir/build/BUILD/pytorch-v2.0.1.gitf81f9093/third_party/cpuinfo/src/api.c:338:23: error: call to undeclared function 'syscall'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                if CPUINFO_UNLIKELY(syscall(__NR_getcpu, &cpu, NULL, NULL) != 0) {
                                    ^
2 errors generated.

A full build log can be found here:
https://download.copr.fedorainfracloud.org/results/jmontleon/pytorch/fedora-38-s390x/06239794-pytorch/builder-live.log.gz

@Maratyszcza
Copy link
Contributor

Why is syscall undeclared on Red Hat?

@Maratyszcza
Copy link
Contributor

Also, cpuinfo doesn't support ppc64 and s390x

@jmontleon
Copy link
Author

Is there a way to build pytorch without it?

@Maratyszcza
Copy link
Contributor

I don't know, you should ask PyTorch devs

@jmontleon
Copy link
Author

Did I file this in the wrong place? cpuinfo is included in the third_party deps of pytorch and this repo is within the pytorch org. I had assumed you all talk occasionally?

The only option I see available in pytorch is -DUSE_SYSTEM_PYTORCH to use a version provided by the system rather than bundled in the third party repo.

And the cmake warning when building on unsupported architectures:

CMake Warning at third_party/cpuinfo/CMakeLists.txt:81 (MESSAGE):
  Target processor architecture "s390x" is not supported in cpuinfo.  cpuinfo
  will compile, but cpuinfo_initialize() will always fail.

@jmontleon
Copy link
Author

To you question, "Why is syscall undeclared on Red Hat?", I don't think this is distribution specific. As mentioned I don't have this problem on amd64 or aarch64 using the same version of clang. Rather it seems a difference in architectures.

One of the explanations I see is:
"#define _GNU_SOURCE before including unistd.h or any other header as syscall(2) is not POSIX."
https://stackoverflow.com/questions/42469583/problems-calling-syscall-function-in-c

It's also present in the example within the man page
https://man7.org/linux/man-pages/man2/syscall.2.html#EXAMPLES

Putting this define at the top of the file does seem to resolve the build failure. I don't have a strong enough understanding at present to say why it's necessary for some architectures and not others.

@bhbruce
Copy link

bhbruce commented Nov 28, 2023

@Maratyszcza syscall is not a standard function in posix.

It is implemented in glibc. It looks like the Clang has strict constraints (compared to GCC) ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration].

The man page https://linux.die.net/man/2/syscall also show that we should add #define _GNU_SOURCE before including headers.

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

No branches or pull requests

4 participants