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 a way to generate a list of symbols for dynamic linkage #916
base: master
Are you sure you want to change the base?
Conversation
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.
Nice - I might need exactly something like this in a project of mine in the next few months.
in a format that the linker (ld) can understand.
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?
3bb7400
to
f4cd4a1
Compare
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. |
f4cd4a1
to
6fc7d2b
Compare
rebased |
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.
Thanks, this looks good. Probably needs a rebase (can get to it if you can't) and I have one suggestion to avoid a couple intermediary allocations. But lmk if it's unreasonable.
@@ -131,6 +131,28 @@ impl Bindings { | |||
fields | |||
} | |||
|
|||
/// Lists the exported symbols that can be dynamically linked, i.e. globals and functions. | |||
pub fn dynamic_symbols_names(&self) -> Vec<String> { |
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.
Probably:
fn dynamic_symbols_names(&self) -> impl Iterator<Item = &str>
And just chain the two things:
self.functions.iter().map(|f| f.path().name())
.chain(self.globals.iter().map(|g| g.export_name()))
std::fs::create_dir_all(dir).unwrap(); | ||
} | ||
let mut symfile = File::create(symfile_path).unwrap(); | ||
write!(&mut symfile, "{{\n{};\n}};\n", symbols.join(";\n")).expect("Writing symbol file failed"); |
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.
I'd probably write this iteratively using the above function rather than storing all the file contents in memory, but it's probably not a huge deal.
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 inBindings
. 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
.