-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Limit symbols exported from proc macros #99944
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,16 +257,18 @@ fn exported_symbols_provider_local<'tcx>( | |
})); | ||
} | ||
|
||
if tcx.sess.crate_types().contains(&CrateType::Dylib) { | ||
if tcx.sess.crate_types().contains(&CrateType::Dylib) | ||
|| tcx.sess.crate_types().contains(&CrateType::ProcMacro) | ||
{ | ||
let symbol_name = metadata_symbol_name(tcx); | ||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); | ||
|
||
symbols.push(( | ||
exported_symbol, | ||
SymbolExportInfo { | ||
level: SymbolExportLevel::Rust, | ||
level: SymbolExportLevel::C, | ||
kind: SymbolExportKind::Data, | ||
used: false, | ||
used: true, | ||
Comment on lines
-260
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @michaelwoerister @wesleywiser @rust-lang/wg-llvm I'm a bit surprised we even need a symbol (and don't find it by section instead). If the symbol only exists to keep the section from being GC'd, shouldn't it be some form of unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The symbol is needed on at least macOS to prevent the section from being discarded. The exact name is unique. I think it would make sense in the future to ensure that the symbol exists when using a dylib as dependency to ensure versions don't get mixed without recompilation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, right, the SVH enforcement ideas, but is this symbol accessible to the dynamic loader at all? EDIT: moved the rest of the comment below to #73917 (comment) (click to open old version)We could even have something like this: struct LinkGuard {
deps: &'static [&'static LinkGuard],
}
extern "Rust" {
// foo[b7924b40b7ed5e7f]::{shim:LINK_GUARD#0}::<0x461e83de35f0b704f7e69b4cc741ad8eu128>
#[link_name = "_RINSCsfL95rG4I7iB_3foo10LINK_GUARDKo461e83de35f0b704f7e69b4cc741ad8e_E"]
static LINK_GUARD_DEP_FOO: LinkGuard;
// bar[acb4b2d152c0bd2e]::{shim:LINK_GUARD#0}::<0xf8fc0fadc6a6e727eef4b916531abfe9u128>
#[link_name = "_RINSCsePjaApBJGQA_3bar10LINK_GUARDKof8fc0fadc6a6e727eef4b916531abfe9_E"]
static LINK_GUARD_DEP_BAR: LinkGuard;
}
// my_crate[78009e3fbfa2f6af]::{shim:LINK_GUARD#0}::<0xe538955c5950b59a598304a1e701c9fbu128>
#[export_name = "_RINSCsaiLK1vfX74x_8my_crate10LINK_GUARDKoe538955c5950b59a598304a1e701c9fb_E"]
pub static LINK_GUARD: LinkGuard {
deps: unsafe { &[
&LINK_GUARD_DEP_FOO,
&LINK_GUARD_DEP_BAR,
] }
}; (and then use global constructors to ensure it gets kept in - potentially even doing some redundant SVH checking at runtime too...? or something more cursed where it's "activating" something that would be broken otherwise. but that's too much) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. cc #73917 |
||
}, | ||
)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate an_rlib; | ||
|
||
// This should not be exported | ||
#[no_mangle] | ||
extern "C" fn public_c_function_from_cdylib() { | ||
an_rlib::public_c_function_from_rlib(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.