aswf-docker icon indicating copy to clipboard operation
aswf-docker copied to clipboard

Setting `CLANG_DEFAULT_PIE_ON_LINUX` when building clang

Open swahtz opened this issue 1 year ago • 1 comments

It seems that the behaviour for whether or not -fPIE is on by default in Linux changed in clang 14 to be controlled by a flag when building clang:

https://github.com/llvm/llvm-project/commit/1042de90589c74c6998c127d1ee1b33ff3efb8cc

We were having a bit of an issue switching to the 2024 OS CI images and building with clang++ on the OpenVDB project (when moving from 2022 clang11 to the 2024 image):

https://github.com/AcademySoftwareFoundation/openvdb/pull/1926

Shall we set CLANG_DEFAULT_PIE_ON_LINUX to match the behaviour of gcc?

swahtz avatar Oct 22 '24 06:10 swahtz

As a point of comparison, it seems that gcc 11.2.1 which is installed in the aswf-docker containers from gcc-toolset is not configured with either --enable-host-pie or --enable-default-pie :

Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/gcc-toolset-11/root/usr --mandir=/opt/rh/gcc-toolset-11/root/usr/share/man --infodir=/opt/rh/gcc-toolset-11/root/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20220127/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux

The 2022 images were available with multiple Clang versions, from 10-14. Looking at .github/workflows/nanovdb.yml the image is specified as aswf/ci-openvdb:2022 or aswf/ci-openvdb:2024, which according to:

https://hub.docker.com/r/aswf/ci-openvdb/tags

has the 2022 tag defaulting to clang 10.0.1: this is confusing since clang 10 is well before clang added the ability to build clang with PIE enabled by default. The 2024 tag is defaulting to 2024-clang17, where clang 17.0.6 is not built with that flag.

For 2022/clang 10.0.1:

[root@a1865748f473 aswf]# llvm-config --cflags
-I/usr/local/include  -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
[root@a1865748f473 aswf]# llvm-config --cxxflags
-I/usr/local/include -std=c++14   -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
[root@a1865748f473 aswf]# llvm-config --ldflags
-L/usr/local/lib

For 2022/clang 17.0.6:

[root@4f19be8f8c79 aswf]# llvm-config --cflags
-I/usr/local/include  -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
[root@4f19be8f8c79 aswf]# llvm-config --cxxflags
-I/usr/local/include -std=c++17   -fno-exceptions -funwind-tables -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
[root@4f19be8f8c79 aswf]# llvm-config --ldflags
-L/usr/local/lib64

Is there a change between CUDA 11.4 (in the 2022 images) and CUDA 12.6 (in latest 2024 images) which now requires compiling with PIE which did not before?

jfpanisset avatar Nov 03 '24 21:11 jfpanisset