Index: clang/docs/StandardCPlusPlusModules.rst =================================================================== --- clang/docs/StandardCPlusPlusModules.rst +++ clang/docs/StandardCPlusPlusModules.rst @@ -910,6 +910,70 @@ this means the build speedup at higher optimization levels may be lower than expected given ``O0`` experience, but does provide by more optimization opportunities. +Can modules speedup linking? +---------------------------- + +It is possible. Since the use of modules can reduce the symbols in the object files. + +Here is an example, + +.. code-block:: c++ + + // A.h + inline void notDirectlyUsed() {} + inline void DirectlyUsed() { notDirectlyUsed(); } + + // A.cc + #include "A.h" + void foo() { DirectlyUsed(); } + +then compile it and look the generated symbol with the following commands + +.. code-block:: console + + $ clang++ -std=c++20 A.cc -c -o A.o + $ nm -C A.o + 0000000000000000 W DirectlyUsed() + 0000000000000000 W notDirectlyUsed() + 0000000000000000 T foo() + +now let's check the result after using modules with the following example: + +.. code-block:: c++ + + // A.cppm + export module A; + void notDirectlyUsed() {} + export void DirectlyUsed() { notDirectlyUsed(); } + + // A.cc + #include "A.h" + void foo() { DirectlyUsed(); } + +compile it with the following commands: + +.. code-block:: console + + $ clang++ -std=c++20 A.cppm --precompile -o A.pcm + $ clang++ -std=c++20 A.cc -fprebuilt-module-path=. -c -o A.o + $ nm -C A.o + 0000000000000000 t _GLOBAL__sub_I_Use.cc + 0000000000000000 T foo() + U _ZGIW1A + U _ZW1A12DirectlyUsedv + +First we can find that there are 2 additional symbols ``_GLOBAL__sub_I_Use`` and +``_ZGIW1A``. These 2 symbols are used to initialize the current object file and +the module A. + +The interesting part here is that there is not the symbol for ``notDirectlyUsed``. +In a real world project, the number of ``notDirectlyUsed`` symbols should +usually be much more than the ``DirectlyUsed`` ones. + +So that we can reduce many symbols in the object files and so we can speedup linking +by using modules. Note that things may be better with optimizations, since the +``DirectlyUsed`` ones may be optimized out. + Interoperability with Clang Modules -----------------------------------