OpenOrbis / OpenOrbis-PS4-Toolchain

The OpenOrbis PS4 custom toolchain. Allows developers to build homebrew for the PS4 without the official SDK.
GNU General Public License v3.0
473 stars 86 forks source link

Samples fail to build with latest LLVM 11. #100

Closed nkrapivin closed 2 years ago

nkrapivin commented 3 years ago

Error: 1>EXEC : error : unknown argument: '-fuse-init-array' Clang:

C:\Users\nikita>clang++ --version
clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\SDKs\LLVM\bin

Perhaps the flag is gone?

Cryptogenic commented 3 years ago

So this again seems to be the result of dumb changes on the LLVM side which are screwing us. It's the result of this commit I believe: https://reviews.llvm.org/D71393

Essentially to make "commands shorter" they removed the fuse-init-array flag and replaced it with the fno-use-init-array flag since most targets use init arrays by default by now. So instead of allowing init arrays to be default or opt-in, they made it default or opt-out. This completely screws with targets that do not use init arrays by default such as the freebsd target tuple we use for homebrew.

I don't know of an easy solution to this problem, because they essentially say "if your target gets messed up, it's your problem, have fun", meaning we would have to modify the target directly and distribute a modified clang to account for it. At that point, people might as well just use clang10 and below.

bucanero commented 3 years ago

since LLVM 11 and LLVM 12 can't be used, which version should we use? I think that v10 should do it, right?

I don't see a formula on brew to install llvm 10, but there's one for llvm 9. I need to try and see if it works.

Edit: tested and I was able to build the hello_world sample using llvm@9.

You need to install llvm@9 and symlink it to llvm so make works properly:

brew install llvm@9
ln -s /usr/local/opt/llvm@9 /usr/local/opt/llvm
lordfriky commented 3 years ago

Since LLVM 9 doesn't support Big Sur nor Apple Silicon (or at least brew doesn't provide formulas for them) it is not a proper solution for macOS users, but it's still a nice workaround, thanks bucanero! :)

bucanero commented 3 years ago

Since LLVM 9 doesn't support Big Sur nor Apple Silicon (or at least brew doesn't provide formulas for them) it is not a proper solution for macOS users, but it's still a nice workaround, thanks bucanero! :)

hello @lordfriky

I'm using macOS Big Sur (11.3.1), and those commands worked fine. So at least on macOS (intel) it is a valid solution. Also, the llvm@9 formula is still there, I just updated brew and checked:

% brew info llvm@9
llvm@9: stable 9.0.1 (bottled) [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
/usr/local/Cellar/llvm@9/9.0.1_2 (6,839 files, 3.7GB)
  Poured from bottle on 2021-04-29 at 18:18:10
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/llvm@9.rb
License: Apache-2.0
==> Dependencies
Build: cmake ✘
Required: libffi ✔, swig ✔
==> Requirements
Build: Xcode ✔
Required: x86_64 architecture ✔
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm@9/lib -Wl,-rpath,/usr/local/opt/llvm@9/lib"

llvm@9 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have llvm@9 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/llvm@9/bin:$PATH"' >> ~/.zshrc

For compilers to find llvm@9 you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm@9/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm@9/include"

==> Analytics
install: 1,066 (30 days), 3,256 (90 days), 10,497 (365 days)
install-on-request: 316 (30 days), 1,144 (90 days), 4,557 (365 days)
build-error: 0 (30 days)
[MacBook-Pro-13] /opt/OpenOrbis-PS4-Toolchain % 
lordfriky commented 3 years ago

Oh, I thought it wasn't compatible with Big Sur because the webpage of the formula don't mention it :b I can't test that myself because I no longer own an Intel Mac and the one I had was too old for it (it even was too old for Catalina but I installed it with a patch), but thank you so much for letting me know that!

HearseDev commented 3 years ago

Fix for macOS Big Sur: install llvm9 using brew install llvm@9 Then, in your project Makefile, change CC := /usr/local/opt/llvm/bin/clang++ to CC := /usr/local/opt/llvm@9/bin/clang++ LD := /usr/local/opt/llvm/bin/ld.lld to LD := /usr/local/opt/llvm@9/bin/ld.lld Downside is, you have to do that every time for your project or you can make the changes yourself in the setup project script and edit the default makefile so you don't have to do it every time. It's better than symlinking especially if I use other tools that rely on llvm12.

Instructions for people that don't want to edit makefile every project. cd into $OO_PS4_TOOLCHAIN/samples/hello_world make the same changes as above to the makefile in the directory. The script uses this sample projects makefile as a default makefile for new projects. After this, your new projects makefile should have the changes already.

bucanero commented 3 years ago

Oh, I thought it wasn't compatible with Big Sur because the webpage of the formula don't mention it :b I can't test that myself because I no longer own an Intel Mac and the one I had was too old for it (it even was too old for Catalina but I installed it with a patch), but thank you so much for letting me know that!

btw, is there any fix or workaround to build the open Orbis toolchain on Mac M1 (arm64)?

bucanero commented 3 years ago

btw, is there any fix or workaround to build the open Orbis toolchain on Mac M1 (arm64)?

Replying to myself, I found a workaround to use Open Orbis on macOS M1 (arm64). I know it's probably not the optimal way, but at least I've got everything working. I was able to compile samples and execute them correctly on my PS4 (6.72)

Steps:

Now you have a compatible LLVM compiler to use with Open Orbis. On M1 arch it will run using Rosetta2 so performance might not be the greatest, but it works just fine.

Finally, install the regular MacOS installer from OpenOrbis release page. You're good to go 😄

bucanero commented 2 years ago

For those concerned about performance, you can also build LLVM10 from sources for arm64 (macOS), by doing this:

Note: cmake and ninja are required, you can install them with brew install cmake ninja

Download and unpack the v10.0.1 source files: https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/llvm-project-10.0.1.tar.xz

then, create a folder for this build...

cd llvm-project-10.0.1
mkdir build
cd build

call cmake to generate the required build scripts:

cmake -G Ninja \
    -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \
    -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;lld;clang-tools-extra" \
    -DLLVM_TARGETS_TO_BUILD=all -DCMAKE_BUILD_TYPE=Release ../llvm

now, lets compile:

ninja clang
ninja cxx
ninja lld
ninja llvm-ar

when finished, you'll have the llvm 10 native binaries in the bin folder. You can copy the build folder to /usr/local/opt/llvm and use it with the PS4 Open Orbis SDK.

godreborn commented 2 years ago

I'm having the same problem. I don't really understand how to symlink llvm@9 either. I downloaded it with brew, but the command posted above doesn't work, since there is no opt folder in that location. I'm using debian btw. I tried to compile hello_world, and I got the same error as above.

bucanero commented 2 years ago

I'm having the same problem. I don't really understand how to symlink llvm@9 either. I downloaded it with brew, but the command posted above doesn't work, since there is no opt folder in that location. I'm using debian btw. I tried to compile hello_world, and I got the same error as above.

the notes above are for macOS, but they should work for Linux too. I'm not sure were Open Orbis looks for LLVM on Linux, but in any case if you don't have /usr/local/opt/ you can just create it:

mkdir -p /usr/local/opt
godreborn commented 2 years ago

I'm having the same problem. I don't really understand how to symlink llvm@9 either. I downloaded it with brew, but the command posted above doesn't work, since there is no opt folder in that location. I'm using debian btw. I tried to compile hello_world, and I got the same error as above.

the notes above are for macOS, but they should work for Linux too. I'm not sure were Open Orbis looks for LLVM on Linux, but in any case if you don't have /usr/local/opt/ you can just create it:

mkdir -p /usr/local/opt

thanks. I've tried several things, and the samples still fail to compile. I think I'm doing something wrong with the symlink. I think I found the location of llvm@9:

image the end of that command, is that to llvm 11? it's not called llvm on my computer, but I found a folder named llvm-11:

image

I tried symlinking both together, and it didn't affect anything.

godreborn commented 2 years ago

nm. I got it to work in much easier way:

image

Cryptogenic commented 2 years ago

New build scripts, linker script, and create-fself should now support new LLVM versions.