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 'rust_begin_unwind': {start,end}-group missing when using an allocator #51647

Closed
japaric opened this issue Jun 20, 2018 · 3 comments

Comments

@japaric
Copy link
Member

japaric commented Jun 20, 2018

STR

$ cargo clone cortex-m-quickstart --vers 0.3.2

$ cd cortex-m-quickstart

$ cat > memory.x <<EOF
/* Linker script for the STM32F103C8T6 */
MEMORY
{
  FLASH : ORIGIN = 0x08000000, LENGTH = 64K
  RAM : ORIGIN = 0x20000000, LENGTH = 20K
}
EOF

$ # OK, doesn't use an allocator
$ # NOTE depends on arm-none-eabi-gcc being installed
$ cargo build --example hello --target thumbv7m-none-eabi

$ cargo add alloc-cortex-m --vers 0.3.5

$ # fails to link
$ cargo build --example allocator --target thumbv7m-none-eabi
  = note: "arm-none-eabi-gcc" (..)
  = note: $_/libcore-c8a4409079a3a8cf.rlib(core-c8a4409079a3a8cf.core7-a6f8712c77d6e222f682a36ad1b2802c.rs.rcgu.o): In function `core::panicking::panic_fmt':
          /checkout/src/libcore/panicking.rs:92: undefined reference to `rust_begin_unwind'

AFAICT the issue is that the linker call in the allocator example doesn't include the -Wl,--{start,end}-group flags added in #49316. Linker invocation for each example is shown below:

$ cargo rustc --example hello --target thumbv7m-none-eabi -- -Z print-link-args "arm-none-eabi-gcc" "-L" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/hello-7bcb38c76f2cfcf9.16u6js6g0l3k1ic6.rcgu.o" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/hello-7bcb38c76f2cfcf9.3l0398fjltevyo2h.rcgu.o" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/hello-7bcb38c76f2cfcf9.4xq48u46a1pwiqn7.rcgu.o" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/hello-7bcb38c76f2cfcf9.544l4wfz89vbhoea.rcgu.o" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/hello-7bcb38c76f2cfcf9.8xzrsc1ux72v29j.rcgu.o" "-o" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/hello-7bcb38c76f2cfcf9" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/debug/deps" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-quickstart-83c2769bb84a5327/out" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-91d6bcd8221521d0/out" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-rt-8f472c01bb62b44f/out" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-rt-8f472c01bb62b44f/out" "-L" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-semihosting-0b565ca91223cdc9/out" "-L" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libpanic_semihosting-5bedc9c7e9038e5a.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m-608790ed92cdaba8.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libvolatile_register-febb9ecda2e1e875.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libvcell-5f0330b175b9171f.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libbare_metal-cd38b616da4ad7a9.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libaligned-65d7a0374e7cc15f.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m_semihosting-2b99179dc7319028.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m_rt-df2a73939030a238.rlib" "/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libr0-0230fc14e4aa7a0c.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcore-c8a4409079a3a8cf.rlib" "-Wl,--end-group" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcompiler_builtins-a0b503090929f0e3.rlib" "-Wl,-Tlink.x" "-nostartfiles" "-Wl,-Bdynamic"

$ cargo build --example allocator --target thumbv7m-none-eabi
"arm-none-eabi-gcc"
"-L"
"/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.12o6z8zowpxdwec2.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.16u6js6g0l3k1ic6.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.181cuta0v63atwcm.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.1im38lueib99jsk0.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.1mvmz58owquyropc.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.1y16o1qfye96o7m0.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.2lyh15q6cjwzy18c.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.2njzq1xnlu88l3yx.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.2oafmlh5ijbov6fd.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.3ayaeypdcro9d6yk.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.3l0398fjltevyo2h.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.48721dc4k5qxei0u.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.49a7n47po4ttqjl7.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.4ezmh1vbs95c5ack.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.4kcm5l1y0r3i2da7.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.4xq48u46a1pwiqn7.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.4yh8x2b62dcih00t.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.51s1w397y42gpez1.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.56dly8q07ws8ucdq.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.8xzrsc1ux72v29j.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.9elsx31vb4it187.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.9fcb3syd3ne5k0n.rcgu.o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.y08g5q2x813c4wx.rcgu.o"
"-o"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/examples/allocator-d041c1c8fc06f1f7.crate.allocator.rcgu.o"
"-Wl,--gc-sections"
"-nodefaultlibs"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/debug/deps"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-quickstart-83c2769bb84a5327/out"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-91d6bcd8221521d0/out"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-rt-8f472c01bb62b44f/out"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-rt-8f472c01bb62b44f/out"
"-L"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/build/cortex-m-semihosting-0b565ca91223cdc9/out"
"-L"
"/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib"
"-Wl,-Bstatic"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libpanic_semihosting-5bedc9c7e9038e5a.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m_semihosting-2b99179dc7319028.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m_rt-df2a73939030a238.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libr0-0230fc14e4aa7a0c.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m-608790ed92cdaba8.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libvolatile_register-febb9ecda2e1e875.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libvcell-5f0330b175b9171f.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libbare_metal-cd38b616da4ad7a9.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libaligned-65d7a0374e7cc15f.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/liballoc_cortex_m-1dc8f624614f3e20.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/liblinked_list_allocator-89856fc389dfa7e0.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libcortex_m-d4954d2588102c99.rlib"
"/home/japaric/tmp/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/libvolatile_register-7f8b6601fedcc83f.rlib"
"/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/liballoc-0cbd0a7c85435046.rlib"
"/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcore-c8a4409079a3a8cf.rlib"
"/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcompiler_builtins-a0b503090929f0e3.rlib"
"-Wl,-Tlink.x"
"-nostartfiles"
"-Wl,-Bdynamic"

Adding -Wl,--{start,end}-group to the linker invocation for the allocator example fixes the linking error.

I believe this error started showing up after #50144 landed.

Meta

$ rustc -V
rustc 1.28.0-nightly (523097979 2018-06-18)

cc @alexcrichton @sfackler

@japaric
Copy link
Member Author

japaric commented Jun 21, 2018

This may be related to, or even directly caused by, #51671. If I move the oom lang item into a separate crate (rlib) then --{start,end}-group appear in the linker invocation and linking succeeds.

@japaric
Copy link
Member Author

japaric commented Jul 3, 2018

This may be related to, or even directly caused by, #51671.

#51671 has been fixed but this problem still remains: the {start,end}-group linker flags are still missing -- the rust_oom and rust_begin_unwind are present in the object files.

@japaric
Copy link
Member Author

japaric commented Aug 28, 2018

I can no longer reproduce this.

@japaric japaric closed this as completed Aug 28, 2018
paoloteti added a commit to paoloteti/compiler-builtins that referenced this issue Sep 1, 2018
rust-lang/rust#51647 has been fixed, so We can remove this hack
paoloteti added a commit to paoloteti/compiler-builtins that referenced this issue Sep 1, 2018
rust-lang/rust#51647 has been fixed, so We can remove this hack
paoloteti added a commit to paoloteti/compiler-builtins that referenced this issue Sep 1, 2018
rust-lang/rust#51647 has been fixed, so We can remove this hack
AaronKutch added a commit to AaronKutch/compiler-builtins that referenced this issue Dec 11, 2020
AaronKutch added a commit to AaronKutch/compiler-builtins that referenced this issue Dec 11, 2020
rust-lang/rust#51647 is fixed but panic-handler is still needed
AaronKutch added a commit to AaronKutch/compiler-builtins that referenced this issue Apr 2, 2021
rust-lang/rust#51647 is fixed but panic-handler is still needed
dmakarov pushed a commit to anza-xyz/compiler-builtins that referenced this issue Apr 4, 2021
rust-lang/rust#51647 is fixed but panic-handler is still needed
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

No branches or pull requests

1 participant