1
Fork 0

Rollup merge of #130005 - davidlattimore:protected-vis-flag, r=Urgau

Replace -Z default-hidden-visibility with -Z default-visibility

Issue #105518
This commit is contained in:
Matthias Krüger 2024-10-01 21:09:18 +02:00 committed by GitHub
commit 389a399a50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 208 additions and 81 deletions

View file

@ -830,6 +830,46 @@ impl RelroLevel {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
pub enum SymbolVisibility {
Hidden,
Protected,
Interposable,
}
impl SymbolVisibility {
pub fn desc(&self) -> &str {
match *self {
SymbolVisibility::Hidden => "hidden",
SymbolVisibility::Protected => "protected",
SymbolVisibility::Interposable => "interposable",
}
}
}
impl FromStr for SymbolVisibility {
type Err = ();
fn from_str(s: &str) -> Result<SymbolVisibility, ()> {
match s {
"hidden" => Ok(SymbolVisibility::Hidden),
"protected" => Ok(SymbolVisibility::Protected),
"interposable" => Ok(SymbolVisibility::Interposable),
_ => Err(()),
}
}
}
impl ToJson for SymbolVisibility {
fn to_json(&self) -> Json {
match *self {
SymbolVisibility::Hidden => "hidden".to_json(),
SymbolVisibility::Protected => "protected".to_json(),
SymbolVisibility::Interposable => "interposable".to_json(),
}
}
}
impl FromStr for RelroLevel {
type Err = ();
@ -2326,13 +2366,12 @@ pub struct TargetOptions {
/// for this target unconditionally.
pub no_builtins: bool,
/// The default visibility for symbols in this target should be "hidden"
/// rather than "default".
/// The default visibility for symbols in this target.
///
/// This value typically shouldn't be accessed directly, but through
/// the `rustc_session::Session::default_hidden_visibility` method, which
/// allows `rustc` users to override this setting using cmdline flags.
pub default_hidden_visibility: bool,
/// This value typically shouldn't be accessed directly, but through the
/// `rustc_session::Session::default_visibility` method, which allows `rustc` users to override
/// this setting using cmdline flags.
pub default_visibility: Option<SymbolVisibility>,
/// Whether a .debug_gdb_scripts section will be added to the output object file
pub emit_debug_gdb_scripts: bool,
@ -2623,7 +2662,7 @@ impl Default for TargetOptions {
requires_lto: false,
singlethread: false,
no_builtins: false,
default_hidden_visibility: false,
default_visibility: None,
emit_debug_gdb_scripts: true,
requires_uwtable: false,
default_uwtable: false,
@ -2963,6 +3002,18 @@ impl Target {
Some(Ok(()))
})).unwrap_or(Ok(()))
} );
($key_name:ident, Option<SymbolVisibility>) => ( {
let name = (stringify!($key_name)).replace("_", "-");
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
match s.parse::<SymbolVisibility>() {
Ok(level) => base.$key_name = Some(level),
_ => return Some(Err(format!("'{}' is not a valid value for \
symbol-visibility. Use 'hidden', 'protected, or 'interposable'.",
s))),
}
Some(Ok(()))
})).unwrap_or(Ok(()))
} );
($key_name:ident, DebuginfoKind) => ( {
let name = (stringify!($key_name)).replace("_", "-");
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
@ -3353,7 +3404,7 @@ impl Target {
key!(requires_lto, bool);
key!(singlethread, bool);
key!(no_builtins, bool);
key!(default_hidden_visibility, bool);
key!(default_visibility, Option<SymbolVisibility>)?;
key!(emit_debug_gdb_scripts, bool);
key!(requires_uwtable, bool);
key!(default_uwtable, bool);
@ -3633,7 +3684,7 @@ impl ToJson for Target {
target_option_val!(requires_lto);
target_option_val!(singlethread);
target_option_val!(no_builtins);
target_option_val!(default_hidden_visibility);
target_option_val!(default_visibility);
target_option_val!(emit_debug_gdb_scripts);
target_option_val!(requires_uwtable);
target_option_val!(default_uwtable);