Skip to content

Commit e29144d

Browse files
committed
[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`.
1 parent e3a0cb8 commit e29144d

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

openmp/runtime/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ set(VE FALSE)
190190
set(S390X FALSE)
191191
set(WASM FALSE)
192192
set(PPC FALSE)
193+
set(SPARC FALSE)
194+
set(SPARCV9 FALSE)
193195
if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture
194196
set(IA32 TRUE)
195197
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
226228
set(S390X TRUE)
227229
elseif("${LIBOMP_ARCH}" STREQUAL "wasm32") # WebAssembly architecture
228230
set(WASM TRUE)
231+
elseif("${LIBOMP_ARCH}" STREQUAL "sparc") # SPARC architecture
232+
set(SPARC TRUE)
233+
elseif("${LIBOMP_ARCH}" STREQUAL "sparcv9") # SPARC V9 architecture
234+
set(SPARCV9 TRUE)
229235
endif()
230236

231237
# Set some flags based on build_type

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ function(libomp_get_cxxflags cxxflags)
6060
libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG)
6161
endif()
6262
# Architectural C and C++ flags
63+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
64+
libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG)
65+
endif()
6366
if(${IA32})
64-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
65-
libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG)
66-
endif()
6767
libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG)
6868
libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG)
6969
libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG)
@@ -81,10 +81,10 @@ endfunction()
8181
function(libomp_get_asmflags asmflags)
8282
set(asmflags_local)
8383
# Architectural assembler flags
84+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
85+
libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG)
86+
endif()
8487
if(${IA32})
85-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
86-
libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG)
87-
endif()
8888
libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG)
8989
libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG)
9090
elseif(${MIC})
@@ -112,10 +112,10 @@ function(libomp_get_ldflags ldflags)
112112
libomp_append(ldflags_local -static-intel LIBOMP_HAVE_STATIC_INTEL_FLAG)
113113
libomp_append(ldflags_local /SAFESEH LIBOMP_HAVE_SAFESEH_FLAG)
114114
# Architectural linker flags
115+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
116+
libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG)
117+
endif()
115118
if(${IA32})
116-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
117-
libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG)
118-
endif()
119119
libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG)
120120
elseif(${MIC})
121121
libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
@@ -162,7 +162,7 @@ endfunction()
162162
# Fortran flags
163163
function(libomp_get_fflags fflags)
164164
set(fflags_local)
165-
if(${IA32})
165+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
166166
libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
167167
endif()
168168
set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS})

openmp/runtime/cmake/LibompUtils.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ function(libomp_get_legal_arch return_arch_string)
117117
set(${return_arch_string} "VE" PARENT_SCOPE)
118118
elseif(${S390X})
119119
set(${return_arch_string} "S390X" PARENT_SCOPE)
120+
elseif(${SPARC})
121+
set(${return_arch_string} "SPARC" PARENT_SCOPE)
122+
elseif(${SPARCV9})
123+
set(${return_arch_string} "SPARCV9" PARENT_SCOPE)
120124
else()
121125
set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)
122126
libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}")

0 commit comments

Comments
 (0)