Skip to content

#[link_section] does not work in libraries on release #85045

@AsafFisher

Description

@AsafFisher

I tried this code while compiling for release:
bin.rs

use elfredo::extended_data;


fn main() {
    print!("{}", do_stuff_with_extended_data());
}

lib.rs

#[link_section = ".extended"]
#[used]
#[no_mangle]
pub static extended_data: u8 = 3;

fn do_stuff_with_extended_data() -> &str{
// Uses extended_data
}

I expected to see this happen (compiled with debug):

asaffisher@ubuntu:/mnt/hgfs/elfredo/target/debug$ readelf -S test_echo_patch_elf | grep extend
  [18] .extended         PROGBITS         000000000003cec8  0003cec8

Instead, this happened(compiled in release):

asaffisher@ubuntu:/mnt/hgfs/elfredo/target/release$ readelf -S test_echo_patch_elf | grep extend
asaffisher@ubuntu:/mnt/hgfs/elfredo/target/release$

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (42816d61e 2021-04-24)
binary: rustc
commit-hash: 42816d61ead7e46d462df997958ccfd514f8c21c
commit-date: 2021-04-24
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-linkageArea: linking into static, shared libraries and binariesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.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