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

Undefined reference to `__morestack' when compiling with -O #13625

Closed
sebcrozet opened this issue Apr 19, 2014 · 2 comments
Closed

Undefined reference to `__morestack' when compiling with -O #13625

sebcrozet opened this issue Apr 19, 2014 · 2 comments

Comments

@sebcrozet
Copy link
Contributor

Since I updated the compiler to:

rustc 0.11-pre (2c22ae4 2014-04-19 04:26:28 -0700)
host: x86_64-unknown-linux-gnu

the following code:

extern crate native;

#[start]
fn start(argc: int, argv: **u8) -> int {
    native::start(argc, argv, main)
}

fn main() {
}

fails to compile with optimizations on:

rustc -O test.rs
error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'test' 'test.o' '-lmorestack' '-nodefaultlibs' '-Wl,--as-needed' '-Wl,-O1' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-aad93cea-0.11-pre.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-3574b280-0.11-pre.rlib' '-L.' '-L/home/tortue/trash/.rust' '-L/home/tortue/trash' '-L/home/tortue/.rust' '-Wl,-Bdynamic' '-ldl' '-lpthread' '-lgcc_s' '-lc' '-lm' '-Wl,-rpath,$ORIGIN/../../../usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lcompiler-rt'
note: /usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib(native.o): In function `io::addrinfo::GetAddrInfoRequest::run::ha9bf714109bfa7af1aa::v0.11.pre':
native.rs:(.text+0x28): undefined reference to `__morestack'
/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib(native.o): In function `fmt::secret_string::h10210563234607143262::v0.11.pre':
native.rs:(.text+0xda0): undefined reference to `__morestack'
/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib(native.o): In function `rt::unwind::begin_unwind::h2680316326101838750::v0.11.pre':
native.rs:(.text+0xe00): undefined reference to `__morestack'
/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib(native.o): In function `any::T.Any::get_type_id::h10127464687270589723::v0.11.pre':
native.rs:(.text+0xe90): undefined reference to `__morestack'
/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib(native.o): In function `io::net::sockaddr_to_addr::h1c5b17f236d8b4feAsa::v0.11.pre':
native.rs:(.text+0xed0): undefined reference to `__morestack'
/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib(native.o):native.rs:(.text+0x1160): more undefined references to `__morestack' follow
collect2: error: ld returned 1 exit status

error: aborting due to previous error

Compiling without -O does work fine.

sebcrozet added a commit to sebcrozet/kiss3d that referenced this issue Apr 19, 2014
Version of rustc: rustc 0.11-pre (2c22ae4 2014-04-19 04:26:28 -0700)

The last two examples fail to link because of rust-lang/rust#13625.
@alexcrichton
Copy link
Member

Can you paste the output of rustc --emit=ir foo.rs?

@sebcrozet
Copy link
Contributor Author

Output of rustc --emit=ir test.rs:

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

; Function Attrs: uwtable
define internal i64 @_ZN5start20ha41e9c28898510a9faa4v0.0E(i64, i8**) unnamed_addr #0 {
entry-block:
  %argc = alloca i64
  %argv = alloca i8**
  %__adjust = alloca { void (i8*)*, i8* }
  store i64 %0, i64* %argc
  store i8** %1, i8*** %argv
  %2 = load i64* %argc
  %3 = load i8*** %argv
  %4 = getelementptr inbounds { void (i8*)*, i8* }* %__adjust, i32 0, i32 0
  store void (i8*)* @_ZN4main14as_closure.983E, void (i8*)** %4
  %5 = getelementptr inbounds { void (i8*)*, i8* }* %__adjust, i32 0, i32 1
  store i8* null, i8** %5
  %6 = call i64 @_ZN5start20h52ed3dec7308a2ebxzd9v0.11.preE(i64 %2, i8** %3, { void (i8*)*, i8* }* nocapture %__adjust)
  ret i64 %6
}

define i64 @main(i64, i8**) unnamed_addr {
top:
  %2 = call i64 @_ZN5start20ha41e9c28898510a9faa4v0.0E(i64 %0, i8** %1)
  ret i64 %2
}

declare i64 @_ZN5start20h52ed3dec7308a2ebxzd9v0.11.preE(i64, i8**, { void (i8*)*, i8* }* noalias) unnamed_addr #1

; Function Attrs: uwtable
define internal void @_ZN4main20ha1e063e2a65e22b5yaa4v0.0E() unnamed_addr #0 {
entry-block:
  ret void
}

define internal void @_ZN4main14as_closure.983E(i8*) unnamed_addr {
entry-block:
  call void @_ZN4main20ha1e063e2a65e22b5yaa4v0.0E()
  ret void
}

attributes #0 = { uwtable "split-stack" }
attributes #1 = { "split-stack" }

Output of rustc -O --emit=ir test.rs:

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

define i64 @main(i64, i8**) unnamed_addr {
top:
  %__adjust.i = alloca { void (i8*)*, i8* }, align 8
  %2 = bitcast { void (i8*)*, i8* }* %__adjust.i to i8*
  call void @llvm.lifetime.start(i64 16, i8* %2)
  %3 = getelementptr inbounds { void (i8*)*, i8* }* %__adjust.i, i64 0, i32 0
  store void (i8*)* @_ZN4main14as_closure.983E, void (i8*)** %3, align 8
  %4 = getelementptr inbounds { void (i8*)*, i8* }* %__adjust.i, i64 0, i32 1
  store i8* null, i8** %4, align 8
  %5 = call i64 @_ZN5start20h52ed3dec7308a2ebxzd9v0.11.preE(i64 %0, i8** %1, { void (i8*)*, i8* }* nocapture %__adjust.i)
  call void @llvm.lifetime.end(i64 16, i8* %2)
  ret i64 %5
}

declare i64 @_ZN5start20h52ed3dec7308a2ebxzd9v0.11.preE(i64, i8**, { void (i8*)*, i8* }* noalias) unnamed_addr #0

; Function Attrs: nounwind readnone
define internal void @_ZN4main14as_closure.983E(i8* nocapture) unnamed_addr #1 {
entry-block:
  ret void
}

; Function Attrs: nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #2

; Function Attrs: nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #2

attributes #0 = { "split-stack" }
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind }

bors added a commit that referenced this issue Apr 19, 2014
In upgrading LLVM, only rust functions had the "split-stack" attribute added.
This commit changes the addition of LLVM's "split-stack" attribute to *always*
occur and then we remove it sometimes if the "no_split_stack" rust attribute is
present.

Closes #13625
Manishearth pushed a commit to Manishearth/rust that referenced this issue Nov 23, 2022
internal: Update proc-macro-srv tests

Should have been included in rust-lang#13548, but I didn't notice as those tests aren't run in our CI.

cc rust-lang#104454
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 28, 2024
It's becoming more and more common to see people including markdown
files in their code using `doc = include_str!("...")`, which is great.
However, often there is no condition on this include, which is not great
because it slows down compilation and might trigger recompilation if
these files are updated.

This lint aims at fixing this situation.

changelog: Add new lint `doc_include_without_cfg`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants