Skip to content

[lld][wasm] Clear lazyBitcodeFiles while resetting context #118440

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

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

anutosh491
Copy link
Member

Hi @sbc100

I was looking into a use case involving the link function (which got my attention to reset).

I see that lazyBitcodeFiles variable was introduced here #114327 but I don't see it being reset while destroying the context eventually. Hopefully this should be the correct way to address it.

@llvmbot
Copy link
Member

llvmbot commented Dec 3, 2024

@llvm/pr-subscribers-lld

Author: Anutosh Bhat (anutosh491)

Changes

Hi @sbc100

I was looking into a use case involving the link function (which got my attention to reset).

I see that lazyBitcodeFiles variable was introduced here #114327 but I don't see it being reset while destroying the context eventually. Hopefully this should be the correct way to address it.


Full diff: https://github.com/llvm/llvm-project/pull/118440.diff

1 Files Affected:

  • (modified) lld/wasm/Driver.cpp (+1)
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 8d01ff839ddfcf..37a0156c728f6f 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -59,6 +59,7 @@ void Ctx::reset() {
   stubFiles.clear();
   sharedFiles.clear();
   bitcodeFiles.clear();
+  lazyBitcodeFiles.clear();
   syntheticFunctions.clear();
   syntheticGlobals.clear();
   syntheticTables.clear();

@llvmbot
Copy link
Member

llvmbot commented Dec 3, 2024

@llvm/pr-subscribers-lld-wasm

Author: Anutosh Bhat (anutosh491)

Changes

Hi @sbc100

I was looking into a use case involving the link function (which got my attention to reset).

I see that lazyBitcodeFiles variable was introduced here #114327 but I don't see it being reset while destroying the context eventually. Hopefully this should be the correct way to address it.


Full diff: https://github.com/llvm/llvm-project/pull/118440.diff

1 Files Affected:

  • (modified) lld/wasm/Driver.cpp (+1)
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 8d01ff839ddfcf..37a0156c728f6f 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -59,6 +59,7 @@ void Ctx::reset() {
   stubFiles.clear();
   sharedFiles.clear();
   bitcodeFiles.clear();
+  lazyBitcodeFiles.clear();
   syntheticFunctions.clear();
   syntheticGlobals.clear();
   syntheticTables.clear();

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Do we have tests for re-using contexts?

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm % testing question

@anutosh491
Copy link
Member Author

Do we have tests for re-using contexts?

Hmmm, not sure :(
Do you think we need one ? Being new to contributing to llvm, maybe you could suggest where and what kind of test should be added, if we need one.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 3, 2024

I guess we can land this without a test, especially since #78640 also didn't have any test.

@MaskRay do you know of any tests for context reuse/reset?

@anutosh491
Copy link
Member Author

My use case of running clang-repl completely in browser technically supports my claim that context resetting works as expected.
Attaching a small screen recorded demo for the same (I should have this in jupyterlite by the weekend I think)

Screen.Recording.2024-12-04.at.11.03.06.AM.mov

@MaskRay
Copy link
Member

MaskRay commented Dec 4, 2024

I guess we can land this without a test, especially since #78640 also didn't have any test.

@MaskRay do you know of any tests for context reuse/reset?

We have basic unittests in lld/unittest/AsLibELF. We should have wasm tests as well, but it's difficult and probably unnecessary to cover just lazyBitcodeFiles.

If lld/wasm constructs Ctx and drops reset, this pitfall will be removed. https://maskray.me/blog/2024-11-17-removing-global-state-from-lld Eliminating the global ctx variable

@sbc100
Copy link
Collaborator

sbc100 commented Dec 4, 2024

I guess we can land this without a test, especially since #78640 also didn't have any test.
@MaskRay do you know of any tests for context reuse/reset?

We have basic unittests in lld/unittest/AsLibELF. We should have wasm tests as well, but it's difficult and probably unnecessary to cover just lazyBitcodeFiles.

If lld/wasm constructs Ctx and drops reset, this pitfall will be removed. https://maskray.me/blog/2024-11-17-removing-global-state-from-lld Eliminating the global ctx variable

Both of those sounds like good ideas, thank you. I don't think we need to block this change on those though.

@sbc100 sbc100 merged commit 52aff97 into llvm:main Dec 4, 2024
11 checks passed
@anutosh491
Copy link
Member Author

Hey @sbc100 @MaskRay

I just skimmed through this blog post pasted above. I think we could try the following out

If lld/wasm constructs Ctx and drops reset, this pitfall will be removed. https://maskray.me/blog/2024-11-17-removing-global-state-from-lld Eliminating the global ctx variable

Let me know if I have the green flag from your side and I'll try to address this on a separate branch.

@anutosh491 anutosh491 deleted the clear_lazyBitcodeFiles branch December 4, 2024 06:26
@anutosh491
Copy link
Member Author

I guess we can land this without a test, especially since #78640 also didn't have any test.
@MaskRay do you know of any tests for context reuse/reset?

We have basic unittests in lld/unittest/AsLibELF. We should have wasm tests as well, but it's difficult and probably unnecessary to cover just lazyBitcodeFiles.

If lld/wasm constructs Ctx and drops reset, this pitfall will be removed. https://maskray.me/blog/2024-11-17-removing-global-state-from-lld Eliminating the global ctx variable

I opened an issue to track the progress on this
#119180

Y'all could let me know your thoughts on the same and let me know if my thinking on the issue makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants