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

#[linkage] does not propagate through generic functions #18804

Closed
alexcrichton opened this Issue Nov 9, 2014 · 3 comments

Comments

Projects
None yet
6 participants
@alexcrichton
Copy link
Member

alexcrichton commented Nov 9, 2014

For example:

// lib.rs
#![feature(linkage)]

pub fn foo<T>() -> *const () {
    extern {
        #[linkage = "extern_weak"]
        static FOO: *const ();
    }
    FOO
}
// main.rs
extern crate lib;

fn main() {
    lib::foo::<int>();
}
$ rustc lib.rs --crate-type rlib
$ rustc main.rs -L .
error: linking with `cc` failed: exit code: 1
note: cc '-Wl,--as-needed' '-m64' '-L' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'main' 'main.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-fno-lto' '-Wl,--gc-sections' '-pie' '-nodefaultlibs' '/home/alex/liblib.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libsync-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustrt-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib' '/home/alex/code/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib' '-L' '.' '-L' '/home/alex/.rust' '-L' '/home/alex' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-ldl' '-lpthread' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: main.o:main.0.rs:function foo::h6978205699166201756: error: undefined reference to 'FOO'
collect2: error: ld returned 1 exit status

error: aborting due to previous error

This can be a little more clearly seen with the IR generated for main:

; ModuleID = 'main.0.rs'
target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@FOO = external global {}*

...

Note the lack of extern_weak anywhere on FOO.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Dec 31, 2015

Triage: this is still true today, though int needs to be updated to i32, and there's now a warning about () not being a valid foreign type, which is irrelevant to this particular issue.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jun 1, 2017

@Mark-Simulacrum claims it repros still.

@yodaldevoid

This comment has been minimized.

Copy link
Contributor

yodaldevoid commented Jan 17, 2018

Updated test code:

// lib.rs
#![feature(linkage)]

pub fn foo<T>() -> *const() {
    extern {
        #[linkage = "extern_weak"]
        static FOO: *const();
    }
    unsafe { FOO }
}
// main.rs
extern crate lib;

fn main() {
    lib::foo::<i32>();
}

Still fails to compile with the same errors mentioned in the top post along with the irrelevant invalid foreign type warning mentioned by @steveklabnik.

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 23, 2018

Add regression test for issue rust-lang#18804
Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 23, 2018

Properly set the linkage type on non-local statics
Fixes issue rust-lang#18804

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 23, 2018

Add regression test for issue rust-lang#18804
Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 23, 2018

Properly set the linkage type on non-local statics
Fixes issue rust-lang#18804

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

bors added a commit that referenced this issue Jul 24, 2018

Auto merge of #52635 - yodaldevoid:issue_18804, r=oli-obk
Fix #[linkage] propagation though generic functions

Fixes #18804

In the non-local branch of `get_static` (where the fix was implemented) `span_fatal` had to be replaced with `bug!` as we have no span in that case.

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 25, 2018

Add regression test for issue rust-lang#18804
Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 25, 2018

Properly set the linkage type on non-local statics
Fixes issue rust-lang#18804

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 25, 2018

Disable regression test for issue rust-lang#18804 on Emscripten and A…
…smjs

The Emscripten compiler does not support weak symbols at the moment.

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 25, 2018

Add regression test for issue rust-lang#18804
Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 25, 2018

Properly set the linkage type on non-local statics
Fixes issue rust-lang#18804

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

yodaldevoid added a commit to yodaldevoid/rust that referenced this issue Jul 25, 2018

Disable regression test for issue rust-lang#18804 on Emscripten and A…
…smjs

The Emscripten compiler does not support weak symbols at the moment.

Signed-off-by: Gabriel Smith <ga29smith@gmail.com>

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 26, 2018

Rollup merge of rust-lang#52635 - yodaldevoid:issue_18804, r=oli-obk
Fix #[linkage] propagation though generic functions

Fixes rust-lang#18804

In the non-local branch of `get_static` (where the fix was implemented) `span_fatal` had to be replaced with `bug!` as we have no span in that case.

@bors bors closed this in #52635 Jul 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.