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

Failed to build llvm libc 14.0.5 on Oracle Ampere A1 Arm with GCC 8.5.0 #60473

Closed
Tomcruseal opened this issue Feb 2, 2023 · 20 comments
Closed

Comments

@Tomcruseal
Copy link

Tomcruseal commented Feb 2, 2023

Hi there,

I was trying to build LLVM 14.0.5 and all the subprojects from source on Oracle Ampere A1 Arm. The OS is Oracle Linux arm-server-beta-2022 5.4.17-2102.204.4.4.el8uek.aarch64 with 4 cores 24GB ram.

My cmake configure was

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/home/opc/library -DCMAKE_BUILD_TYPE=RELEASE -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;cross-project-tests;libc;libclc;lld;lldb;openmp;polly;pstl" DLLVM_ENABLE_RUNTIMES="compiler-rt;libc;libcxx;libcxxabi;libunwind" ../llvm

CMake went well, but it crashed at Make. The error information is shown below,

Consolidate compiler generated dependencies of target libc.src.fenv.fegetexcept
[ 42%] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexcept.dir/fegetexcept.cpp.o
In file included from /home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/FEnvUtils.h:17,
                 from /home/opc/Downloads/llvm-project-14.0.5.src/libc/src/fenv/fegetexcept.cpp:10:
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h: In static member function 'static uint32_t __llvm_libc::fputil::FEnv::getControlWord()':
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h:69:45: error: '__arm_rsr' was not declared in this scope
   static uint32_t getControlWord() { return __arm_rsr("fpcr"); }
                                             ^~~~~~~~~
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h: In static member function 'static void __llvm_libc::fputil::FEnv::writeControlWord(uint32_t)':
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h:71:49: error: '__arm_wsr' was not declared in this scope
   static void writeControlWord(uint32_t fpcr) { __arm_wsr("fpcr", fpcr); }
                                                 ^~~~~~~~~
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h: In static member function 'static uint32_t __llvm_libc::fputil::FEnv::getStatusWord()':
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h:73:44: error: '__arm_rsr' was not declared in this scope
   static uint32_t getStatusWord() { return __arm_rsr("fpsr"); }
                                            ^~~~~~~~~
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h: In static member function 'static void __llvm_libc::fputil::FEnv::writeStatusWord(uint32_t)':
/home/opc/Downloads/llvm-project-14.0.5.src/libc/src/__support/FPUtil/aarch64/FEnvImpl.h:75:48: error: '__arm_wsr' was not declared in this scope
   static void writeStatusWord(uint32_t fpsr) { __arm_wsr("fpsr", fpsr); }
                                                ^~~~~~~~~
make[2]: *** [projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexcept.dir/build.make:76: projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexcept.dir/fegetexcept.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:42575: projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexcept.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Could you please give some suggestions? Many thanks

@DimitryAndric
Copy link
Collaborator

What is your host compiler, and which version is it? E.g. what does the CMake stage print when it detects CMAKE_C_COMPILER and CMAKE_CXX_COMPILER?

@llvmbot
Copy link
Member

llvmbot commented Feb 2, 2023

@llvm/issue-subscribers-libc

@llvmbot
Copy link
Member

llvmbot commented Feb 2, 2023

@llvm/issue-subscribers-backend-arm

@Tomcruseal
Copy link
Author

Tomcruseal commented Feb 2, 2023

Hi, the host compiler GNU C++, of version 8.5.0, the print info at CMake stage is below

-- The C compiler identification is GNU 8.5.0
-- The CXX compiler identification is GNU 8.5.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done

Thanks!

@sivachandra
Copy link
Collaborator

The minimum version of gcc required for building the libc is 12.2. Also, I do no think anyone has actually done an arm64 host build of the libc. We have a CI builder for x86_64 which builds using gcc-12.2: https://lab.llvm.org/buildbot/#/builders/250

@DavidSpickett
Copy link
Collaborator

Seems like the function is present for C but not C++ when using gcc https://godbolt.org/z/Gjr1bfWx3.

@Tomcruseal
Copy link
Author

Seems like the function is present for C but not C++ when using gcc https://godbolt.org/z/Gjr1bfWx3.

Yes, thanks for it! and seems the function works well with C++ when using clang https://godbolt.org/z/cG8GsEMs3

@DavidSpickett
Copy link
Collaborator

There are two AArch64 bots that I presume compile this code, https://lab.llvm.org/buildbot/#/builders/138, https://lab.llvm.org/buildbot/#/builders/223. However they both use clang.

I will see what's going on with gcc/g++ and at least raise a bug for it.

@DavidSpickett
Copy link
Collaborator

Filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642.

As far as I can tell it's always worked for clang and arm_acle.h is correct.

I'm a but surprised your initial cmake command wasn't using the newly built clang to build libc, because it looks a lot like https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build. Either way, if you've got a clang that works that's the important thing.

@DavidSpickett DavidSpickett changed the title Failed to build llvm 14.0.5 on Oracle Ampere A1 Arm Failed to build llvm 14.0.5 on Oracle Ampere A1 Arm with GCC 8.5.0 Feb 2, 2023
@DavidSpickett DavidSpickett changed the title Failed to build llvm 14.0.5 on Oracle Ampere A1 Arm with GCC 8.5.0 Failed to build llvm libc 14.0.5 on Oracle Ampere A1 Arm with GCC 8.5.0 Feb 2, 2023
@DavidSpickett
Copy link
Collaborator

There is a slim chance we could work around this or at least document a required version of g++. Might be worth waiting for the gcc bug to be triaged before closing this.

@sivachandra
Copy link
Collaborator

I'm a but surprised your initial cmake command wasn't using the newly built clang to build libc, because it looks a lot like https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build. Either way, if you've got a clang that works that's the important thing.

@Tomcruseal included libc under enabled projects as well as enabled runtimes. That is the suggested way to do it currently but was not supported under 14.0.5. If libc is not included in enabled projects, my guess is it should just work with 14.0.5. With HEAD, CMake will report an error if libc is not included in enabled projects and enabled runtimes.

@sivachandra
Copy link
Collaborator

A correction to my previous comment: It would be the suggested way after https://reviews.llvm.org/D141460 lands.

@Tomcruseal
Copy link
Author

Filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642.

As far as I can tell it's always worked for clang and arm_acle.h is correct.

I'm a but surprised your initial cmake command wasn't using the newly built clang to build libc, because it looks a lot like https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build. Either way, if you've got a clang that works that's the important thing.

@DavidSpickett Thanks! I will have a look at Bootstrapping build, it is quite new to me.

@Tomcruseal
Copy link
Author

A correction to my previous comment: It would be the suggested way after https://reviews.llvm.org/D141460 lands.

@sivachandra Thanks for the link!

@DavidSpickett
Copy link
Collaborator

Fix the full build with gcc: https://reviews.llvm.org/D143261

I also found that the overlay mode has been broken with gcc on any platform for a while. In case you were trying to use that too. Stick with clang if you can.

@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2023

@llvm/issue-subscribers-backend-aarch64

@DavidSpickett
Copy link
Collaborator

For the overlay build see #60481.

DavidSpickett added a commit that referenced this issue Feb 20, 2023
The libc uses some functions that GCC does not currently
implement, that come from Arm's ACLE header usually.

These are:
```
__arm_wsr64
__arm_rsr64
__arm_wsr
__arm_rsr
```

This issue was reported to us (#60473)
and I've then reported that back to GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642).

Even if these functions are added, clang has some non standard extensions
to them that gcc may not take. So we're looking at a fix in gcc 13 at best,
and that may not be enough for what we're doing with them.

So I've added ifdefs to use alternatives with gcc.

For handling the stack pointer, inline assembly is unfortunately the only option.
I have verified that the single mov is essentially what __arm_rsr64 generates.

For fpsr and fpcr the gcc devs suggested using
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Built-in-Functions.html#AArch64-Built-in-Functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143261
@DavidSpickett
Copy link
Collaborator

The fix is on main for this. We could cherry pick it to 16.x but I'm not sure how useful that is.

@Tomcruseal unless you're looking to build some kind of release off of this, are you happy to use the libc from the main branch instead? Which is/will be 17.x.

CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Feb 21, 2023
The libc uses some functions that GCC does not currently
implement, that come from Arm's ACLE header usually.

These are:
```
__arm_wsr64
__arm_rsr64
__arm_wsr
__arm_rsr
```

This issue was reported to us (llvm/llvm-project#60473)
and I've then reported that back to GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642).

Even if these functions are added, clang has some non standard extensions
to them that gcc may not take. So we're looking at a fix in gcc 13 at best,
and that may not be enough for what we're doing with them.

So I've added ifdefs to use alternatives with gcc.

For handling the stack pointer, inline assembly is unfortunately the only option.
I have verified that the single mov is essentially what __arm_rsr64 generates.

For fpsr and fpcr the gcc devs suggested using
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Built-in-Functions.html#AArch64-Built-in-Functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143261
@Tomcruseal
Copy link
Author

The fix is on main for this. We could cherry pick it to 16.x but I'm not sure how useful that is.

@Tomcruseal unless you're looking to build some kind of release off of this, are you happy to use the libc from the main branch instead? Which is/will be 17.x.

Hi @DavidSpickett thanks for it! Yes, I will use the libc from the main branch instead.

@DavidSpickett
Copy link
Collaborator

Great, then I will close this.

veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue Aug 12, 2024
The libc uses some functions that GCC does not currently
implement, that come from Arm's ACLE header usually.

These are:
```
__arm_wsr64
__arm_rsr64
__arm_wsr
__arm_rsr
```

This issue was reported to us (llvm/llvm-project#60473)
and I've then reported that back to GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642).

Even if these functions are added, clang has some non standard extensions
to them that gcc may not take. So we're looking at a fix in gcc 13 at best,
and that may not be enough for what we're doing with them.

So I've added ifdefs to use alternatives with gcc.

For handling the stack pointer, inline assembly is unfortunately the only option.
I have verified that the single mov is essentially what __arm_rsr64 generates.

For fpsr and fpcr the gcc devs suggested using
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Built-in-Functions.html#AArch64-Built-in-Functions.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143261
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants