Skip to content
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

link_section attribute misleadingly allowed on modules and impls #65128

Open
Earlz opened this issue Oct 5, 2019 · 3 comments
Open

link_section attribute misleadingly allowed on modules and impls #65128

Earlz opened this issue Oct 5, 2019 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Earlz
Copy link

Earlz commented Oct 5, 2019

The #[link_section] attribute seems to be allowed on modules and impl blocks, but it will not do anything. I would expect either all functions/statics within the module/impl to be placed into the specified link_section, but this does not happen.

Code used:

#[link_section = ".textaux1"]
mod foo{
    //#[link_section = ".textaux1"]
    pub fn testing() -> u32{
        20
    }
}
mod foo2{
    pub struct Whatever{}
    #[link_section = ".textaux1"]
    impl Whatever{
        //#[link_section = ".textaux1"]
        pub fn watt(&self) -> u32{
            50
        }
    }
}

I've verified the functions are linked in and not just optimized out etc. As-is the functions will be placed into the default .text section, but if I uncomment the link_section attributes then they are properly placed in the .textaux1 section. No compiler errors or warnings are generated

rustc version:
rustc 1.40.0-nightly (2daa404 2019-10-02)
binary: rustc
commit-hash: 2daa404
commit-date: 2019-10-02
host: x86_64-apple-darwin
release: 1.40.0-nightly
LLVM version: 9.0

@jonas-schievink jonas-schievink added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 5, 2019
@hannobraun
Copy link

The same seems to be true for extern functions. I would have expected the following code to link the extern function into .data, but it was linked into .text:

extern {
    #[link_section=".data"]
    #[inline(never)]
    fn write_half_page(address: *mut u32, words: *const u32);
}

No warning or error was emitted. The link_section attribute was just ignored, it seems.

@ehuss
Copy link
Contributor

ehuss commented Sep 15, 2020

A warning for this has been added in #73461.

@bjorn3
Copy link
Member

bjorn3 commented Jul 29, 2023

There is a future compat lint for this. Should this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants