-
Notifications
You must be signed in to change notification settings - Fork 31
Discuss linking with libclangInterpreter.a for covering missing symbols in CppInterOpTest.js #519
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
Comments
What is being done here is the following
So emscripten by nature while building clangCppInterOp would fetch all symbols coming out of libclangInterpreter.a and propagte it to clangCppInterOp but the linker gets rid of any symbol that is not being used out of these 5 source files !
Hence it is highly probable that CppInterOpTests would require symbols being used in these source object files but that are not present in clangCppInterOp just cause these source files are not covered yet. |
Some options on what can be done
We can here itself create a test-intermediate library (naming it libtestintermediate.so for now) And we can do
So now we have a lib that can has all the symbols relevant to the test object files and not being included in clangCppInterOp and then we can use this while linking
So yeah the easier way out is basically just adding clangInterpreter in the linking step here https://github.com/compiler-research/CppInterOp/pull/483/files#diff-83065e07beb1893613b121d9407df26d6fe57ed08948d6def04986690a22ba37R43 This should be done because this keeps clangCppInterOp clean (emscripten knows what symbols should be propagated through this and we don't play with that) and CppInterOpTests.js also gets the symbols it needs. |
cc @vgvassilev @mcbarton says he's waiting for your views before applying this suggestion on his PR. This should get rid of all the undefined symbols we are concerned with. let us know what you think. |
The design of CppInterOp is that it should contain all required symbols. We need to understand why the symbols we need are not there. |
@vgvassilev @anutosh491 This is what I believe may be going on/possible solution. If you look at the remaining symbols one still exists from CppInterOp CppInterOp/lib/Interpreter/exports.ld Line 1 in a12e15b
By making use of EMSCRIPTEN_KEEPALIVE here (found by applying c++filt -n to the symbol) CppInterOp/lib/Interpreter/CppInterOp.cpp Line 3504 in 33bfa39
CppInterOps shared library was able to export the symbol without me explicitly exporting it through the linker. You'll also find the statement in the FAQs
Using the EXPORTED_FUNCTIONS flag is the Emscripten suggested way to export functions (which we cannot use since we are making a SIDE_MODULE). So in summary It could be the case that during our llvm build these functions are being inlined and removed by Emscripten. By utilising EMSCRIPTEN_KEEPALIVE on the functions we might be able to keep them alive so we won't have export all symbols manually (and no linking the interpreter library directly to the tests). For llvm 19 this would require a new patch, but we should be able to get this into llvm 20 assuming you think this solution would get merged. Let me know what you think of the solution, and I will investigate what the exact patch for llvm would be if you think the solution is good. |
Well, we might not be able to use the exported_functions, but we just need this during the link step isn't it ?
|
Looks like we need |
Yes perfect that should be enough to take care of those symbols. |
@vgvassilev @anutosh491 After using CPPINTEROP_API I am left with just the clang and llvm specific symbols. I've separated them out in the attached files Applying c++filt -n to the llvm symbols I get
and applying it to the clang symbols I get
Please look over this, and let me know if you anything stands out about the lists, and gives you an idea as to why they are not being exported by CppInterOps shared library. |
Hey, I think my approach is exactly what we want here ! We just need to link CppInterOptests target against libclangInterpreter now. P:S I've been hacking around with your branch locally and it builds pretty smoothly just like we want. You might also be interested in seeing the other reviews I gave in this regard. More than half of the tests marked as skipped now work. |
As an update, on reading your statement again , I see this
That's actually what I am pointing towards. These symbols don't necessarily need to come out of cppinterop's shared build if that's the confusion here. Why should these be exposed through libclangCppInterOp.so ? When building clangCppInterOp, we only care about these symbols coming out of these source object files
So emscripten would make sure to capture all llvm/clang based symbols being used here and strip the rest. There's nothing wrong there correct ? That's what libclangCppInterOp.so is responsible for ! But when we get to the tests, you need to have symbols out of these source files too !
And its CppInterOpTests.js that needs these but isn't not really the job of clangCppInterOp to expose them cause clangCppInterOp is not responsible for the source files from the test dir. Hence we just need to do
and we're done. If we really want to expose it through clangCppInterOp that can be done, but its not that goal here I think. Here's how you can do it if you really want to
I don't think this is called for here though :\ I am not sure expecting symbols from fileA, fileB in libXX.so when we are not even compiling them while building XX is correct while building with emscripten. Obviously anything unncessary is stripped off isn't it ? |
No. This is the opposite of what we want. We don’t want to link to libclangInterpterer. As I mentioned in a previous comment CppInterOp should be standalone. |
Hmm okay maybe I am missing something here. I've pasted a workaround to have it in cppinterop itself in my comment above (#519 (comment)) Something like that might be the only way to organically have these symbols in cppinterop's shared build and not export them forcefully. |
The tests are essentially programs built as use-cases for CppInterOp. They should not need any llvm libraries as all symbols should be provided by our library. PS: the proposed workaround is not what we want either. I still do not understand why we are debating this PR. |
Hmmm okay, I guess something is still unclear to me but that leaves us with no option but to force these symbols
So our question isn't really "why these symbols are not found by default in
Both force the symbols to stay alive rather than being stripped in the linking step Cause the symbols are only required when you run the tests and not otherwise isn't it. Best probably would be to sort of maintain the symbol list in cppinterop itself (not messing with llvm) and only do the linking when tests are enabled (obviously you see the build time for clangCppInterOp go up after the changes .... so I don't think these symbols need to be taken care of if tests are off.). |
The tests show that these symbols are probably needed by to support some of the exported api, right? That means if the tests are broken, likely client code with CppInterOp is broken. |
Yeah like there's nothing wrong exposing those symbols ( obviously needed when tests are enabled, might not be too obvious when tests are disabled) That's because, for testing any repo dependent on Hence I had no issues while running the following on my PR (cause these are not dependent on symbols coming from the source files in the test dir)
Its only when we build CppInterOpTests that we would need those symbols. Apart from then if we test xeus-cpp, clad, cppyy etc etc these symbols shouldn't play a role. But again not a big concern, can be done in both cases (was just thinking about a faster build above and if we can skip those symbols when tests are disabled) |
As I’ve said a week ago. I am not opposed to revisit this once we get more experience with the current approach. |
@vgvassilev Am I reverting the llvm patch solution I added to my automated wasm tests PR I added last night (see here for the patch https://github.com/compiler-research/CppInterOp/blob/ffb37b4e038d43eeaa87aa11fd9de32611532dc1/patches/llvm/emscripten-clang19-4-emscripten-keepalive.patch )? Although using CPPINTEROP_API are -Wl,export are similar in the sense they allow the symbols to be available by the shared library, the first approach allows the emscripten driver to process the symbols, while the second (the Wl,export method) doesn't. Regardless of what is decided I suggest we move ahead with my automated wasm tests PR as is, and make subsequent improvements in a separate PR. |
We must add |
These are the symbols in llvm and clang, so cannot have cppinterop_api applied (or at least I cannot see how I can use it). Should I revert my llvm patch, which uses EMSCRIPTEN_KEEPALIVE and go back to the -Wl,export method (taking into consideration the drawback of the latter in this comment #519 (comment))? |
I would do that and not mess with the llvm build as I stated above |
Description of bug
Currently if we see the approach taken in #483 with respect to exporting symbols.
There are 2 main places from where undefined symbols are coming out of for CppInterOpTests.js
What operating system was you using when the bug occured?
Other
What is the architechture of the cpu on your system?
Other
What did you build CppInterOp against?
Clang-repl (LLVM19)
The text was updated successfully, but these errors were encountered: