Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deps_info system and the running of llvm-nm on input files. NFC #18905

Merged
merged 1 commit into from
Apr 18, 2023

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 5, 2023

This uses a new "stub library" construct to tell the linker (https://reviews.llvm.org/D145308) not only about the existence of the JS library symbols but the native symbols on which they depend (a.k.a reverse dependencies).

This allows us to completely remove deps_info.py in favor of just using normal __deps entries in the library files. It also means we no longer need to run llvm-nm on the linker inputs to discover the symbols they use.

Fixes: #18875

sbc100 added a commit that referenced this pull request Mar 5, 2023
Split out from #18905, which completely removes llvm_nm_multiple.
sbc100 added a commit that referenced this pull request Mar 5, 2023
Also use the `weak` macros from musl's internal features.h

Split out from #18905
sbc100 added a commit that referenced this pull request Mar 6, 2023
Split out from #18905, which completely removes llvm_nm_multiple.
sbc100 added a commit that referenced this pull request Mar 6, 2023
Also use the `weak` macros from musl's internal features.h

Split out from #18905
sbc100 added a commit that referenced this pull request Mar 6, 2023
Split out from #18905, which completely removes llvm_nm_multiple.
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
Also use the `weak` macros from musl's internal features.h

Split out from emscripten-core#18905
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
Also use the `weak` macros from musl's internal features.h

Split out from emscripten-core#18905
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
@sbc100 sbc100 force-pushed the use_stub_object branch 2 times, most recently from 8147f9b to e7b2986 Compare March 24, 2023 18:49
@sbc100 sbc100 changed the title [WIP] Remove deps_info system and and the running of llvm-nm on input files. NFC Remove deps_info system and and the running of llvm-nm on input files. NFC Mar 24, 2023
@sbc100 sbc100 force-pushed the use_stub_object branch 2 times, most recently from 99a521d to 194e399 Compare April 3, 2023 04:45
@sbc100 sbc100 requested a review from dschuff April 3, 2023 05:01
@sbc100 sbc100 changed the title Remove deps_info system and and the running of llvm-nm on input files. NFC Remove deps_info system and the running of llvm-nm on input files. NFC Apr 3, 2023
@sbc100 sbc100 force-pushed the use_stub_object branch 4 times, most recently from 0d552d5 to 1192eb0 Compare April 7, 2023 18:40
@sbc100 sbc100 force-pushed the use_stub_object branch 3 times, most recently from 67c9142 to a1cfdc7 Compare April 11, 2023 17:48
@sbc100 sbc100 requested review from kripken and juj April 11, 2023 19:55
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What impact does this have on link times?

emcc.py Outdated Show resolved Hide resolved
src/jsifier.js Show resolved Hide resolved
src/library.js Outdated Show resolved Hide resolved
test/other/metadce/test_metadce_cxx_ctors1.jssize Outdated Show resolved Hide resolved
test/test_other.py Outdated Show resolved Hide resolved
tools/system_libs.py Outdated Show resolved Hide resolved
tools/system_libs.py Outdated Show resolved Hide resolved
sbc100 added a commit to llvm/llvm-project that referenced this pull request Apr 14, 2023
…cies

This actually simplifies the code by performs a pre-pass of the stub
objects prior to LTO.

This should be the final change needed before we can make the switch
on the emscripten side: emscripten-core/emscripten#18905

Differential Revision: https://reviews.llvm.org/D148287
@sbc100 sbc100 force-pushed the use_stub_object branch 3 times, most recently from 133cdf6 to 1d0b596 Compare April 14, 2023 21:30
@sbc100 sbc100 requested a review from kripken April 14, 2023 23:42
emscripten.py Show resolved Hide resolved
src/jsifier.js Outdated Show resolved Hide resolved
emscripten.py Show resolved Hide resolved
emcc.py Show resolved Hide resolved
src/library_exceptions.js Show resolved Hide resolved
tools/system_libs.py Outdated Show resolved Hide resolved
tools/system_libs.py Outdated Show resolved Hide resolved
tools/system_libs.py Outdated Show resolved Hide resolved
tools/system_libs.py Outdated Show resolved Hide resolved
if basename in {'vmlock.o'}:
return 'AAA_' + basename
else:
return basename
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So IIUC, __vm_wait is defined in vmlock properly, and in a weak form by mmap. If mmap appears first then the weak form is linked in. It will be overwritten by the non-weak vmlock version later, so the code will work, but meanwhile it pulled in all of the mmap file, which adds some overhead. Is that right?

Is there no linker option to make them look forward for a non-weak version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats exactly right yes. I confirmed this behaviour using native gcc and clang too. The first symbol that is found will be used. Only later when the object file containing the strong definition is included for some other reason will the strong definition overwrite the weak one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid this code then by splitting up mmap.c into two files? Then mmap__vm_wait would just contain the __vm_wait for mmap, and linking it in wouldn't bring in all of mmap?

Copy link
Collaborator Author

@sbc100 sbc100 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there might be another way to do it such as the one you suggest. But mmap.c is an upstream musl file so splitting it up for this reason seem hacky and harder to maintain over time. This hack doesn't seem any worse to me.

Also, I think over time we might find other files to add to this list for similar reasons since musl makes quick heavy use of weak linking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, sgtm.

@sbc100
Copy link
Collaborator Author

sbc100 commented Apr 15, 2023

The timing results for binaryen linked with -O0 and -sWASM_BIGINT (to avoid wasm-opt and therefore show the greatest proportional gains):

Before:

0m1.661s                                                                            
0m1.748s                                                                            
0m1.644s                                                                            
0m1.700s 

After:

0m1.349s                                                                                       
0m1.341s                                                                            
0m1.399s                                                                            
0m1.340s   

Thats an average of 1.688 and 1.357 which is a speedup of 20%!

@kripken
Copy link
Member

kripken commented Apr 17, 2023

Nice speedup!

emscripten.py Outdated Show resolved Hide resolved
emscripten.py Show resolved Hide resolved
if basename in {'vmlock.o'}:
return 'AAA_' + basename
else:
return basename
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid this code then by splitting up mmap.c into two files? Then mmap__vm_wait would just contain the __vm_wait for mmap, and linking it in wouldn't bring in all of mmap?

@sbc100
Copy link
Collaborator Author

sbc100 commented Apr 17, 2023

Added ChangeLog entry.

@sbc100 sbc100 force-pushed the use_stub_object branch 2 times, most recently from a4fb164 to 3ebaf30 Compare April 18, 2023 00:27
sbc100 added a commit that referenced this pull request Apr 18, 2023
… NFC

This uses a new "stub object" construct to tell the linker (wasm-ld)
not only about the existence of the JS library symbols but the native
symbols on which they depend (a.k.a reverse dependencies).

This allows us to completely remove deps_info.py in favor of just using
normal `__deps` entries in the library files.  It also means we no
longer need to run `llvm-nm` on the linker inputs to discover the
symbols they use.

Depends on: https://reviews.llvm.org/D145308

Fixes: #18875
@sbc100 sbc100 merged commit 1e7b78f into main Apr 18, 2023
1 of 2 checks passed
@sbc100 sbc100 deleted the use_stub_object branch April 18, 2023 01:42
flemairen6 pushed a commit to Xilinx/llvm-project that referenced this pull request May 10, 2023
…cies

This actually simplifies the code by performs a pre-pass of the stub
objects prior to LTO.

This should be the final change needed before we can make the switch
on the emscripten side: emscripten-core/emscripten#18905

Differential Revision: https://reviews.llvm.org/D148287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completely remove REVERSE_DEPS / deps_info using new wasm-ld feature
3 participants