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

Add custom prefix to autogenerated C functions #268

Merged
merged 1 commit into from
Mar 20, 2025
Merged

Add custom prefix to autogenerated C functions #268

merged 1 commit into from
Mar 20, 2025

Conversation

qmuntal
Copy link
Collaborator

@qmuntal qmuntal commented Mar 20, 2025

In #259 I refactored the C bindings to autogenerate them. While doing that, I removed the go_openssl prefix from them, leaving the C function names with the same name as defined in the OpenSSL headers.

The problem is that when this Go module is compiled as a shared library, dynamically loaded in another module, and that module ends up dynamically loading the real OpenSSL (which is the case of all the OpenSSL providers) then the OpenSSL functions that we defined are loaded twice, from us and from OpenSSL, causing undefined behavior.

To avoid this issue, we better add a custom prefix to the autogenerated C functions. This PR does that by applying the following changes:

  • Autogenerated C functions now are prefixed with _mkcgo_.
  • All autogenerated C functions are now declared in zossl.h, not just the one needing an error wrapper, as shims.h no longer contains real function names (unless OpenSSL is dynamically loaded).
  • Replaced shims.h for zoosl.h in those fails that were including it.
  • Bonus: We were previously generating two wrapper functions for those C functions that required error handling, but only the one that did the error handling was really called from Go. I've removed the non-error variant.

@qmuntal qmuntal marked this pull request as ready for review March 20, 2025 14:53
return "_mkcgo_err_" + fn.CName
// fnGoName returns the Go function name for function f.
func fnGoName(fn *mkcgo.Func) string {
// TODO: use a prefix that is not OpenSSL specific.
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO, open an issue or fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in #269 😄

@qmuntal qmuntal merged commit 345655e into v2 Mar 20, 2025
50 checks passed
@qmuntal qmuntal deleted the mkcgoprefix branch March 20, 2025 18:36
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.

3 participants