aboutsummaryrefslogtreecommitdiff
path: root/test/link
AgeCommit message (Collapse)Author
2025-09-17Elf: implement `linksection`Jacob Young
Closes #24330
2025-09-16test: move glibc_compat from link to standalone testsAlex Rønne Petersen
This is not really testing the linker.
2025-09-16test: remove @cImport usage in interdependent_static_c_libsAlex Rønne Petersen
2025-07-26Migrate from deprecated `Step.Compile` APIsCarl Åstholm
2025-07-20Update test build.zig.zon files to conform to the new manifest rulesCarl Åstholm
2025-07-07update standalone and incremental tests to new APIAndrew Kelley
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-07-01test: Properly limit glibc_compat versions based on the hostAlex Rønne Petersen
2025-06-19Target: pass and use locals by pointer instead of by valueJacob Young
This struct is larger than 256 bytes and code that copies it consistently shows up in profiles of the compiler.
2025-06-19Build: change how the target is printed in step namesJacob Young
e.g. `x86_64-windows.win10...win11_dt-gnu` -> `x86_64-windows-gnu` When the OS version is the default this is redundant with checking the default in the standard library.
2025-06-12test-link: correct expected object file namemlugg
The name of the ZCU object file emitted by the LLVM backend has been changed in this branch from e.g. `foo.o` to `foo_zcu.o`. This is to avoid name clashes. This commit just updates a link test which started failing because the object name in a linker error changed.
2025-06-06tests: avoid loading 16 MiB onto the stackmlugg
Currently, Zig semantically loads an array as a temporary when indexing it. This means it cannot be guaranteed that only the requested element is loaded; in particular, our self-hosted backends do not elide the load of the full array, so this test case was crashing on self-hosted.
2025-04-26compiler: Allow configuring UBSan mode at the module level.Alex Rønne Petersen
* Accept -fsanitize-c=trap|full in addition to the existing form. * Accept -f(no-)sanitize-trap=undefined in zig cc. * Change type of std.Build.Module.sanitize_c to std.zig.SanitizeC. * Add some missing Compilation.Config fields to the cache. Closes #23216.
2025-03-08test: Disable `test-elf-ld-script-path-error` for now.Alex Rønne Petersen
https://github.com/ziglang/zig/issues/23125
2025-03-05Remove uses of deprecated callconv aliasesLinus Groh
2025-02-25ubsan: update wordingDavid Rubin
2025-02-25build: add comments explaining why we disable ubsanDavid Rubin
2025-02-25correct some bugsDavid Rubin
2025-02-22zig build fmtAndrew Kelley
2025-02-22Merge pull request #22659 from ifreund/linker-script-fixAndrew Kelley
link: fix ambiguous names in linker scripts
2025-02-22link.MachO: Add support for the -x flag (discard local symbols).Alex Rønne Petersen
This can also be extended to ELF later as it means roughly the same thing there. This addresses the main issue in #21721 but as I don't have a macOS machine to do further testing on, I can't confirm whether zig cc is able to pass the entire cgo test suite after this commit. It can, however, cross-compile a basic program that uses cgo to x86_64-macos-none which previously failed due to lack of -x support. Unlike previously, the resulting symbol table does not contain local symbols (such as C static functions). I believe this satisfies the related donor bounty: https://ziglang.org/news/second-donor-bounty
2025-02-10link: fix ambiguous names in linker scriptsIsaac Freund
Currently zig fails to build while linking the system LLVM/C++ libraries on my Chimera Linux system due to the fact that libc++.so is a linker script with the following contents: INPUT(libc++.so.1 -lc++abi -lunwind) Prior to this commit, zig would try to convert "ambiguous names" in linker scripts such as libc++.so.1 in this example into -lfoo style flags. This fails in this case due to the so version number as zig checks for exactly the .so suffix. Furthermore, I do not think that this conversion is semantically correct since converting libfoo.so to -lfoo could theoretically end up resulting in libfoo.a getting linked which seems wrong when a different file is specified in the linker script. With this patch, this attempted conversion is removed. Instead, zig always first checks if the exact file/path in the linker script exists relative to the current working directory. If the file is classified as a library (including versioned shared objects such as libfoo.so.1), zig then falls back to checking if the exact file/path in the linker script exists relative to each directory in the library search path, selecting the first match or erroring out if none is found. This behavior fixes the regression that prevents building zig while linking the system LLVM/C++ libraries on Chimera Linux.
2025-01-22std.Build: add `addLibrary` function (#22554)BratishkaErik
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but linking mode can be changed more easily in build.zig, for example: In library: ```zig const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default const lib = b.addLibrary(.{ .linkage = linkage, .name = "foo_bar", .root_module = mod, }); ``` In consumer: ```zig const dep_foo_bar = b.dependency("foo_bar", .{ .target = target, .optimize = optimize, .linkage = .static // or dynamic }); mod.linkLibrary(dep_foor_bar.artifact("foo_bar")); ``` It also matches nicely with `linkLibrary` name. Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-20reject crti.o/crtn.o, embrace the futureAndrew Kelley
crti.o/crtn.o is a legacy strategy for calling constructor functions upon object loading that has been superseded by the init_array/fini_array mechanism. Zig code depends on neither, since the language intentionally has no way to initialize data at runtime, but alas the Zig linker still must support this feature since popular languages depend on it. Anyway, the way it works is that crti.o has the machine code prelude of two functions called _init and _fini, each in their own section with the respective name. crtn.o has the machine code instructions comprising the exitlude for each function. In between, objects use the .init and .fini link section to populate the function body. This function is then expected to be called upon object initialization and deinitialization. This mechanism is depended on by libc, for example musl and glibc, but only for older ISAs. By the time the libcs gained support for newer ISAs, they had moved on to the init_array/fini_array mechanism instead. For the Zig linker, we are trying to move the linker towards order-independent objects which is incompatible with the legacy crti/crtn mechanism. Therefore, this commit drops support entirely for crti/crtn mechanism, which is necessary since the other commits in this branch make it nondeterministic in which order the libc objects and the other link inputs are sent to the linker. The linker is still expected to produce a deterministic output, however, by ignoring object input order for the purposes of symbol resolution.
2025-01-15test/link/wasm/shared-memory: update to better linker behaviorAndrew Kelley
now it's smarter about omitting tls stuff if there end up being no TLS data sections
2025-01-15wasm linker: change rules about symbol visibilityAndrew Kelley
export by default means export, as expected. if you want hidden visibility then use hidden visibility.
2025-01-15wasm linker: fix TLS data segmentsAndrew Kelley
fix calculation of alignment and size include __tls_align and __tls_size globals along with __tls_base include them only if the TLS segment is emitted add missing reloc logic for memory_addr_tls_sleb fix name of data segments to include only the prefix
2025-01-15tests: remove dead codeAndrew Kelley
2025-01-15test/link/wasm/export-data: update expected behaviorAndrew Kelley
Object being linked has neither functions nor globals named "foo" or "bar" and so these names correctly fail to be exported when creating an executable.
2025-01-15test/wasm/infer-features: update to expected behaviorAndrew Kelley
I intentionally simplified the target features functionality to use the target features that are explicitly specified to the linker and ignore the "tooling conventions" this makes the wasm linker behave the same as ELF, COFF, and MachO.
2025-01-15test/link/wasm/function-table: delete bad testAndrew Kelley
this tests for importing a function table, but the example source does not try to use an imported table, so it's a useless check. it's unclear what the behavior is even supposed to do in this case. the other two cases are left alone.
2025-01-15test/link/wasm/segment: delete bad testAndrew Kelley
- doesn't run the exe - checks for data segment named .rodata which is not a thing - checks for data segment named .bss which is not needed
2025-01-15test/link/wasm/type: remove redundant testsAndrew Kelley
This test passes now, but let's not run it for the other optimization modes since they don't affect linker behavior.
2025-01-15test/wasm/export: delete redundant testsAndrew Kelley
the other optimization modes don't affect linking
2025-01-15delete bad linker test: bssAndrew Kelley
The purpose of this test is unclear. It checks for the existence of bss section which is completely unnecessary since those zeroes can be omitted from the binary. Furthermore the code generated for __wasm_init_memory looks wrong. Finally, the CheckObject DSL is brittle, it only checks for exact matches of entire lines in an ad-hoc text format. Conclusion, it's a bad test, delete it.
2025-01-15wasm linker: implement hidden visibilityAndrew Kelley
2024-12-18compiler: disallow `callconv` etc from depending on function parametersmlugg
Resolves: #22261
2024-12-18test-link: migrate from deprecated std.Build APIsmlugg
2024-12-18std.Build.Step.Compile.Options: change `root_module` field type to `*Module`mlugg
2024-11-24std.Target: Add Os.HurdVersionRange for Os.Tag.hurd.Alex Rønne Petersen
This is necessary since isGnuLibC() is true for hurd, so we need to be able to represent a glibc version for it. Also add an Os.TaggedVersionRange.gnuLibCVersion() convenience function.
2024-10-29link/Elf: ensure we always sort all relocations by r_offset in -r modeJakub Konka
According to a comment in mold, this is the expected (and desired) condition by the linkers, except for some architectures (RISCV and Loongarch) where this condition does not have to upheld. If you follow the changes in this patch and in particular doc comments I have linked the comment/code in mold that explains and implements this. I have also modified `testEhFrameRelocatable` test to now test both cases such that `zig ld -r a.o b.o -o c.o` and `zig ld -r b.o a.o -o d.o`. In both cases, `c.o` and `d.o` should produce valid object files which was not the case before this patch.
2024-10-23more helpful message when testTlsOffsetAlignment failsAndrew Kelley
2024-10-23use deterministic order in relocatable-eh-frame testsAndrew Kelley
This test does not pass in master branch either if you flip the object order around.
2024-10-23split a fat test caseAndrew Kelley
2024-10-23better error messagesAndrew Kelley
2024-10-23introduce a CLI flag to enable .so scripts; default offAndrew Kelley
The compiler defaults this value to off so that users whose system shared libraries are all ELF files don't have to pay the cost of checking every file to find out if it is a text file instead. When a GNU ld script is encountered, the error message instructs users about the CLI flag that will immediately solve their problem.
2024-10-23move ld script processing to the frontendAndrew Kelley
along with the relevant logic, making the libraries within subject to the same search criteria as all the other libraries. this unfortunately means doing file system access on all .so files when targeting ELF to determine if they are linker scripts, however, I have a plan to address this.
2024-10-10link.Elf tests: update for new static lib behaviorAndrew Kelley
the new code in this branch correctly only stores basenames in the static archive; update the test to reflect that.
2024-10-10linker tests: avoid trivially unnecessary allocationAndrew Kelley
2024-10-09test/link/macho: test reporting undefined special symbolsJakub Konka