Skip to content

link_section attribute misleadingly allowed on modules and impls  #65128

Open
@Earlz

Description

@Earlz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions