-
Notifications
You must be signed in to change notification settings - Fork 171
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 symbols to library #159
Conversation
Please complete the commit message correctly as pointed out by the compliance checks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the commit message to meet the checkpatch requirements and to explain why these changes have been made.
As I see it, this pull request has two parts.
The first part brings the code into the 21st century, by replacing macros with inline functions. This is obviously a good idea.
The second part is what needs explanation. By making a bunch of functions globally visible, it changes the existing API and could cause problems for existing code. Please explain why this change is useful.
I'll refactor the commits shortly to meet the compiance checks. Let me explain the rational here. I use libmetal in a FFI environment (linking from rust). Functions defined as #defines, or as static inlines in headers are useless in this context. The compiled library simply does not contain these symbols. So, this PR does 2 things
I'm certain there is further scope for refactorings of the second kind. These are just the functions I've personally hit linkage problems with. |
I have never developed in a Rust environment so I would like to beter understand your issue.
|
I compile a vanilla libmetal library via a c toolchain. I then link to its symbols from rust. There are tools to automate the discovery of these symbols by parsing headers, but fundamentally thats what's happening. This is the same for all the FFI's i've ever used (python, rust, Haskell). Code in C headers are not compiled by other languages compilers (unsurprisingly).
To do this, Rust compilers would have to compile C. Headers may be arbitrarily complex.
If you accept that it'd be helpful for a library to actually contain the symbols (I'm very aware of header only libraries, I've worked a lot in C++), you've 2 choices:
or (and this is what i've done in this PR)
|
Thanks for your description of the alternatives, that's what I have in mind too.
@edmooring: any opinion on this? |
Lots of opinions, but no concrete answer at this point. First, making libmetal friendly to Foreign Function Interface libraries in other languages is highly desirable. Right now, it's mostly for Linux; but I'm seeing some interest in Rust on the more constrained Cortex-R and Cortex-M processors as well. Second, the effect of this effort (regardless of the way in which we do it) is to add a bunch of libmetal-related symbols to those already visible to the linker at program scope. I'm not sure how much practical effect this has. Third, the 'static inline' idiom in C libraries is well-established, and both compilers and coders know what it means. It is used as a compile-time indirection mechanism. Because it is explicit, and it can be shown that compilers obey it, it can be relied on for safety and security evaluations of products that use libmetal. Fourth, I'm concerned about the effects on the more resource-constrained environments that libmetal runs in (some of them have a total of 64K memory available),. Inlining reduces the requirements somewhat. Does anybody have some real data? |
Thanks @edmooring The answer seems not simple...
So i propose to go ahead with option 1 and check effect on few projects (Zephyr, Linux, baremetal) and few compilers (gcc, IAR, armcc) to have real data. @ollie-etl: Please could you update the PR in this way ( without c09c50b commit which breaks the API) |
Hi @ollie-etl |
I've just realised this is unresolved. I do plan on returning and fixing this up. As ever, there are not enough hours in the day. |
In such environments, would you not be compiling binaries via a static libraries, and either performing link time optimization, and stripping your binary pretty ruthlessly? |
Hello @ollie-etl
I have not analyzed the code in detail, but the distribution of the footprint shows that some functions that were previously forced inline are no longer inline. |
This pull request has been marked as a stale pull request because it has been open (more than) 45 days with no activity. |
Work to address #156
In addition to #defines, static inline functions have no symbols in compiled library. This PR also addresses the more obvious candidates here.