-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add tools/symbol-check.py
#1135
Conversation
I think checking that not too many symbols are exported could be interesting for us. Checking libraries not so much, we anyway don't have dependencies, so all linkage should be introduced by the compiler. Or what do you think? |
02d0bce
to
8ae0d51
Compare
Cleaned up, improved, undrafted. |
contrib/symbol-check.py
contrib/symbol-check.py
Now that I think about this, I wonder why that would be necessary. I've never seen any libraries doing this. I think in our case it could be helpful to prevent mistakes where we forget to make an internal function But on the other hand, it's yet another file that needs to be maintained. In particular the list of function must be kept in sync with the include files. This violates the DRY principle. Do you think the list could be generated on-the-fly, maybe just using some clever Weak Concept ACK because it has potential to prevent mistakes where we forget |
Because quality matters :)
bitcoin/bitcoin#25020 (comment)
The Other use cases:
👍 |
That would be neat. |
8ae0d51
to
766964f
Compare
This fails for me with
|
What system/compiler on? UPD. I assume, it is a clang... |
llibsecp256k1, unlike Bitcoin Core, has no affordances to make sure the produced builds are compatible with certain, specific, version of glibc on the user's system. I think the max version checks should just be dropped here. |
766964f
to
6a97f72
Compare
Ok yes, I was wondering what the purpose of the max version is... :) |
Bikeshedding: I believe I know, Bitcoin Core uses a different definition. My point is that the current contents of the folder fit the definition on stackexchange, so we shouldn't mix up the two. I think |
6a97f72
to
6813bee
Compare
It's not clear to me that adding this script is worth it (especially as it continue to shrink). We seem to be adding a new language dependency, and third party library dependency, to run grep + objdump? I might have thought a bash script would be a better fit for libsecp256k1, especially since this is basically just a sanity check that will live in the CI (as the API rarely changes, and I don't think anyone will run this locally)? Is there a reason this doesn't support macOS shared libs? LIEF supports them as far as I'm aware, and it seems odd to add a platform agnostic binary parser as a dependency, and then not support all libraries that are being built. |
I think @hebasto convinced me above that this tool has >0 benefit, but indeed, it introduces a maintenance burden and doing the same with objdump instead of Python+LIEF might reduce this burden (but I don't know -- for example I don't know if objdump exists on macOS). Note that we already have python as a CI dependency for our sage scripts. |
It does, but at the moment, I guess that doesn't matter, given the script doesn't check macOS libs. Would you expect an API issue to be present in one shared library, but not all others? We might be able to get away with just sanity checking an ELF lib, as I assume if there's an issue that you'd want to catch, present there, it'll be present everywhere. |
6813bee
to
6e6aa49
Compare
Updated to support macOS libs. LIEF v0.13.0 (not released yet) is required. |
Looks like you could do something like this to check that the expected exports are present? diff --git a/tools/symbol-check.py b/tools/symbol-check.py
index 8206b95..7237158 100755
--- a/tools/symbol-check.py
+++ b/tools/symbol-check.py
@@ -59,12 +59,10 @@ def check_MACHO_exported_functions(library, expected_exports) -> bool:
ok: bool = True
macho_lib: lief.MACHO.Binary = library.concrete
- for function in macho_lib.exported_functions:
- name: str = function.name[1:]
- if name in expected_exports:
- continue
- print(f'{filename}: export of function {name} not expected')
- ok = False
+ for name in expected_exports:
+ if not macho_lib.has_symbol(name):
+ print(f'{filename}: export of function {name} missing')
+ ok = False |
6e6aa49
to
cc7933d
Compare
cc7933d
to
71ceda7
Compare
We've discussed this at length in the meeting today, see https://gnusha.org/secp256k1/2022-12-19.log for details. Conclusion: |
As the suggested approach changes the check logic, the script fails if any of modules are disabled. For example, the "recovery" module is disabled by default, and script ends with:
Making this PR a draft for now. |
The new
tools/symbol-check.py
aims to ensure that only expected symbols are exported in thesecp256k1
shared library.The script itself stems from Bitcoin Core's
contrib/devtools/symbol-check.py
and bitcoin/bitcoin#25020. It uses the LIEF library.Useful to ensure that build system changes (including #1113) will not introduce any unexpected regressions.