Repository navigation
Rewriting/simplifying DynamicLibrary in C. - #5221
Conversation
207a141 to
33c45a2
Compare
c5b070e to
c45c361
Compare
|
(this may break windows pdb symbol attachment to executables - but I'm likely going to be deprecating that path soon anyway so I'm fine with that - everyone but me is using linux anyway) |
| // Query the 'TMPDIR' environment variable to allow users to override the | ||
| // path. | ||
| const char* tmpdir = getenv("TMPDIR"); |
There was a problem hiding this comment.
Can we use TEST_TMPDIR also?
Or, more generally... @GMNGeoffrey what would you like to see here, relating to #5147 ?
The specific concern is:
When I sshed into phones in our lab, I see a huge amount of files with dylib_executableNNNNNN directly under /data/local/tmp. They should be generated into TEST_TMPDIR so it can be deleted after running the tests?
There was a problem hiding this comment.
Nope - something like TEST_TMPDIR does not belong in core code - that's for test outputs, where these are not test outputs. If the test env wants to override the temp path it can do so via one of the system temp env vars.
There was a problem hiding this comment.
Figured that would be your answer :P
@GMNGeoffrey want to handle setting one of the supported env vars through the test runners as part of #5147?
There was a problem hiding this comment.
Yes, using TEST_TMPDIR to set the system temp var seems like the right approach. Core code shouldn't have to know about being executed by a test. However, I don't want to do that right this instant and I suspect this change will mean that we have a bunch of temp files getting written all over the place and not getting cleaned up. Can we make sure that doesn't happen before submitting this? I believe when I initially added this because without it tests failed if you ran them twice (#731). Not sure if this will also cause a regression there (probably depends on whether those tests still exist).
There was a problem hiding this comment.
"all over the place" will still be the system temp directory though? That is easy enough to clean (by the OS or us manually)
There was a problem hiding this comment.
Yeah but filling up the temp directory on everyone's machine isn't very nice, not respecting the TEST_TMPDIR breaks the contract of tests run on Bazel (would cause issues?), and I'm concerned that it will cause non-hermetic behavior of tests.
There was a problem hiding this comment.
I did some shuffling and was able to match the FILE_FLAG_DELETE_ON_CLOSE behavior I have on Windows by just unlinking the temp file after dlopening it on linux. This means that the only time a temp file will remain in the temp path is if the test dies (and that means segfault - not gracefully fails) while loading the library - which is just about never. I'm fine with a few files per month at most accumulating on the CI - and we should be running these things in docker images with transient tmp dirs anyway so I don't think that would even happen.
I think the metapoint here is that the world is not defined by the bazel test runner. If bazel wants to have non-test temp files written to a certain path it should set the platform environment variables for the temp path. Go already does this so maybe porting that to the cc rules would be useful if one really cared (edit: looks like that got reverted, with --sandbox_tmpfs_path=/tmp being recommended instead). TEST_TMPDIR also causes issues for usability - prior to this change one couldn't run the file_io or dynamic_library tests unless they were run under the bazel test runner or through our crazy 4-layer cmake shims. All test binaries should be runnable without needing any environment setup.
I prefer having the system temp path used for this particular case (again, non-test temp files) as having the usage be hermetic is reducing coverage of a critical use case: the code as anyone will be using it goes to the system temp path. If two concurrently running tests can have issues by doing that then it means two concurrently running real applications would as well - and we should be catching that. For example #731 linked above is terrifying: if a test can't run with existing non-test temp files, then a real app can't either. I don't want the first report of issues to be real users having trouble with their temp dirs. In other words, having the system temp path used should never flake and if it does we need to fix that vs. working around it in a way that is not representative of real usage.
There was a problem hiding this comment.
I agree with almost everything you're saying here. We shouldn't need to have prod code execute a different path if it's on a test. But if some part of our project is doing something bad that we don't like, we should fix that first, not take a scorched earth approach of "this is the way things should be so I'll act like this is the way things are". #5147 should hopefully address these concerns, but I'm prioritizing it against many other things and I haven't gotten to it yet.
With regards to #731, the particular issue is that the test is (was?) asserting that the file it's trying to create isn't already there so that when it checks the contents of that file it's actually testing what it thinks it's testing. This would not be an issue with real applications. The particular approach of having a wrapper for our tests under ctest was one of several approaches I considered and ultimately one you approved. It's totally fine that we both now think that wasn't the best approach, but again let's not introduce instability into our project because of that.
Having the tmp files get automatically cleaned up seems great, thank you (and I agree that there's not much we can do if the process just dies. Polluting the tmp dir is about the best case for that).
There was a problem hiding this comment.
Totally makes sense - thanks for pushing back a bit as it led me down the path of fixing it in a much nicer way :)
There was a problem hiding this comment.
Thank you for doing that :-)
This allowed for a lot of file IO code to go away - there was needless abstraction here as there was only a single user of a lot of these things that was already platform-specialized. Progress on #4369 and #3848. Fixes #4642. Unblocks #3845, which can now be added cleanly. # Conflicts: # iree/hal/local/loaders/legacy_library_loader.c
c45c361 to
960d413
Compare
This allowed for a lot of file IO code to go away - there was needless
abstraction here as there was only a single user of a lot of these things
that was already platform-specialized.
Progress on #4369 and #3848.
Fixes #4642.
Unblocks #3845, which can now be added cleanly.