Hiding rust_eh_personality symbol in cdylib

I'm creating a cdylib that is intendend to be LD_PRELOADed. As such, I want strong control over exported symbols: every extra symbol has the potential to break something.

Rust provides its own version script to the linker, which includes rust_eh_personality as a public symbol. I can:

  1. Set panics to abort, apparently, but I am considering handling them so I can making my library minimize damage.
  2. Add a version script of my own, which I'm doing—but at least with LLD, that doesn't override the previous one, it's just additive, and rustc already adds a version script of its own with things it thinks should be public. Which means I can add more public symbols, but I can't make rust_eh_personality private via version script.

Is there a way I can either tell rustc to not set a version script of its own (it looks like it's somehow tied to compilation platform, rather config options?), or otherwise have more control over symbol visibility?

And, just figured it out: if my extra version script explicitly calls it out as local, rather than relying on *, it gets set as private. So my version script looks like this:

1 Like

If anyone finds this in the future: note that different linkers work differently given multiple version scripts. GNU ld blows up, GNU gold works (with new enough version, and I'm not sure how it behaves in this particular situation), LLVM lld works and does the above.


I wonder if anything breaks if rust_eh_personality is marked as #[rustc_std_internal_symbol]. That will prevent exporting it from cdylib's.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.