<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92459>92459</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang][driver] support symbol visibility flag
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
h-vetinari
</td>
</tr>
</table>
<pre>
While working on upgrading the SciPyb-builds in conda-forge to use flang 18, I'm running into the fact that flang got a lot stricter about unknown flags (which previously were just ignored, presumably).
Some of this probably needs to be fixed on the meson side (which generates the actual compiler invocations from the build files), but I noticed one case where there's both arguably missing functionality, and the warnings don't make sense, namely `-fvisibility=`, which clang [documents](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fvisibility) as:
> Set the default symbol visibility for all global definitions. <arg> must be ‘default’, ‘hidden’, ‘internal’ or ‘protected’.
SciPy specifies hidden visibility for some targets, and when this gets hit by flang (on windows), the result at first is
```
[962/1475] Compiling Fortran object scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj
FAILED: scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj
"flang-new" "-Iscipy\linalg\_interpolative.cp311-win_amd64.pyd.p" "-Iscipy\linalg" "-I..\scipy\linalg" "-I..\..\_h_env\Lib\site-packages\numpy\_core\include" "-I..\..\_h_env\Lib\site-packages\numpy\f2py\src" "-Iscipy\lib_fortranobject.a.p" "-I%PREFIX%\Include" "-fvisibility=hidden" "-DNDEBUG" "-D_FILE_OFFSET_BITS=64" "-O3" "-D_CRT_SECURE_NO_WARNINGS" "-D_MT" "-D_DLL" "--target=x86_64-pc-windows-msvc" "-DMS_WIN64=" "-module-dir" "scipy\linalg\_interpolative.cp311-win_amd64.pyd.p" -o scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj "-c" ../scipy/linalg/src/id_dist/src/dfft.f
flang-new: error: unknown argument '-fvisibility=hidden'; did you mean '-Xclang -fvisibility=hidden'?
```
Using the suggested `-Xclang -fvisibility=hidden`, I then get
```
[962/1475] Compiling Fortran object scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj
FAILED: scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj
"flang-new" "-Iscipy\linalg\_interpolative.cp311-win_amd64.pyd.p" "-Iscipy\linalg" "-I..\scipy\linalg" "-I..\..\_h_env\Lib\site-packages\numpy\_core\include" "-I..\..\_h_env\Lib\site-packages\numpy\f2py\src" "-Iscipy\lib_fortranobject.a.p" "-I%PREFIX%\Include" "-Xclang" "-fvisibility=hidden" "-DNDEBUG" "-D_FILE_OFFSET_BITS=64" "-O3" "-D_CRT_SECURE_NO_WARNINGS" "-D_MT" "-D_DLL" "--target=x86_64-pc-windows-msvc" "-DMS_WIN64=" "-module-dir" "scipy\linalg\_interpolative.cp311-win_amd64.pyd.p" -o scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj "-c" ../scipy/linalg/src/id_dist/src/dfft.f
flang-new: error: unknown argument '-Xclang'; did you mean '-Xflang'?
```
Finally, using `-Xflang -fvisibility=hidden`, the result is
```
[962/1475] Compiling Fortran object scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj
FAILED: scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj
"flang-new" "-Iscipy\linalg\_interpolative.cp311-win_amd64.pyd.p" "-Iscipy\linalg" "-I..\scipy\linalg" "-I..\..\_h_env\Lib\site-packages\numpy\_core\include" "-I..\..\_h_env\Lib\site-packages\numpy\f2py\src" "-Iscipy\lib_fortranobject.a.p" "-I%PREFIX%\Include" "-Xflang" "-fvisibility=hidden" "-DNDEBUG" "-D_FILE_OFFSET_BITS=64" "-O3" "-D_CRT_SECURE_NO_WARNINGS" "-D_MT" "-D_DLL" "--target=x86_64-pc-windows-msvc" "-DMS_WIN64=" "-module-dir" "scipy\linalg\_interpolative.cp311-win_amd64.pyd.p" -o scipy/linalg/_interpolative.cp311-win_amd64.pyd.p/src_id_dist_src_dfft.f.obj "-c" ../scipy/linalg/src/id_dist/src/dfft.f
error: unknown argument: '-fvisibility=hidden'
```
At the very least the warnings are misleading. But setting symbol visibility should probably be supported in general?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWM1u4zgSfhr6UpBgU5Z_Dj4ktjUwkEkPkm703ASKLEnspkiBpOzx2y9I2fFkNuldDKYPuwhgyCKrWD-sqo9UMedkoxE3JL8n-W7CBt8au2mTI3qpmZWTyojz5msrFcLJ2O9SN2A0DH1jmQgD3yI8c_nbuUqqQSrhQGrgRguW1MY2CN7A4BBqxXQDsxWhWzgQuuzADloHCVJ7E8XUjHvwLfMX5sZ4YKCMB-et5B4tsMoMHgb9XZuTDmyNA0JXp1byFnqLR2kGp85wQovwbXAeZKONRRHU9hbd0LFKnQldp2S6I9O78flsOgRTg2-lg96aKjCBRhQu2F8h1PIPFMHzYGiHzmhwUuBNeYMaLfPoIgfjfmAKuOl6qdCC1EfDmZdGO6it6SJT3C-opUJH6DpYWA0eDqCNlzxqQ-DMIZza4I4PT0KXDirjW2C2GaKZnXQu7GM9aB40MCX9OUhjWkQ9J2bDRjsQRhO69NCx7wgOtcPAplmH6gxkMU3qo3SyklFAtiOLaaCP_vEYEpLfC8OHDrV3JN8Rumq97x3J7ggtCC0iV6rUsUuNbQgthOGO0GIb5rem65gWD1LjE9ZoUXNMW98pQjPeCdMH65Mo4pUldA0sqhgjlu3hGX30TGDNBuXBnbvKKLitgdpYYEpBo0zFVGCUWsb9T4FkW2abIKcLGVIhkD0lqylZry4Cr-MYlBdiK4VA_TZNao9WM_VCBWNv1N4aj9yjeCG_Tr9QP-B65LKW6GBU9Fd3XEhSz2yD3l3De2pRj1kbZqGVHqrzpXwIXRkNJ6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