From e29144d0f2cec194f874f3ea1c0f1406a0e459a8 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Mon, 2 Jun 2025 13:20:38 +0200 Subject: [PATCH 1/2] [OpenMP][cmake] Add SPARC support Linking `libomp.so` on 32-bit SPARC `FAIL`s with ``` ld: fatal: file projects/openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_asm.S.o: wrong ELF class: ELFCLASS64 ``` This was a 1-stage build with a 64-bit-default `gcc`. Unlike the C++ sources, which were compiled as 32-bit objects due to the use of `-DCMAKE_CXX_FLAGS=-m32`, the assembler sources were not. This patch adds SPARC infrastructure to the `openmp` `cmake` files, matching what is done for other architectures. Simultaneously it simplifies passing `-m32`: instead of doing it per architecture, `-m32` is now always passed when the target uses 32-bit pointers and supports the option. Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`, `sparc-unknown-linux-gnu`, `sparc64-unknown-linux-gnu`, `i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and `x86_64-pc-linux-gnu`. --- openmp/runtime/CMakeLists.txt | 6 ++++++ openmp/runtime/cmake/LibompHandleFlags.cmake | 20 ++++++++++---------- openmp/runtime/cmake/LibompUtils.cmake | 4 ++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt index 6041fb2b23a0f..b6c4759ec03f7 100644 --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -190,6 +190,8 @@ set(VE FALSE) set(S390X FALSE) set(WASM FALSE) set(PPC FALSE) +set(SPARC FALSE) +set(SPARCV9 FALSE) if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture set(IA32 TRUE) elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture @@ -226,6 +228,10 @@ elseif("${LIBOMP_ARCH}" STREQUAL "s390x") # S390x (Z) architecture set(S390X TRUE) elseif("${LIBOMP_ARCH}" STREQUAL "wasm32") # WebAssembly architecture set(WASM TRUE) +elseif("${LIBOMP_ARCH}" STREQUAL "sparc") # SPARC architecture + set(SPARC TRUE) +elseif("${LIBOMP_ARCH}" STREQUAL "sparcv9") # SPARC V9 architecture + set(SPARCV9 TRUE) endif() # Set some flags based on build_type diff --git a/openmp/runtime/cmake/LibompHandleFlags.cmake b/openmp/runtime/cmake/LibompHandleFlags.cmake index cb7e488652230..103637ae970dd 100644 --- a/openmp/runtime/cmake/LibompHandleFlags.cmake +++ b/openmp/runtime/cmake/LibompHandleFlags.cmake @@ -60,10 +60,10 @@ function(libomp_get_cxxflags cxxflags) libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) endif() # Architectural C and C++ flags + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) + endif() if(${IA32}) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) - endif() libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) @@ -81,10 +81,10 @@ endfunction() function(libomp_get_asmflags asmflags) set(asmflags_local) # Architectural assembler flags + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) + endif() if(${IA32}) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) - endif() libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG) libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG) elseif(${MIC}) @@ -112,10 +112,10 @@ function(libomp_get_ldflags ldflags) libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) # Architectural linker flags + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) + endif() if(${IA32}) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) - endif() libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) elseif(${MIC}) libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) @@ -162,7 +162,7 @@ endfunction() # Fortran flags function(libomp_get_fflags fflags) set(fflags_local) - if(${IA32}) + if(CMAKE_SIZEOF_VOID_P EQUAL 4) libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) endif() set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS}) diff --git a/openmp/runtime/cmake/LibompUtils.cmake b/openmp/runtime/cmake/LibompUtils.cmake index 58b93b384a76a..a810881c2544e 100644 --- a/openmp/runtime/cmake/LibompUtils.cmake +++ b/openmp/runtime/cmake/LibompUtils.cmake @@ -117,6 +117,10 @@ function(libomp_get_legal_arch return_arch_string) set(${return_arch_string} "VE" PARENT_SCOPE) elseif(${S390X}) set(${return_arch_string} "S390X" PARENT_SCOPE) + elseif(${SPARC}) + set(${return_arch_string} "SPARC" PARENT_SCOPE) + elseif(${SPARCV9}) + set(${return_arch_string} "SPARCV9" PARENT_SCOPE) else() set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE) libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}") From b4e3956e5edb14997141e96cebb0321e675f53f5 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Wed, 4 Jun 2025 10:43:55 +0200 Subject: [PATCH 2/2] Split off `-m32` handling to new PR #142742. --- openmp/runtime/cmake/LibompHandleFlags.cmake | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/openmp/runtime/cmake/LibompHandleFlags.cmake b/openmp/runtime/cmake/LibompHandleFlags.cmake index 103637ae970dd..cb7e488652230 100644 --- a/openmp/runtime/cmake/LibompHandleFlags.cmake +++ b/openmp/runtime/cmake/LibompHandleFlags.cmake @@ -60,10 +60,10 @@ function(libomp_get_cxxflags cxxflags) libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) endif() # Architectural C and C++ flags - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) - endif() if(${IA32}) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) + endif() libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) @@ -81,10 +81,10 @@ endfunction() function(libomp_get_asmflags asmflags) set(asmflags_local) # Architectural assembler flags - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) - endif() if(${IA32}) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) + endif() libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG) libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG) elseif(${MIC}) @@ -112,10 +112,10 @@ function(libomp_get_ldflags ldflags) libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG) libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG) # Architectural linker flags - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) - endif() if(${IA32}) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) + endif() libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) elseif(${MIC}) libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) @@ -162,7 +162,7 @@ endfunction() # Fortran flags function(libomp_get_fflags fflags) set(fflags_local) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) + if(${IA32}) libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG) endif() set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS})