(external_symbols)
| 151 | |
| 152 | |
| 153 | def lld_flags_for_executable(external_symbols): |
| 154 | cmd = [] |
| 155 | if external_symbols: |
| 156 | if settings.INCLUDE_FULL_LIBRARY: |
| 157 | # When INCLUDE_FULL_LIBRARY is set try to export every possible |
| 158 | # native dependency of a JS function. |
| 159 | all_deps = set() |
| 160 | for deps in external_symbols.values(): |
| 161 | for dep in deps: |
| 162 | if dep not in all_deps: |
| 163 | cmd.append('--export-if-defined=' + dep) |
| 164 | all_deps.add(dep) |
| 165 | stub = create_stub_object(external_symbols) |
| 166 | cmd.append(stub) |
| 167 | |
| 168 | if settings.FAKE_DYLIBS or (not settings.MAIN_MODULE and not settings.SIDE_MODULE): |
| 169 | cmd.append('-Bstatic') |
| 170 | else: |
| 171 | # wasm-ld still defaults to static linking by default. If that ever changes, we can remove this line. |
| 172 | cmd.append('-Bdynamic') |
| 173 | |
| 174 | if not settings.ERROR_ON_UNDEFINED_SYMBOLS: |
| 175 | cmd.append('--import-undefined') |
| 176 | |
| 177 | if settings.IMPORTED_MEMORY: |
| 178 | cmd.append('--import-memory') |
| 179 | |
| 180 | if settings.SHARED_MEMORY: |
| 181 | cmd.append('--shared-memory') |
| 182 | |
| 183 | # wasm-ld can strip debug info for us. this strips both the Names |
| 184 | # section and DWARF, so we can only use it when we don't need any of |
| 185 | # those things. |
| 186 | if (not settings.GENERATE_DWARF and |
| 187 | not settings.EMIT_SYMBOL_MAP and |
| 188 | not settings.GENERATE_SOURCE_MAP and |
| 189 | not settings.EMIT_NAME_SECTION and |
| 190 | not settings.ASYNCIFY): |
| 191 | cmd.append('--strip-debug') |
| 192 | |
| 193 | if settings.LTO and not settings.EXIT_RUNTIME: |
| 194 | # The WebAssembly backend can generate new references to `__cxa_atexit` at |
| 195 | # LTO time. This `-u` flag forces the `__cxa_atexit` symbol to be |
| 196 | # included at LTO time. For other such symbols we exclude them from LTO |
| 197 | # and always build them as normal object files, but that would inhibit the |
| 198 | # LowerGlobalDtors optimization which allows destructors to be completely |
| 199 | # removed when __cxa_atexit is a no-op. |
| 200 | cmd.append('-u__cxa_atexit') |
| 201 | |
| 202 | c_exports = [e for e in settings.EXPORTED_FUNCTIONS if is_c_symbol(e)] |
| 203 | # Strip the leading underscores |
| 204 | c_exports = [demangle_c_symbol_name(e) for e in c_exports] |
| 205 | # Filter out symbols external/JS symbols |
| 206 | c_exports = [e for e in c_exports if e not in external_symbols] |
| 207 | c_exports += settings.REQUIRED_EXPORTS |
| 208 | if settings.MAIN_MODULE: |
| 209 | c_exports += side_module_external_deps(external_symbols) |
| 210 | for export in c_exports: |
no test coverage detected