Skip to content

Commit af961ad

Browse files
authored
docs: Add note regarding limiations of EMSCRIPTEN_KEEPALIVE (#18049)
See #6233
1 parent 264b61d commit af961ad

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

site/source/docs/api_reference/emscripten.h.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,15 +899,19 @@ Compiling
899899
900900
.. c:macro:: EMSCRIPTEN_KEEPALIVE
901901
902-
Forces LLVM to not dead-code-eliminate a function.
903-
904-
This also exports the function, as if you added it to :ref:`EXPORTED_FUNCTIONS <faq-dead-code-elimination>`.
902+
Tells the compiler and linker to preserve a symbol, and export it, as if you
903+
added it to :ref:`EXPORTED_FUNCTIONS <faq-dead-code-elimination>`.
905904
906905
For example: ::
907906
908907
void EMSCRIPTEN_KEEPALIVE my_function() { printf("I am being kept alive\n"); }
909908
910-
909+
Note that this will only work if the object file in which the symbol is
910+
defined is otherwise included by the linker. If the object file is part of an
911+
archive, and is not otherwise referenced the linker will not include it at all
912+
and any symbols in the object file will not be included or exported. One way
913+
to work around this limitation is to use the ``-Wl,--whole-archive`` /
914+
``-Wl,--no-whole-archive`` flags on either side of the archive file.
911915
912916
913917
Worker API

0 commit comments

Comments
 (0)