Skip to content

Commit d76b9d6

Browse files
authored
[OpenMP][cmake] Simplify -m32 handling (#142742)
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 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 70fce92 commit d76b9d6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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)
@@ -159,7 +159,7 @@ endfunction()
159159
# Fortran flags
160160
function(libomp_get_fflags fflags)
161161
set(fflags_local)
162-
if(${IA32})
162+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
163163
libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
164164
endif()
165165
set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS})

0 commit comments

Comments
 (0)