Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for the `linkage` feature #29603
Comments
aturon
added
T-lang
B-unstable
labels
Nov 5, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Currently this translates to the various linkage models of LLVM, for example the values of the attribute can be: match name {
"appending" => Some(llvm::AppendingLinkage),
"available_externally" => Some(llvm::AvailableExternallyLinkage),
"common" => Some(llvm::CommonLinkage),
"extern_weak" => Some(llvm::ExternalWeakLinkage),
"external" => Some(llvm::ExternalLinkage),
"internal" => Some(llvm::InternalLinkage),
"linkonce" => Some(llvm::LinkOnceAnyLinkage),
"linkonce_odr" => Some(llvm::LinkOnceODRLinkage),
"private" => Some(llvm::PrivateLinkage),
"weak" => Some(llvm::WeakAnyLinkage),
"weak_odr" => Some(llvm::WeakODRLinkage),
_ => None,
} Some worries about this are:
That being said, it's the only way to do weak symbols on Linux and it's also convenient for exporting a known symbol without worrying about privacy on the Rust side of things. I would personally want to reduce the set of accepted linkage types and then state "well of course linkage is platform-specific!" |
This comment has been minimized.
This comment has been minimized.
|
cc #29629 |
This comment has been minimized.
This comment has been minimized.
|
This feature is fundamentally broken. Consider the following code: static unsigned long B = 0;
unsigned long *A = &B;
void f(void) { }#![feature(linkage)]
#[link_name = "c_part"]
extern {
#[linkage = "extern_weak"] static A: *const usize;
fn f();
}
fn main() {
unsafe {
f();
println!("{:x} @ {:x} @ {:p}", *(*A as *const usize), *A, A);
}
}Which prints |
This comment has been minimized.
This comment has been minimized.
|
This attribute is also used incorrectly here. |
mattico
referenced this issue
May 31, 2016
Closed
Panic in LLVM when using #[linkage] even with supported targets #33992
nrc
added
the
T-tools
label
Aug 17, 2016
Mark-Simulacrum
added
T-dev-tools
and removed
T-tools
labels
May 24, 2017
This comment has been minimized.
This comment has been minimized.
|
#18804 needs to be resolved before stabilization. |
Mark-Simulacrum
removed
the
T-dev-tools
label
Jun 1, 2017
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I think we should at least work on stabilising the To give an example of a use-case for That being said, // crate older version
#[linkage="weak"]
static mut FOO: u32 = !0;// crate newer version
#[linkage="weak"]
static mut FOO: char = 'a';when linked together, all uses of |
This comment has been minimized.
This comment has been minimized.
|
extern_weak is broken in such a dubious way that even though I pointed out two years ago that it was being used incorrectly in the stdlib, the bug still hasn't been fixed.
gcc and clang handle this attribute correctly. PS: The address of __dso_handle isn't actually too significant in __cxa_thread_atexit_impl and &__dso_handle is only a few bytes off. PSS: Wow, looks like I already explained this above (also two years ago). Maybe the NSA is trying to keep this potential remote code execution unfixed. |
This comment has been minimized.
This comment has been minimized.
|
Ping @alexcrichton @nagisa what's the status here? Is there a bug here that can be solved / mentored? |
This comment has been minimized.
This comment has been minimized.
|
@cramertj I personally consider this a perma-unstable issue for now. In general symbol visibility and ABIs are something that historically rustc hasn't done much to specify and has had a lot of freedom over. We relatively regularly tweak ABIs, symbol names, etc. There's a very thin layer at the end (like a C ABI) which is pretty stable but even that gets sketchy sometimes ( I think we've benefitted quite greatly from the symbol visibility flexibility we've had historically in terms of compiler refactorings and heading off regressions. It's hard to introduce a regression when you can't rely on the feature in the first place! Along those lines I think there's definitely some select use cases where using something like (plus that and the whole |
This comment has been minimized.
This comment has been minimized.
acmcarther
commented
Mar 28, 2018
•
|
Given that crate owners can't control how many instances of their crate will be included in a given binary, it seems that we really need a mechanism at least for weak linkage in stable Rust. I got bit by the fallout from #29603 (comment), where rust-libloading gained a cc complation step to workaround this missing feature. |
This comment has been minimized.
This comment has been minimized.
|
I would love some mechanism to merge statics and variables with the same value (and name, possibly). Consider the following code: // In my actual code, this is a more complicated proc macro.
macro_rules! special_number {
($value: expr) => {
{
// In my actual code, these static variables also have
// the special `export_name` of
// "\x01L_special_number_<unique_id>", where
// `<unique_id>` is a unique identifier to avoid
// symbol conflicts.
#[link_section = ".data,__custom_special_section"]
static SPECIAL_NUMBER: usize = $value;
&SPECIAL_NUMBER
}
};
}
extern {
fn consume_special_number(value: &usize);
}
pub fn main() {
unsafe {
consume_special_number(special_number!(42));
consume_special_number(special_number!(42));
consume_special_number(special_number!(42));
};
}This will generate three different static variables. I would love it if I could get Rust to merge these static variables into one single static variable. Using a There are two ways the merging could be performed:
I would be prefer option 2 (merging by name). Perhaps this is what the The |
aturon commentedNov 5, 2015
Tracks stabilization for the
linkageattribute.