AOCC
AOCC (AMD Optimizing C/C++ Compiler) compiler system is a high performance, production quality code generation tool.
The AOCC environment provides various options to developers when building and optimizing C, C++, and Fortran applications targeting 32-bit and 64-bit Linux® platforms. The AOCC compiler system offers a high level of advanced optimizations, multi-threading and processor support that includes global optimization, vectorization, inter-procedural analyses, loop transformations, and code generation. AMD also provides highly optimized libraries, which extract the optimal performance from each x86 processor core when utilized. The AOCC Compiler Suite simplifies and accelerates development and tuning for x86 applications.
Installation
This is a highly experimental and unsupported package! Don't make bug reports for build failures with AOCC!
First download the latest version from AOCC's homepage. Read the EULA carefully before accepting it. Choose a location to run it from,
root #
cd /opt
root #
tar -xvf /tmp/aocc-compiler-2.3.0.tar
Optional: Make a symlink for future upgrades:
root #
ln -s aocc-compiler-2.3.0/ aocc
Unarchived media has a script to check for all prerequisities:
root #
cd aocc/
root #
sh AOCC-prerequisites-check.sh
The prerequisities check may return errors for multiple checks; If you don't need these features, they can be ignored.
Usage
You should try to match the symlinks of AOCC to clang's.
root #
cd /opt/aocc/bin
root #
ln -s clang x86_64-pc-linux-gnu-clang
root #
ln -s clang++ x86_64-pc-linux-gnu-clang++
root #
ln -s clang++-11 x86_64-pc-linux-gnu-clang++-11
root #
ln -s clang-11 x86_64-pc-linux-gnu-clang-11
root #
ln -s clang-cl-11 x86_64-pc-linux-gnu-clang-cl
root #
ln -s clang-cl-11 x86_64-pc-linux-gnu-clang-cl-11
root #
ln -s clang-cpp-11 x86_64-pc-linux-gnu-clang-cpp
root #
ln -s clang-cpp-11 x86_64-pc-linux-gnu-clang-cpp-11
With "AOCC_PATH" in make.conf / package.env
Please see /etc/portage/package.env to see how package.env works.
AOCC_PATH="/opt/aocc/bin/"
CC="${AOCC_PATH}clang"
CXX="${AOCC_PATH}clang++"
LDFLAGS="-fuse-ld=lld"
Add LLVM AR, NM and RANLIB if needed:
AOCC_PATH="/opt/aocc/bin/"
CC="${AOCC_PATH}clang"
CXX="${AOCC_PATH}clang++"
AR="${AOCC_PATH}llvm-ar"
NM="${AOCC_PATH}llvm-nm"
RANLIB="${AOCC_PATH}llvm-ranlib"
LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind"
Via /etc/env.d
This is optional, and not really needed. Please see #Switching to aocc below.
root #
cd /etc/env.d
PATH="/opt/aocc/bin"
# we need to duplicate it in ROOTPATH for Portage to respect...
ROOTPATH="/opt/aocc/bin"
MANPATH="/opt/aocc/bin/share/man"
LDPATH="/opt/aocc/lib/:/opt/aocc/lib/lib32:/opt/aocc/lib/lib64"
we use 50aocc so it gets placed before the default LLVM directory in to your
$PATH
. Suggestion is to use full path via AOCC_PATH
in your make.conf or package.env to avoid mistakes.root #
env-update
Relog for the changes take effect!
Test that it works:
user $
clang -v
''
AMD clang version 11.0.0 (CLANG: AOCC_2.3.0-Build#85 2020_11_10) (based on LLVM Mirror.Version.11.0.0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/aocc/bin/
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
package.env
Please see /etc/portage/package.env to see how package.env works.
root #
cd /etc/portage/env
CC="clang"
CXX="clang++"
LDFLAGS="-fuse-ld=lld"
Add LLVM AR, NM and RANLIB if needed:
CC="clang"
CXX="clang++"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"
LDFLAGS="-fuse-ld=lld"
If you don't wish to replace vanilla-clang via /etc/env.d, AOCC can be used per-package with:
AOCC_PATH="/opt/aocc/bin/"
CC="${AOCC_PATH}clang"
CXX="${AOCC_PATH}clang++"
Plainly trusting in this method does not work with every ebuild inheriting llvm.eclass, ie www-client/firefox
make.conf
AOCC can be used globally by defining it in make.conf:
CC="clang"
CXX="clang++"
LDFLAGS="-fuse-ld=lld"
Please see Clang#GCC_fallback_environments
Again if you don't wish to pollute your vanilla-clang, you can define
AOCC_PATH
in make.conf and use that.llvm.eclass
Switching to AOCC
Please read the #Installation part above. Continue from there, without choosing method of usage first.
Add following USE flags to your /etc/portage/make.conf
USE="clang compiler-rt default-compiler-rt default-libcxx libcxx libcxxabi libunwind"
Compile LLVM/clang toolchain with your (working) system default compiler first:
root #
emerge -1avt clang llvm libcxx libcxxabi compiler-rt libunwind lld
After it is done, switch to AOCC:
These are pretty aggressive settings, AOCC can be used without
-stdlib=libc++, -rtlib=compiler-rt -unwindlib=libunwind
etc.AOCC_PATH="/opt/aocc-compiler-2.3.0/bin/"
CC="${AOCC_PATH}clang"
CXX="${AOCC_PATH}clang++"
BUILD_CC="${CC}"
BUILD_CXX="${CXX}"
CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="-stdlib=libc++ ${CFLAGS}"
LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind"
Add rest of LLVM tools if desired needed.
AR="${AOCC_PATH}llvm-ar"
NM="${AOCC_PATH}llvm-nm"
RANLIB="${AOCC_PATH}llvm-ranlib"
Set up GCC fallback for packages which won't compile with clang!
CC="gcc"
CXX="g++"
CXXFLAGS="${CFLAGS}"
LDFLAGS=""
LDFLAGS="${LDFLAGS} -lgcc_s"
LDFLAGS="${LDFLAGS} -lm"
And add known packages to workaround-list:
### system-clang
###
# Doesn't compile with clang and needs gcc
dev-libs/elfutils compiler-gcc.conf
dev-libs/libgcrypt compiler-gcc.conf
dev-libs/popt compiler-gcc.conf
sys-apps/busybox compiler-gcc.conf
sys-apps/sandbox compiler-gcc.conf
sys-apps/sysvinit compiler-gcc.conf
sys-boot/efibootmgr compiler-gcc.conf
sys-devel/gcc compiler-gcc.conf
sys-libs/binutils-libs compiler-gcc.conf
sys-libs/glibc compiler-gcc.conf
# Needs -lgcc_s in LDFLAGS,
# resolve __register_frame / __deregister_frame undefined symbols
sys-devel/llvm ldflags-lgcc_s.conf
# Needs -lm in LDFLAGS,
# "undefined symbol: sqrt" and "undefined symbol: log10" link errors
sys-devel/gettext ldflags-lm.conf
Depending on your installed packages, this list will most likely grow to match your system.
Rebuild clang.
root #
emerge -1avt clang llvm libcxx libcxxabi compiler-rt libunwind lld
Check that your config works:
root #
cat /var/db/pkg/sys-devel/llvm-11.0.0/CC
''
/opt/aocc-compiler-2.3.0/bin/clang
Rebuild your system.
root #
emerge -vt -e @world
Avoid using
--keep-going
, but --resume
and --resume --skipfirst
might come handy.Please see the original forum post for where these steps came from.
This method is rather foolproof and keeps your system vanilla LLVM/clang separated from the AOCC, but it doesn't work with every package inheriting llvm.eclass in Gentoo. Mesa, Firefox and Thunderbird are problematic ones to name a few. They need local hacks to work with AOCC.
Troubleshooting
"/opt/aocc/bin/clang: file not found!"
For some reason the symlink was wiped few times during -e @world
. It seems to be related to packages calling eselect compiler-shadow
during their emerge. There are a couple core packages doing so. Beware of this, and avoid using --keep-going.
If you get an error saying clang: error while loading shared libraries: libLLVM-11.so: cannot open shared object file: No such file or directory you most likely attempted to symlink or override all system LLVM settings. Don't do that.
multilib system, "multilib-strict check failed!"
It seems like AOCC doesn't work very well on a multilib system, might be due to missing i686 compatible compiler. Workarounds for using system-clang might be needed.
See also
- AMD — a semiconductor company. AMD is best known for producing CPUs based on x86 intruction set, motherboard chipsets and their own line of GPUs.
- Clang — a C/C++/Objective-C/C++, CUDA, and RenderScript language front-end for the LLVM project
External resources
- Phoronix web presenting benchmarks between AOCC, clang and GCC
- AOCC 2.3 vs clang 11 vs GCC10