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

Use protected visibility by default on ELF platforms #105518

Open
pcc opened this issue Dec 10, 2022 · 8 comments
Open

Use protected visibility by default on ELF platforms #105518

pcc opened this issue Dec 10, 2022 · 8 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pcc
Copy link
Contributor

pcc commented Dec 10, 2022

I noticed that the .so files built by x.py contain a lot of "unnecessary" PLT entries. The compiler should be using protected visibility on ELF platforms by default.

I was thinking we should be able to tie it to #[no_mangle] but on Zulip @bjorn3 proposed tying it to the SymbolExportLevel (Rust for mangled and unmangled but not exported from cdylib #[rustc_std_internal_symbol] symbols and C for #[no_mangle] symbols).

@bjorn3 bjorn3 added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 10, 2022
@danakj
Copy link
Contributor

danakj commented May 24, 2023

This is related to #37530 and #33221

@bjorn3
Copy link
Member

bjorn3 commented May 24, 2023

Those issues are about which symbols are exported or not. This issue is not about which symbols are exported or not. Protected visibility will still export symbols. It merely prevents overwriting those symbols from other dylibs.

@danakj
Copy link
Contributor

danakj commented May 24, 2023

Ah ok thanks for the clarification!

@bjorn3
Copy link
Member

bjorn3 commented Jul 19, 2023

Attempted to implement this in https://github.com/bjorn3/rust/tree/protected_visibility. It works fine for ld.gold and ld.lld, but with ld.bfd it results in:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/bin:/home/gh-bjorn3/.local/bin:/home/gh-bjorn3/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" VSLANG="1033" "cc" "-Wl,--version-script=/tmp/rustcOHW0DQ/list" "-Wl,--no-undefined-version" "/tmp/rustcOHW0DQ/symbols.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.00.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.01.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.02.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.03.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.04.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.05.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.06.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.08.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.09.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.10.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.11.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.12.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.14.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.15.rcgu.o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.4jul3hyqzc65lxuh.rcgu.rmeta" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.3lo40xndxmc2j69n.rcgu.o" "-Wl,--as-needed" "-L" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps" "-L" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/release/deps" "-L" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libpanic_unwind-6539d23e93d602e2.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libobject-a47966ab81fae984.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libmemchr-1b930b63de7c56f6.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libaddr2line-eb24309d543fdabf.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libgimli-3b7990132945b345.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/librustc_demangle-d091de4010eed9b8.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libstd_detect-1b1db080986b68cf.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libhashbrown-65245041fec002ce.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/librustc_std_workspace_alloc-40b6828da573b833.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libminiz_oxide-dbf6b23630950e0f.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libadler-65b9b24cccb63b72.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libunwind-b6cb3762975e15c6.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcfg_if-b0325152658f881c.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/liblibc-7a5025d388fb2618.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/liballoc-880cfc5ae7643f83.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/librustc_std_workspace_core-3a5d24fbcee0e4fd.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcompiler_builtins-30a15f09c31cdce0.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libstd-415ef54566353f34.so" "-shared" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-Wl,-z,origin" "-Wl,-rpath,$ORIGIN/../lib"
  = note: /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.02.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9backtrace9Backtrace7capture17hbe0ab5a5ae8a4d77E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.02.rcgu.o: in function `std::backtrace::Backtrace::capture':
          std.9bb3df1236a54be1-cgu.02:(.text._ZN3std9backtrace9Backtrace7capture17hbe0ab5a5ae8a4d77E+0x124): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.02.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9backtrace9Backtrace13force_capture17hef3296f41bc64462E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.02.rcgu.o: in function `std::backtrace::Backtrace::force_capture':
          std.9bb3df1236a54be1-cgu.02:(.text._ZN3std9backtrace9Backtrace13force_capture17hef3296f41bc64462E+0x4): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h57a6bf59ff8b4107E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o: in function `std::panicking::panic_count::increase':
          std.9bb3df1236a54be1-cgu.07:(.text._ZN3std9panicking11panic_count8increase17hb67738ce4889cd48E+0x8): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h57a6bf59ff8b4107E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o: in function `std::panicking::panic_count::decrease':
          std.9bb3df1236a54be1-cgu.07:(.text._ZN3std9panicking11panic_count8decrease17h7032ce993a333a03E+0x4): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking11panic_count18GLOBAL_PANIC_COUNT17h57a6bf59ff8b4107E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.07.rcgu.o: in function `std::panicking::panic_count::set_always_abort':
          std.9bb3df1236a54be1-cgu.07:(.text._ZN3std9panicking11panic_count16set_always_abort17h4c2528c0ec6026dbE+0x4): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN91_$LT$std..sys_common..backtrace.._print..DisplayBacktrace$u20$as$u20$core..fmt..Display$GT$3fmt17hb8d1b111f7cc8252E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: in function `std::sys_common::backtrace::print':
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std10sys_common9backtrace5print17hf7aac3e29d72f262E+0x98): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: in function `std::panicking::set_hook':
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking8set_hook17h8591ac4933ef13a8E+0x38): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking8set_hook17h8591ac4933ef13a8E+0x58): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: in function `std::panicking::take_hook':
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking9take_hook17h6d3b290e8ed034f5E+0x24): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking9take_hook17h6d3b290e8ed034f5E+0x150): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: in function `std::panicking::rust_panic_with_hook':
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking20rust_panic_with_hook17h3533559235359199E+0x54): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking20rust_panic_with_hook17h3533559235359199E+0x64): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking20rust_panic_with_hook17h3533559235359199E+0x88): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.13.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN3std9panicking4HOOK17h70a6060fe0d379ceE' which may bind externally can not be used when making a shared object; recompile with -fPIC
          std.9bb3df1236a54be1-cgu.13:(.text._ZN3std9panicking20rust_panic_with_hook17h3533559235359199E+0xa0): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.15.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN63_$LT$std..process..ExitStatus$u20$as$u20$core..fmt..Display$GT$3fmt17h227b634e4373fa20E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.15.rcgu.o: in function `<std::process::ExitStatusError as core::fmt::Display>::fmt':
          std.9bb3df1236a54be1-cgu.15:(.text._ZN68_$LT$std..process..ExitStatusError$u20$as$u20$core..fmt..Display$GT$3fmt17h25dd15edbda74edbE+0x8): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.15.rcgu.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN58_$LT$std..io..error..Error$u20$as$u20$core..fmt..Debug$GT$3fmt17hd3cced40c18becd9E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/std-415ef54566353f34.std.9bb3df1236a54be1-cgu.15.rcgu.o: in function `<std::sys::unix::fs::Dir as core::ops::drop::Drop>::drop':
          std.9bb3df1236a54be1-cgu.15:(.text._ZN65_$LT$std..sys..unix..fs..Dir$u20$as$u20$core..ops..drop..Drop$GT$4drop17h7ea69e9215da5a9fE+0x4c): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libstd_detect-1b1db080986b68cf.rlib(std_detect-1b1db080986b68cf.std_detect.8c82cd51d704ab52-cgu.1.rcgu.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN10std_detect6detect5cache5CACHE17h1d43f563830256b8E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libstd_detect-1b1db080986b68cf.rlib(std_detect-1b1db080986b68cf.std_detect.8c82cd51d704ab52-cgu.1.rcgu.o): in function `std_detect::detect::cache::detect_and_initialize':
          std_detect.8c82cd51d704ab52-cgu.1:(.text.unlikely._ZN10std_detect6detect5cache21detect_and_initialize17h6b9853ffcd91f3c4E+0x14): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN4core3num7flt2dec8strategy5grisu12CACHED_POW1017ha575f96fa2ca9354E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): in function `core::num::flt2dec::strategy::grisu::cached_power':
          core.fb8474c54fa90b60-cgu.02:(.text._ZN4core3num7flt2dec8strategy5grisu12cached_power17h5128fe17067d2382E+0x3c): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN4core3num7flt2dec8strategy5grisu12CACHED_POW1017ha575f96fa2ca9354E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): in function `core::num::flt2dec::strategy::grisu::format_shortest_opt':
          core.fb8474c54fa90b60-cgu.02:(.text._ZN4core3num7flt2dec8strategy5grisu19format_shortest_opt17h754cfe6b872040c0E+0xf8): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN4core3num7flt2dec8strategy5grisu12CACHED_POW1017ha575f96fa2ca9354E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): in function `core::num::flt2dec::strategy::grisu::format_exact_opt':
          core.fb8474c54fa90b60-cgu.02:(.text._ZN4core3num7flt2dec8strategy5grisu16format_exact_opt17h28bcd1f634583a4fE+0x94): dangerous relocation: unsupported relocation
          /usr/bin/ld: /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZN67_$LT$core..net..ip_addr..Ipv4Addr$u20$as$u20$core..fmt..Display$GT$3fmt17hd4e486673774bef8E' which may bind externally can not be used when making a shared object; recompile with -fPIC
          /home/gh-bjorn3/rust/build/aarch64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/deps/libcore-3f87a9c32d25ec14.rlib(core-3f87a9c32d25ec14.core.fb8474c54fa90b60-cgu.02.rcgu.o): in function `<core::net::ip_addr::Ipv6Addr as core::fmt::Display>::fmt':
          core.fb8474c54fa90b60-cgu.02:(.text._ZN67_$LT$core..net..ip_addr..Ipv6Addr$u20$as$u20$core..fmt..Display$GT$3fmt17h1126a36f89d04df3E+0x1f4): dangerous relocation: unsupported relocation
          collect2: error: ld returned 1 exit status
          

error: could not compile `std` (lib) due to previous error

@VorpalBlade
Copy link

@bjorn3 did you report the issue upstream to Binutils? This would be a nice thing to have.

@bjorn3
Copy link
Member

bjorn3 commented Aug 15, 2024

I didn't. I don't even know if the latest binutils has the same issue.

@davidlattimore
Copy link
Contributor

I just published a blog post on this topic: https://davidlattimore.github.io/posts/2024/08/27/rust-dylib-rabbit-holes.html

The situation has improved significantly with GNU ld from binutils 2.40 and later, which went into distros late last year. I'd say that we can't justify breaking linking for users that have GNU ld < 2.40 for quite some time. So that means this would need to be behind a flag. The good news is that we could consider defaulting that flag to true when LLD is selected as the linker.

I'm happy to have a go at this, unless @bjorn3 or someone else wants to?

@mati865
Copy link
Contributor

mati865 commented Sep 6, 2024

This might be a bit unexpected, so I'm posting it for your information.
This flag will also affect windows-gnu* targets because of llvm/llvm-project@c5b3de6.
So, it's not an ELF only flag.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 1, 2024
… r=Urgau

Replace -Z default-hidden-visibility with -Z default-visibility

Issue rust-lang#105518
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 1, 2024
Rollup merge of rust-lang#130005 - davidlattimore:protected-vis-flag, r=Urgau

Replace -Z default-hidden-visibility with -Z default-visibility

Issue rust-lang#105518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants