Commit Graph

31660 Commits

Author SHA1 Message Date
Andrew Kelley
5e11790c7b mutex protect comp.arena in --verbose-link 2024-10-23 16:27:39 -07:00
Andrew Kelley
2530d638d6 more helpful message when testTlsOffsetAlignment fails 2024-10-23 16:27:39 -07:00
Andrew Kelley
504ad56815 link.flushTaskQueue: move safety lock
The safety lock needs to happen after check()
2024-10-23 16:27:39 -07:00
Andrew Kelley
ba71079837 combine codegen work queue and linker task queue
these tasks have some shared data dependencies so they cannot be done
simultaneously. Future work should untangle these data dependencies so
that more can be done in parallel.

for now this commit ensures correctness by making linker input parsing
and codegen tasks part of the same queue.
2024-10-23 16:27:39 -07:00
Andrew Kelley
9a511b4b27 work on compiler_rt and fuzzer libs earlier in the pipeline
don't wait for AstGen and C source files to complete before starting to
build compiler_rt and libfuzzer
2024-10-23 16:27:39 -07:00
Andrew Kelley
989e782a01 link.Elf.ZigObject.updateFunc: reduce data dependencies
Unfortunately it's not a complete solution, so a follow-up commit will
need to do something more drastic like not do the linker task queue at
the same time as codegen task queue.

From that point, it is possible to do more work at the same time but
that should be a separate branch. This one has gotten big enough.
2024-10-23 16:27:39 -07:00
Andrew Kelley
e0623df9f7 Compilation.create: skip libc_installation on darwin
If the "is darwin" check is moved below the libc_installation check
below, error.LibCInstallationMissingCrtDir is returned from
lci.resolveCrtPaths().

This should be revisited because it makes sense to check
libc_installation first even on darwin.

Anyway for now this more closely matches logic from master branch.
2024-10-23 16:27:39 -07:00
Andrew Kelley
f2efe05155 use deterministic order in relocatable-eh-frame tests
This test does not pass in master branch either if you flip the object
order around.
2024-10-23 16:27:39 -07:00
Andrew Kelley
3deb9ab30a use unstable sort in relocatable writeSyntheticSections
unstable sort is always better if you have no ties
2024-10-23 16:27:39 -07:00
Andrew Kelley
336466c9df glibc sometimes makes archives be ld scripts
it is incredible how many bad ideas glibc is bundled into one project.
2024-10-23 16:27:39 -07:00
Andrew Kelley
ccac11196b link.Elf: unstable sort for section headers
using name as tie-breaker.
2024-10-23 16:27:39 -07:00
Andrew Kelley
1c45903274 handle _fltused in compiler_rt
so we don't have to do an entire compilation unit for just this silly
symbol
2024-10-23 16:27:39 -07:00
Andrew Kelley
22948616ff split a fat test case 2024-10-23 16:27:39 -07:00
Andrew Kelley
5d75d8f6fc also find static libc files on the host
and don't look for glibc files on windows
2024-10-23 16:27:39 -07:00
Andrew Kelley
2d8ea78249 link.Elf: remove ZigObject from files
By making it a field of link.Elf, it is now accessible without a data
dependency on `files`, fixing a race condition with the codegen thread
and linker thread.
2024-10-23 16:27:38 -07:00
Andrew Kelley
ab33d2e7a9 add missing check for output mode in tsan logic 2024-10-23 16:27:38 -07:00
Andrew Kelley
3cc19cd865 better error messages 2024-10-23 16:27:38 -07:00
Andrew Kelley
d1ecb742ec don't create unused musl crt objects 2024-10-23 16:27:38 -07:00
Andrew Kelley
de0f7fcf52 unify parsing codepaths between relocatable and non 2024-10-23 16:27:38 -07:00
Andrew Kelley
12f3a7c3c2 fix wasm crt logic 2024-10-23 16:27:38 -07:00
Andrew Kelley
3f6b6b1bcd revert macos target version bump 2024-10-23 16:27:38 -07:00
Andrew Kelley
c2898c436f branch fixes 2024-10-23 16:27:38 -07:00
Andrew Kelley
5ca54036ca move linker input file parsing to the compilation pipeline 2024-10-23 16:27:38 -07:00
Andrew Kelley
2dcfa72376 link.Elf: untangle parseObject and parseArchive
from link.Elf, so that they can be used earlier in the pipeline
2024-10-23 16:27:38 -07:00
Andrew Kelley
b510c5719f refactor Compilation.crtFilePath 2024-10-23 16:27:38 -07:00
Andrew Kelley
353d3023c0 fix windows build 2024-10-23 16:27:38 -07:00
Andrew Kelley
e331e81719 link.Elf: refactor output mode checking 2024-10-23 16:27:38 -07:00
Andrew Kelley
cbcd67ea90 link.MachO: fix missing input classification 2024-10-23 16:27:38 -07:00
Andrew Kelley
65d42086ff CLI: dylibs provided by path act as inferred root module 2024-10-23 16:27:38 -07:00
Andrew Kelley
e2a71b37d8 fix MachO linking regression 2024-10-23 16:27:38 -07:00
Andrew Kelley
8cfe303da9 fix resolving link inputs 2024-10-23 16:27:38 -07:00
Andrew Kelley
7656903518 CLI: fix detection of link inputs 2024-10-23 16:27:38 -07:00
Andrew Kelley
861df93768 link.Elf: fix double free of header in parseDso 2024-10-23 16:27:38 -07:00
Andrew Kelley
e567abb339 rework linker inputs
* Compilation.objects changes to Compilation.link_inputs which stores
  objects, archives, windows resources, shared objects, and strings
  intended to be put directly into the dynamic section. Order is now
  preserved between all of these kinds of linker inputs. If it is
  determined the order does not matter for a particular kind of linker
  input, that item should be moved to a different array.
* rename system_libs to windows_libs
* untangle library lookup from CLI types
* when doing library lookup, instead of using access syscalls, go ahead
  and open the files and keep the handles around for passing to the
  cache system and the linker.
* during library lookup and cache file hashing, use positioned reads to
  avoid affecting the file seek position.
* library directories are opened in the CLI and converted to Directory
  objects, warnings emitted for those that cannot be opened.
2024-10-23 16:27:38 -07:00
Andrew Kelley
4706ec81d4 introduce a CLI flag to enable .so scripts; default off
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-23 16:27:38 -07:00
Andrew Kelley
5b016e290a move ld script processing to the frontend
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-23 16:27:38 -07:00
Andrew Kelley
a4cc344aa0 std.Build.Step.Compile: add a way to expect an error message
other than a compile error, specifically
2024-10-23 16:27:38 -07:00
Andrew Kelley
1e785409bb move link.Elf.LdScript to link.LdScript 2024-10-23 16:27:38 -07:00
Andrew Kelley
028a9a1054 link.Elf.LdScript: eliminate dependency on Elf.File
this allows it to be used by the frontend
2024-10-23 16:27:38 -07:00
Andrew Kelley
33d07f4b6e
Merge pull request #21779 from ziglang/avoid-data-races
link.MachO: remove buggy multi-threading
2024-10-23 16:27:09 -07:00
Andrew Kelley
78f643c46d
Merge pull request #21758 from kcbanner/dll_storage_class
Add `is_dll_import` to @extern, to support `__declspec(dllimport)` with the MSVC ABI
2024-10-23 15:35:54 -07:00
Andrew Kelley
322d71139d link.MachO: remove buggy multi-threading
thread-sanitizer reports data races here when running test-link. I tried
only removing the ones that triggered races, but after 10 back and
forths with the compiler and tsan, I got impatient and removed all of
them.

next time, let's be sure the test suite runs tsan-clean before merging
any changes that add parallelism.

after this commit, `zig build test-link` completes without any tsan
warnings.

closes #21778
2024-10-23 14:08:03 -07:00
Andrew Kelley
d210f733f8 std.Progress: fix data race
In end(), the freelist pointer is owned so the bare store would be ok.
However, there is a load in start() that can happen at the same time, if
another start() and end() pair grabs that same index.

I don't think this fixes #21663 actually because even if the data race
corrupts the value for `next`, the cmpxchg protects the value from being
stored there.
2024-10-23 13:47:44 -07:00
Matthew Lugg
6bf52b0505
Merge pull request #21697 from mlugg/callconv
Replace `std.builtin.CallingConvention` with a tagged union, eliminating `@setAlignStack`
2024-10-23 16:48:33 +01:00
kcbanner
7edd69d8aa tests: add tests for is_dll_import externs
- tests/standalone/extern wasn't running its test step
- add compile error tests for thread local / dll import @extern in a comptime scope
2024-10-22 18:46:14 -04:00
kcbanner
b87fa93500 Change ExternOptions.dll_storage_class to is_dll_import
It wouldn't make sense to have passe `.export` here, and that was
in fact a compile error - so simply make this a bool instead.
2024-10-22 12:41:35 -04:00
kcbanner
a4690ecb1f Cause a compilation error to occur if using @extern with is_dll_import in a comptime scope.
Add a note about thread local / dll import being the cause.
2024-10-22 12:41:35 -04:00
kcbanner
ee25757245 Add support for specifying dll_storage_class in @extern 2024-10-22 12:41:35 -04:00
kcbanner
2d888a8e63 tests: re-enable tests that now pass on aarch64-windows 2024-10-22 11:39:29 +02:00
kcbanner
85d87c9ca1 coff: fix incorrect default image_base values and re-enable shared library tests on Windows
This was the cause of aarch64-windows shared libraries causing  "bad image" errors
during load-time linking. I also re-enabled the tests that were surfacing this bug.
2024-10-21 22:54:52 -07:00