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

Try __libc_ section prefix #45

Closed
wants to merge 3 commits into from
Closed

Try __libc_ section prefix #45

wants to merge 3 commits into from

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Sep 26, 2021

Per #41 (comment). Recent versions of lld recognize section names with a __libc_ prefix as being retained even without rustc support for llvm.used.

Relevant to #41 and #40. Sadly as far as I can tell I don't think this fully fixes either one.

Copy link
Owner Author

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS: no change.

---- declaration::test_functions stdout ----
thread 'declaration::test_functions' panicked at 'assertion failed: !FUNCTIONS.is_empty()', tests/custom_linkme_path.rs:21:9

---- declaration::test_slice stdout ----
thread 'declaration::test_slice' panicked at 'assertion failed: !SLICE.is_empty()', tests/custom_linkme_path.rs:12:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Cortex-M:

error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/cortex_m_linkme_test-16abada556882b6c.cortex_m_linkme_test.11f206d2-cgu.0.rcgu.o" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/cortex_m_linkme_test-16abada556882b6c.cortex_m_linkme_test.11f206d2-cgu.1.rcgu.o" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/cortex_m_linkme_test-16abada556882b6c.cortex_m_linkme_test.11f206d2-cgu.2.rcgu.o" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/cortex_m_linkme_test-16abada556882b6c.cortex_m_linkme_test.11f206d2-cgu.3.rcgu.o" "--as-needed" "-L" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps" "-L" "/home/runner/work/linkme/linkme/target/release/deps" "-L" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/build/cortex-m-linkme-test-fd2f9025fa6ab5f3/out" "-L" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/build/cortex-m-dc8ce5e5692e1185/out" "-L" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/build/cortex-m-rt-146748f53fc7675e/out" "-L" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/build/cortex-m-semihosting-06c5e7e29f999ff6/out" "-L" "/usr/share/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib" "-Bstatic" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/liblinkme-f7db9041ae6efe5a.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libcortex_m_rt-66869b94f8d0a046.rlib" "--start-group" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libpanic_semihosting-23f6673becf7b019.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libcortex_m_semihosting-d41a19e13b83fd58.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libcortex_m-d0a9c8248f754074.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libembedded_hal-d3d0fba186ae51c5.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libvoid-9ff3a42907c50f26.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libnb-a64e30147a73fe33.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libnb-722d2d7ea921a817.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libvolatile_register-8f58f7ecc06a6493.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libvcell-bf2fa04b84d99d34.rlib" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/libbare_metal-943465c25f42e4e6.rlib" "/usr/share/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/librustc_std_workspace_core-ba626387a2e50982.rlib" "/usr/share/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcore-bc639632082e340c.rlib" "--end-group" "/usr/share/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcompiler_builtins-4ec3ed03bf6f473e.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/usr/share/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib" "-o" "/home/runner/work/linkme/linkme/target/thumbv7m-none-eabi/release/deps/cortex_m_linkme_test-16abada556882b6c" "--gc-sections" "-O1" "-Tlink.x"
  = note: rust-lld: error: no memory region specified for section '__libc_SHENANIGANS'
          rust-lld: error: no memory region specified for section '__libc_EMPTY'

@mystor
Copy link

mystor commented Sep 28, 2021

It would make sense that macOS would be unchanged, as the code I linked in #41 (comment) is in the /ELF/ subdirectory, and therefore wouldn't be used for Mach-O binaries. The change for Mach-O is probably caused because on macOS #[used] changed meaning to llvm.compiler.used rather than llvm.used. I don't see a trick for working around that in https://github.com/llvm/llvm-project/blob/abbbc480a152c1afbac215064f22ae07c87ed964/lld/MachO/MarkLive.cpp, other than marking the symbols correctly (which I expect requires rustc support).

You can actually see the different generated code fairly easily in the compiler explorer: https://godbolt.org/z/4sTrKzxYn. When building with rustc 1.55.0, there is a .no_dead_strip example::FOO directive in the generated assembly, whereas in nightly that directive is missing.

I believe the original motivation for switching to llvm.compiler.used over llvm.used was that it aligned with clang better, but it appears as though clang specifies .no_dead_strip for both __attribute__((used)) and __attribute__((retain)) right now (https://godbolt.org/z/6Tc3xcjcr), so perhaps that only applies to ELF targets?

In contrast, I don't see any change in the generated assembly for armv7m-none-eabi, they look the same before and after: https://godbolt.org/z/bsP9E8jWq. The new linker errors also suggest that there may be some other place in lld which checks for the __libc_ prefix and is screwing things up there.

@dtolnay dtolnay closed this Nov 21, 2021
@dtolnay dtolnay deleted the libc branch November 21, 2021 04:26
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 this pull request may close these issues.

2 participants