Repository: rust
Issue: Compiler crashes with SIGSEGV when compiling core library with static relocation model
Labels: A-linkage,T-compiler,C-bug

So, I'm compiling Rust programs to run on MS-DOS (386 real mode). This requires a static relocation model, and I can get many programs to compile and run by passing ``-C relocation-model=static`` during compilation and making sure that my linker flags include ``-fno-pie``. However, things went wrong when I tried to hook the I/O routines that I had written up to Rust's formatting macros. Trait implementations for ``core::fmt::Arguments`` start to get pulled in, and the linker complains that they are looking for _GLOBAL_OFFSET_TABLE_ despite the fact that the compiler shouldn't be generating code which needs that.

```
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--gc-sections" "-m16" "-nostdlib" "-march=i386" "-ffreestanding" "-fno-pie" "-Tcom.ld" "-L" "/home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.0.rcgu.o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.1.rcgu.o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.2.rcgu.o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.3.rcgu.o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.4.rcgu.o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.5.rcgu.o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.dos.dg1u0jr4-cgu.6.rcgu.o" "-o" "/home/seren/rusty-dos/target/dos/release/deps/dos-81645608ce9864b6.com" "-Wl,--gc-sections" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/seren/rusty-dos/target/dos/release/deps" "-L" "/home/seren/rusty-dos/target/release/deps" "-L" "/home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib" "-Wl,-Bstatic" "/home/seren/rusty-dos/target/dos/release/deps/libbitflags-e1a464dc3e355838.rlib" "/home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/librustc_std_workspace_core-490848ebf202e93d.rlib" "/home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib" "/home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib" "-Wl,-Bdynamic"
  = note: /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.5.rcgu.o): in function `_ZN4core3fmt10ArgumentV110show_usize17h9290b20043846a9aE.llvm.11768198070876224222':
          core.dffyupwt-cgu.5:(.text._ZN4core3fmt10ArgumentV110show_usize17h9290b20043846a9aE.llvm.11768198070876224222+0x17): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.5.rcgu.o): in function `core::fmt::ArgumentV1::from_usize':
          core.dffyupwt-cgu.5:(.text._ZN4core3fmt10ArgumentV110from_usize17h306ac2fc1d8b66c1E+0xb): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.5.rcgu.o): in function `<core::fmt::Arguments as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.5:(.text._ZN57_$LT$core..fmt..Arguments$u20$as$u20$core..fmt..Debug$GT$3fmt17h00de601147a33c89E+0x1c): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.5.rcgu.o): in function `<core::fmt::Arguments as core::fmt::Display>::fmt':
          core.dffyupwt-cgu.5:(.text._ZN59_$LT$core..fmt..Arguments$u20$as$u20$core..fmt..Display$GT$3fmt17h8229c189564c851aE+0x1c): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.5.rcgu.o): in function `core::fmt::write':
          core.dffyupwt-cgu.5:(.text._ZN4core3fmt5write17h1c6a04dbcbef5dc7E+0x82): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.5.rcgu.o):core.dffyupwt-cgu.5:(.text._ZN4core3fmt9Formatter8wrap_buf17hf8f3027e075f5fd5E+0xd0): more undefined references to `_GLOBAL_OFFSET_TABLE_' follow
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<core::sync::atomic::AtomicI64 as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN66_$LT$core..sync..atomic..AtomicI64$u20$as$u20$core..fmt..Debug$GT$3fmt17hbc9f32d54d630799E+0x35): undefined reference to `__atomic_load_8'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<core::sync::atomic::AtomicU64 as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN66_$LT$core..sync..atomic..AtomicU64$u20$as$u20$core..fmt..Debug$GT$3fmt17h2bacc92521ff782aE+0x1a): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: core.dffyupwt-cgu.12:(.text._ZN66_$LT$core..sync..atomic..AtomicU64$u20$as$u20$core..fmt..Debug$GT$3fmt17h2bacc92521ff782aE+0x3a): undefined reference to `__atomic_load_8'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<&T as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h05f349f183bd57f5E+0x1e): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<&T as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h1feb199478027b45E+0x1e): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<&T as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h25a1d98a3ec158d7E+0xd): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<&T as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h2ca09666842d4c7eE+0x1a): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o): in function `<&T as core::fmt::Debug>::fmt':
          core.dffyupwt-cgu.12:(.text._ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h348ad87268046417E+0x1e): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcore-86783f30f14d1df7.rlib(core-86783f30f14d1df7.core.dffyupwt-cgu.12.rcgu.o):core.dffyupwt-cgu.12:(.text._ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h3eb6f5e1d37d7ffdE+0x1e): more undefined references to `_GLOBAL_OFFSET_TABLE_' follow
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.7.rcgu.o): in function `__llvm_memcpy_element_unordered_atomic_8':
          compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memcpy_element_unordered_atomic_8+0x47): undefined reference to `__atomic_load_8'
          /usr/sbin/ld: compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memcpy_element_unordered_atomic_8+0x5a): undefined reference to `__atomic_store_8'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.7.rcgu.o): in function `__llvm_memmove_element_unordered_atomic_8':
          compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memmove_element_unordered_atomic_8+0x15): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memmove_element_unordered_atomic_8+0x5a): undefined reference to `__atomic_load_8'
          /usr/sbin/ld: compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memmove_element_unordered_atomic_8+0x6d): undefined reference to `__atomic_store_8'
          /usr/sbin/ld: compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memmove_element_unordered_atomic_8+0xa7): undefined reference to `__atomic_load_8'
          /usr/sbin/ld: compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memmove_element_unordered_atomic_8+0xba): undefined reference to `__atomic_store_8'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.7.rcgu.o): in function `__llvm_memset_element_unordered_atomic_8':
          compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memset_element_unordered_atomic_8+0x17): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: compiler_builtins.85hciet7-cgu.7:(.text.__llvm_memset_element_unordered_atomic_8+0xaf): undefined reference to `__atomic_store_8'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.10.rcgu.o): in function `__divdi3':
          compiler_builtins.85hciet7-cgu.10:(.text.__divdi3+0x13): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.10.rcgu.o): in function `__divti3':
          compiler_builtins.85hciet7-cgu.10:(.text.__divti3+0x1e): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.10.rcgu.o): in function `__moddi3':
          compiler_builtins.85hciet7-cgu.10:(.text.__moddi3+0x11): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.10.rcgu.o): in function `__modti3':
          compiler_builtins.85hciet7-cgu.10:(.text.__modti3+0x1e): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          /usr/sbin/ld: /home/seren/rusty-dos/target/sysroot/lib/rustlib/dos/lib/libcompiler_builtins-ae809761299d8c44.rlib(compiler_builtins-ae809761299d8c44.compiler_builtins.85hciet7-cgu.10.rcgu.o): in function `__divmoddi4':
          compiler_builtins.85hciet7-cgu.10:(.text.__divmoddi4+0x13): undefined reference to `_GLOBAL_OFFSET_TABLE_'
          collect2: error: ld returned 1 exit status
```