https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118401
Bug ID: 118401 Summary: [Offload][OpenMP][OpenACC] Compilation failure with -finstrument-functions active Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: j.reu...@fz-juelich.de Target Milestone: --- Created attachment 60091 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60091&action=edit Source files & Makefile to reproduce the issue Some applications, e.g. performance tools, are interested in instrumenting other applications to collect information and present them to users. For this, tool might use compiler plugins, or rely on existing flags. Many compilers support function instrumentation via -finstrument-functions or similar flags. This allows tools to implement '__cyg_profile_func_enter' and '__cyg_profile_func_exit' to get information about the called function and its callsite. However, this can cause issues in the case where users try to offload code via OpenACC or OpenMP. With GCC 13.3.0 and 14.2.0, different error messages can be observed depending on the optimization level. A reproducer for this is attached. With a simple 'make' the error should be reproducible. I've checked this on two different systems (Arch Linux, GCC 14.2.0 built via EasyBuild, RTX 3070 & Rocky Linux 9, GCC 13.3.0 built via EasyBuild, A100 ) with the same results. ---- The reproducer includes three different C files with basically the same code. One variant adds OpenMP target offloading, another OpenACC. The third variant doesn't do any offloading. The last C file just implements '__cyg_profile_func_enter' and '__cyg_profile_func_exit' and prints the pointers. The Makefile first compiles all files to object files. For the actual "user code", instrumentation via '-finstrument-functions' is used. This is not active for the "profiling interface". After that, the interface is linked together with the user code. This represents the behavior tools might use to instrument applications. Here, different errors occur: With -O0: gcc -O0 -g -Wall -Wextra -Werror -save-temps -fno-strict-aliasing -fwrapv -fopenacc -foffload=nvptx-none instrumented-application-openacc.o profile-interface.o -o instrumented-application-openacc unresolved symbol __cyg_profile_func_exit collect2: error: ld returned 1 exit status nvptx mkoffload: fatal error: x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status compilation terminated. lto-wrapper: fatal error: /data/EasyBuild-develop/software/GCCcore/13.3.0/libexec/gcc/x86_64-pc-linux-gnu/13.3.0//accel/nvptx-none/mkoffload returned 1 exit status compilation terminated. /data/EasyBuild-develop/software/binutils/2.42-GCCcore-13.3.0/bin/ld: error: lto-wrapper failed collect2: error: ld returned 1 exit status make: *** [Makefile:32: instrumented-application-openacc] Error 1 This makes sense, as '__cyg_profile_func_exit' is not implemented for any accelerator. However, many tools are not interested in doing such thing, and only want to rely on the host side. A similar issue was encountered with LLVM some time ago: https://github.com/llvm/llvm-project/issues/59799. Here, the solution was to allow specifying the flag for the host-side only (via '-Xarch_host'). I'm not aware of a similar flag for GCC. With -O1: gcc -O1 -g -Wall -Wextra -Werror -save-temps -fno-strict-aliasing -fwrapv -fopenacc -foffload=nvptx-none instrumented-application-openacc.o profile-interface.o -o instrumented-application-openacc ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 33; error : Illegal operand type to instruction 'ld' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 42; error : Illegal operand type to instruction 'ld' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 33; error : Unknown symbol '%frame' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 42; error : Unknown symbol '%frame' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 66; error : Illegal operand type to instruction 'ld' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 75; error : Illegal operand type to instruction 'ld' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 66; error : Unknown symbol '%frame' ptxas ./instrumented-application-openacc.xnvptx-none.mkoffload.o, line 75; error : Unknown symbol '%frame' ptxas fatal : Ptx assembly aborted due to errors nvptx-as: ptxas returned 255 exit status nvptx mkoffload: fatal error: x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status compilation terminated. lto-wrapper: fatal error: /data/EasyBuild-develop/software/GCCcore/13.3.0/libexec/gcc/x86_64-pc-linux-gnu/13.3.0//accel/nvptx-none/mkoffload returned 1 exit status compilation terminated. /data/EasyBuild-develop/software/binutils/2.42-GCCcore-13.3.0/bin/ld: error: lto-wrapper failed collect2: error: ld returned 1 exit status make: *** [Makefile:32: instrumented-application-openacc] Error 1 This error message is more confusing. I guess something trips here by trying to instrument with '-finstrument-functions', but this is just pure guessing from my side. ---- GCC information: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/data/EasyBuild-develop/software/GCCcore/14.2.0/libexec/gcc/x86_64-pc-linux-gnu/14.2.0/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none Target: x86_64-pc-linux-gnu Configured with: ../configure --enable-languages=c,c++,fortran --without-cuda-driver --enable-offload-targets=nvptx-none --enable-lto --enable-checking=release --disable-multilib --enable-shared=yes --enable-static=yes --enable-threads=posix --enable-plugins --enable-gold --enable-ld=default --prefix=/data/EasyBuild-develop/software/GCCcore/14.2.0 --with-local-prefix=/data/EasyBuild-develop/software/GCCcore/14.2.0 --enable-bootstrap --with-isl=/data/EasyBuild-develop/build/GCCcore/14.2.0/system-system/gcc-14.2.0/stage2_stuff --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.2.0 (GCC)