mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.29k stars 294 forks source link

Add a way to generate a list of symbols for dynamic linkage #916

Open TheElectronWill opened 6 months ago

TheElectronWill commented 6 months ago

This resolves #907 by adding the ability to generate the list of exportable symbols (i.e. functions and globals), in a format that the linker (ld) can understand. Like depfile, this new feature is available both as a CLI option (--symfile) and as a method in Bindings. Therefore, it's easy to use it in a build script.

Most of the new files are tests on the output of the new option --symfile.

TheElectronWill commented 6 months ago

Which linkers specifically support this option? Is the --dynamic-list option of the gold linker compatible with the format, or did you only test with ldd? Is there any documentation on the exact format?

The manual doesn't clearly explain the format. Gnu linker's manual reads "The format of the dynamic list is the same as the version node without scope and node name. See VERSION", and that "version" thing is introduced here.

I would expect at least GNU ld, lld and gold to work with that (I have only tested ld for the moment, but I'm confident that it works with lld too since it's been implemented with the same format in 2016). It would be weird for a linker to offer the same option but with a different format IMO.

TheElectronWill commented 4 months ago

rebased