<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99642>99642</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Linking against libclang_rt.builtins-wasm32.a fails with undefined symbols (__stack_chk_guard/__stack_chk_fail)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bw-86
      </td>
    </tr>
</table>

<pre>
    Hi everyone, I am on Debian Bookworm and installed the following packages from the llvm repository:
```
clang-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed]
clang-tools-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed]
libc++-18-dev-wasm32/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 all [installed]
libc++-18-dev/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed]
libc++1-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libc++abi-18-dev-wasm32/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 all [installed,automatic]
libc++abi-18-dev/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libc++abi1-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libclang-common-18-dev/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libclang-cpp18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libclang-rt-18-dev-wasm32/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 all [installed]
libclang-rt-18-dev/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libclang1-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libllvm18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libunwind-18-dev/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
libunwind-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
lld-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed]
llvm-18-dev/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
llvm-18-linker-tools/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
llvm-18-runtime/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
llvm-18-tools/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
llvm-18/unknown,now 1:18.1.8~++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143 amd64 [installed,automatic]
```

I am trying to link a small hello world binary for the wasm32-wasi target. This is my source file (wasm.cpp):
```
#include <print>

int main() {
        std::print("HELLO!\n");
}
```

I get this error message:
```
$ clang++-18 -target wasm32-wasi -std=c++23 -fno-exceptions -v wasm.cpp 
Debian clang version 18.1.8 (++20240718080534+3b5b5c1ec4a3-1~exp1~20240718200641.143)
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-18/bin/clang" -cc1 -triple wasm32-unknown-wasi -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name wasm.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/tmp -v -fcoverage-compilation-dir=/tmp -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/include/wasm32-wasi/c++/v1 -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include/wasm32-wasi -internal-isystem /usr/local/include -internal-isystem /usr/include/wasm32-wasi -internal-isystem /usr/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcolor-diagnostics -dwarf-debug-flags "/usr/lib/llvm-18/bin/clang --driver-mode=g++ --target=wasm32-wasi -std=c++23 -fno-exceptions -v wasm.cpp -dumpdir a-" -o /tmp/wasm-43a0c3.o -x c++ wasm.cpp
clang -cc1 version 18.1.8 based upon LLVM 18.1.8 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/local/include/wasm32-wasi"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/wasm32-wasi/c++/v1
 /usr/lib/llvm-18/lib/clang/18/include
 /usr/local/include
 /usr/include/wasm32-wasi
 /usr/include
End of search list.
 "/usr/bin/wasm-ld-18" -m wasm32 -L/usr/lib/wasm32-wasi /usr/lib/wasm32-wasi/crt1-command.o /tmp/wasm-43a0c3.o -lc++ -lc++abi -lc /usr/lib/llvm-18/lib/clang/18/lib/wasi/libclang_rt.builtins-wasm32.a -o a.out
wasm-ld-18: error: /usr/lib/llvm-18/lib/clang/18/lib/wasi/libclang_rt.builtins-wasm32.a(umodti3.c.obj): undefined symbol: __stack_chk_guard
wasm-ld-18: error: /usr/lib/llvm-18/lib/clang/18/lib/wasi/libclang_rt.builtins-wasm32.a(umodti3.c.obj): undefined symbol: __stack_chk_guard
wasm-ld-18: error: /usr/lib/llvm-18/lib/clang/18/lib/wasi/libclang_rt.builtins-wasm32.a(umodti3.c.obj): undefined symbol: __stack_chk_fail
clang++-18: error: linker command failed with exit code 1 (use -v to see invocation)
```

It seems as if libclang_rt.builtins-wasm32.a was compiled with `-fstack-protector`, but there is no support for this with the chosen target. Adding `-fno-stack-protector` to my invocation does not change anything since the symbol references do not belong to my translation unit.

Am I doing something wrong here? Thanks for your help!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWc1u4zgSfhrmUqBgUbZjH3xI4jZmgCz2MthrQJElmW3-CCRlx5d-9gUp2XHSnUx6d2fahwUaRouqIr8qfvWn8BBUaxFXZHZPZusb3set86v6QBfzm9rJ4-o3BbhHf3QWCXuA34EbcBbWWCtu4d653cF5A9xKUDZErjVKiFuExmntDsq20HGx4y0GaLwz-Z3WewMeOxdUdP5IqjsyWZPJHZlPxn_5UWhuW1ouCNv0dmfdwRL2YN0BSlLdlYuiLBbfCLsn7J5N2HRyWy4mi8msmhJ2X9WzeiZKFFNe0fIbPnflt5MQm0zm07IopxVwI-dTILP7M3YyW18eHp3T4VdB0KoWw-a0XFCJe3rgwVTsLwSj9Seh_GKHlH_3nbAH3kdneFTiB3B4rX7ZFX0W2XW562ouMIe5cMY4e02OGmB13TV5yceryEOvsVyNe66F0am4XgeS3h6UlVd0T2dAvx6M_tthvBy9N1dzJyMWrewO_dBtXQ0o39uoDF4Nnqvyzi_H8WZWGH7zeBL9MY0d0UGiFXAIJtWTLWrt4OC8llAry_0RGufzPDKUs1TVFETuW4wF_LFVAVQAc4Tgei8QGqURCFsk6UJ0HWHL9yYXwiplhe4lAqkeOq9sJNWXS6TKRjBcWcIWhC2B3N6f3i5DlGnf6m7QSwLsty-Pj_8krCSzB0sYy0efNG4_9kiLEWIyBr13HgyGwFt8H_kUcjk7d_tAB5e88hLN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