-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Item ordering #71
Comments
To add on to this, this feature should at least be documented if it is intended to be used by others. |
Actually I tried that, if I specify a sort key, it just isn't present in the array. |
I've tried the following on Windows: #[distributed_slice]
pub static ITEM: [u32];
#[distributed_slice(ITEM, 2)]
static ITEM2: u32 = 2;
#[distributed_slice(ITEM, 1)]
static ITEM1: u32 = 1; which expands to #[link_section = ".linkme_ITEM$b0002"]
static ITEM2: u32 = {...};
#[link_section = ".linkme_ITEM$b0001"]
static ITEM1: u32 = {...}; According to Raymond Chen's Old New Thing the linker sorts items into the section according to the fragment on the right of the As for the limit of |
Actually there's two unexpected gotchas when using this facility:
#[distributed_slice]
pub static ITEM: [u32];
#[distributed_slice(ITEM, 2)] // .linkme_ITEM$b0002
static ITEM2: u32 = 2;
#[distributed_slice(ITEM, 1)] // .linkme_ITEM$b0001
static ITEM1: u32 = 1;
#[distributed_slice(ITEM)] // .linkme_ITEM$b
static ITEM3: u32 = 3;
fn main() {
println!("{:?}", ITEM.iter());
} yields
#[distributed_slice(ITEM, 1)]
static ITEM1: u32 = 1;
#[distributed_slice(ITEM, 2)]
static ITEM2: u32 = 2;
#[distributed_slice(ITEM, 2)]
static ITEM3: u32 = 3;
#[distributed_slice(ITEM, 4)]
static ITEM4: u32 = 4; yields #[distributed_slice(ITEM, 1)]
static ITEM1: u32 = 1;
#[distributed_slice(ITEM, 2)]
static ITEM3: u32 = 3;
#[distributed_slice(ITEM, 2)]
static ITEM2: u32 = 2;
#[distributed_slice(ITEM, 4)]
static ITEM4: u32 = 4; yields |
Currently, the linkme macro accepts an usize sort key. Although it is not documented, I assume this controls the ordering of the elements in the final slice. I was planing to use this to guarantee a deterministic ordering of entries between builds by supplying a hash of the item as the sort key. Otherwise, I end up with different orderings between release and debug builds. Unfortunately, the sort key is limited to a maximum of 9999, which is too small to avoid hash collisions.
It would be neat to have more control over the ordering of items.
The text was updated successfully, but these errors were encountered: