Commit Graph

24 Commits

Author SHA1 Message Date
jyn ff6b935df4 Filter out -nolibc warning with MingW Clang 2026-04-26 16:07:28 +00:00
Jonathan Brouwer bbe1afafb4 Rollup merge of #149868 - alexcrichton:wasm-no-allow-undefined, r=Mark-Simulacrum
rustc: Stop passing `--allow-undefined` on wasm targets

This commit updates how the linker is invoked on WebAssembly targets (all of them) to avoid passing the `--allow-undefined` flag to the linker. Historically, if I remember this correctly, when `wasm-ld` was first integrated this was practically required because at the time it was otherwise impossible to import a function from the host into a wasm binary. Or, at least, I'm pretty sure that was why this was added.

At the time, as the documentation around this option indicates, it was known that this was going to be a hazard. This doesn't match behavior on native, for example, and can easily paper over what should be a linker error with some sort of other obscure runtime error. An example is that this program currently compiles and links, it just prints null:

    unsafe extern "C" {
        static nonexistent: u8;
    }

    fn main() {
        println!("{:?}", &raw const nonexistent);
    }

This can easily lead to mistakes like rust-lang/libc#4880 and defer what should be a compile-time link error to weird or unusual behavior at link time. Additionally, in the intervening time since `wasm-ld` was first introduced here, lots has changed and notably this program works as expected:

    #[link(wasm_import_module = "host")]
    unsafe extern "C" {
        fn foo();
    }

    fn main() {
        unsafe {
            foo();
        }
    }

This continues to compile without error and the final wasm binary indeed has an imported function from the host. This program:

    unsafe extern "C" {
        fn foo();
    }

    fn main() {
        unsafe {
            foo();
        }
    }

this currently compiles successfully and emits an import from the `env` module. After this change, however, this will fail to compile with a link error stating that the `foo` symbol is not defined.
2026-04-04 17:19:09 +02:00
Jynn Nelson 20404bf4a6 Split out linker-info from linker-messages
- Hide common linker output behind `linker-info`
- Add tests
- Account for different capitalization on windows-gnu when removing
  "warning" prefix
- Add some more comments
- Add macOS deployment-target test
- Ignore linker warnings from trying to statically link glibc

  I don't know what's going on in `nofile-limit.rs` but I want no part
  of it.

- Use a fake linker so tests are platform-independent
2026-03-06 10:38:21 +01:00
Alex Crichton cfd52bba1f rustc: Stop passing --allow-undefined on wasm targets
This commit updates how the linker is invoked on WebAssembly targets
(all of them) to avoid passing the `--allow-undefined` flag to the
linker. Historically, if I remember this correctly, when `wasm-ld` was
first integrated this was practically required because at the time it
was otherwise impossible to import a function from the host into a wasm
binary. Or, at least, I'm pretty sure that was why this was added.

At the time, as the documentation around this option indicates, it was
known that this was going to be a hazard. This doesn't match behavior on
native, for example, and can easily paper over what should be a linker
error with some sort of other obscure runtime error. An example is that
this program currently compiles and links, it just prints null:

    unsafe extern "C" {
        static nonexistent: u8;
    }

    fn main() {
        println!("{:?}", &raw const nonexistent);
    }

This can easily lead to mistakes like rust-lang/libc/4880 and defer what
should be a compile-time link error to weird or unusual behavior at link
time. Additionally, in the intervening time since `wasm-ld` was first
introduced here, lots has changed and notably this program works as
expected:

    #[link(wasm_import_module = "host")]
    unsafe extern "C" {
        fn foo();
    }

    fn main() {
        unsafe {
            foo();
        }
    }

Notably this continues to compile without error and the final wasm
binary indeed has an imported function from the host. What this change
means, however, is that this program:

    unsafe extern "C" {
        fn foo();
    }

    fn main() {
        unsafe {
            foo();
        }
    }

this currently compiles successfully and emits an import from the `env`
module. After this change, however, this will fail to compile with a
link error stating that the `foo` symbol is not defined.
2025-12-10 15:13:14 -08:00
Guillaume Gomez a535c7be54 Ignore more failing ui tests for GCC backend 2025-09-26 15:33:48 +02:00
bjorn3 0711bba9ea Ignore test when dylibs are not supported 2025-08-31 20:43:44 +00:00
bjorn3 fc7de9979e Ensure we emit an allocator shim when only some crate types need one 2025-08-29 08:39:34 +00:00
Oneirical 807d3406c2 Rehome tests/ui/issues/ tests [2/?] 2025-08-02 15:29:16 -04:00
Matthias Krüger 0820cf8c6e Rollup merge of #143908 - Kivooeo:tf0, r=jieyouxu
`tests/ui`: A New Order [0/28]

> [!NOTE]
>
> Intermediate commits are intended to help review, but will be squashed prior to merge.

These are the some last tests that didn’t make it into the main twenty-eightology of PRs. Part of rust-lang/rust#133895.

r? ```@jieyouxu```
2025-07-18 14:49:18 +02:00
Kivooeo c0597fbd80 cleaned up some tests
Reverting file name weird-exprs.rs due to its historical use, recognition in community and references
2025-07-17 15:51:32 +05:00
usamoi 5bb6b9db30 remove no_gc_sections 2025-07-17 14:54:52 +08:00
Kivooeo b7d024b056 moved tests 2025-07-14 02:28:43 +05:00
usamoi f58accb8f3 pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests 2025-07-13 16:27:47 +08:00
Matthias Krüger b11e9e31dd Rollup merge of #143446 - usamoi:export-executable-symbols, r=bjorn3,oli-obk
use `--dynamic-list` for exporting executable symbols

closes rust-lang/rust#101610
cc rust-lang/rust#84161

https://sourceware.org/binutils/docs-2.39/ld/VERSION.html:

> --dynamic-list=dynamic-list-file
Specify the name of a dynamic list file to the linker. This is typically used when creating shared libraries to specify a list of global symbols whose references shouldn’t be bound to the definition within the shared library, or creating dynamically linked executables to specify a list of symbols which should be added to the symbol table in the executable. This option is only meaningful on ELF platforms which support shared libraries.

`ld.lld --help`:

>   --dynamic-list=<file>: Similar to --export-dynamic-symbol-list. When creating a shared object, this additionally implies -Bsymbolic but does not set DF_SYMBOLIC

>  --export-dynamic-symbol-list=file: Read a list of dynamic symbol patterns. Apply --export-dynamic-symbol on each pattern

>  --export-dynamic-symbol=glob: (executable) Put matched symbols in the dynamic symbol table. (shared object) References to matched non-local STV_DEFAULT symbols shouldn't be bound to definitions within the shared object. Does not imply -Bsymbolic.

>  --export-dynamic: Put symbols in the dynamic symbol table

Use `--dynamic-list` because it's older than `--export-dynamic-symbol-list` (binutils 2.35)

try-job: dist-i586-gnu-i586-i686-musl
2025-07-10 20:28:46 +02:00
usamoi bf6d29d558 use --dynamic-list for exporting executable symbols 2025-07-09 22:40:11 +08:00
Rémy Rakic e32b1d7126 expand -Clink-self-contained tests
- update existing tests for stabilization
- ensure `-Clink-self-contained=-linker` is only stable on x64 linux
- test invalid `-Clink-self-contained` components
2025-07-08 10:24:10 +00:00
Rémy Rakic 856c662567 expand -Clinker-features tests
- ensure only `-Clinker-features=-lld` is stabilized, and only on x64
  linux
- test `-Clinker-features` unstable values
2025-07-08 09:30:44 +00:00
Kivooeo 3380a91f5b cleaned up some tests 2025-06-08 01:14:05 +05:00
Jieyou Xu a716f1a523 Add some negative test coverage for -Zlinker-features flag 2025-05-15 16:47:18 +08:00
Jieyou Xu 3e051afec7 Add some negative test coverage for malformed -Clink-self-contained flags 2025-05-15 16:47:17 +08:00
Vadim Petrochenkov 842858f765 linker: Quote symbol names in .def files
To support weird symbol names, including dots in particular.
2025-05-02 16:25:00 +03:00
usamoi b1a38313cb set subsections_via_symbols for ld64 helper sections 2025-04-25 01:41:25 +08:00
Jakub Beránek 9ec11c246d Move link-self-contained-consistency test to a more reasonable location 2025-04-03 15:41:38 +02:00
Jakub Beránek 7bf4e9977e Add test for garbage collection of encapsulation symbols 2025-03-08 19:03:49 +01:00