aboutsummaryrefslogtreecommitdiff
path: root/test/link/elf.zig
AgeCommit message (Collapse)Author
4 daysupdate test-link to new std.Io APIAndrew Kelley
4 daystest: std.fs.File -> std.Io.FileAndrew Kelley
2025-11-19test: disable test-link on big-endian hostsAlex Rønne Petersen
https://github.com/ziglang/zig/issues/25961
2025-11-05zig fmt: fix extra whitespace in StructInit with multiline stringsskewb1k
68d2f68ed introduced special handling for StructInit fields containing multiline strings to prevent inserting whitespace after =. However, this logic didn't handle cases without a trailing comma, which resulted in unwanted trailing whitespace.
2025-09-22test: disable test-link on FreeBSDalexrp
https://github.com/ziglang/zig/issues/25323
2025-09-17Elf: implement `linksection`Jacob Young
Closes #24330
2025-07-26Migrate from deprecated `Step.Compile` APIsCarl Å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-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-25correct some bugsDavid Rubin
2025-02-22zig build fmtAndrew Kelley
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-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.
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-08link tests: add a way to check prefix and use itAndrew Kelley
2024-10-08link.Elf: avoid needless file system reads in flush()Andrew Kelley
flush() must not do anything more than necessary. Determining the type of input files must be done only once, before flush. Fortunately, we don't even need any file system accesses to do this since that information is statically known in most cases, and in the rest of the cases can be determined by file extension alone. This commit also updates the nearby code to conform to the convention for error handling where there is exactly one error code to represent the fact that error messages have already been emitted. This had the side effect of improving the error message for a linker script parse error. "positionals" is not a linker concept; it is a command line interface concept. Zig's linker implementation should not mention "positionals". This commit deletes that array list in favor of directly making function calls, eliminating that heap allocation during flush().
2024-09-04elf: fix emitting static lib when ZigObject is presentJakub Konka
2024-09-04test/link/elf: test --gc-sections on Zig input with LLVM tooJakub Konka
2024-08-27lib,test,tools,doc: update usages of @exportmlugg
2024-08-23std.{coff,elf}: Remove the {MachineType,EM}.toTargetCpuArch() functions.Alex Rønne Petersen
These are fundamentally incapable of producing accurate information for reasons I've laid out in #20771. Since our only use of these functions is to check that object files have the correct machine type, and since #21020 made `std.Target.to{Coff,Elf}Machine()` more accurate, just switch these checks over to that and compare the machine type tags instead. Closes #20771.
2024-08-21link/elf: simplify how we test thunksJakub Konka
2024-08-15test/elf: enhance testImportingDataDynamicJakub Konka
2024-07-30elf: simplify output section tracking for symbolsJakub Konka
2024-07-30elf: resolve COMDATs in more parallel-friendly wayJakub Konka
2024-07-30test/link/elf: test COMDAT eliminationJakub Konka
2024-04-20link/elf: populate current Zig version in .comment; testJakub Konka
2024-04-20test/link/elf: add merge strings test for -r modeJakub Konka
2024-04-20test/link/elf: enhance merge strings testsJakub Konka
2024-04-20link/elf: remove link.link.build as unused; add some merge strings testsJakub Konka
2024-03-13test/link/elf: do not check for $thunk in thunks tests for nowJakub Konka
Andrew and I have discovered that on Linux max peak rss value is taken to be `max(build_runner, test_suite)` and since the thunks test emit a huge binary, we will easily exceed the declared maximum for any of the test suites. This can be worked around for now by not checking for $thunk symbols in this test since it doesn't really yield any additional information; however ideally we would implement per-thread local temp arena that can be freed.
2024-03-12elf+aarch64: fix off-by-one in converging on groups interleaved with thunksJakub Konka
2024-03-12elf+aarch64: actually write out thunks, and add a proper link testJakub Konka
2024-03-11std.builtin: make global linkage fields lowercaseTristan Ross
2024-03-10test/link/elf: remove pie hack due to QEMU bug that is now fixedJakub Konka
2024-03-09test/link/elf: enable tests for aarch64 cpu archJakub Konka
2024-02-21test/link/elf: test static linking C riscv64-muslJakub Konka
2024-02-21test/link/elf: test static linking C aarch64-muslJakub Konka
2024-01-24test/link/link: pass build options to elf and macho testsJakub Konka
2024-01-24test/link/elf: make invalid input file test less jankyJakub Konka