15698 Commits

Author SHA1 Message Date
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
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
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
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
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
mlugg
8d5ac6bdea
Sema: add and improve some callconv compile errors 2024-10-19 19:46:07 +01:00
mlugg
73f4c68005
x86_64: handle incoming stack alignment 2024-10-19 19:46:07 +01:00
mlugg
387965a696
x86_64,riscv64: fix incorrect incoming_stack_alignment handling
The whole motivation behind this proposal in the first place was that
the LLVM backend disagrees with the self-hosted backends on what
`@setAlignStack` meant, so we can't just translate the old logic to the
new system! These backends can introduce support for overriding
`incoming_stack_alignment` later on.
2024-10-19 19:46:06 +01:00
mlugg
289b2f82c3
llvm: fix lowering arm_aapcs_vfp functions 2024-10-19 19:21:33 +01:00
mlugg
28cb887275
Zcu: correct callconvSupported for self-hosted aarch64 2024-10-19 19:21:33 +01:00
mlugg
3ef8bb6354
llvn: fix incorrect mips64 callconv handling 2024-10-19 19:21:32 +01:00
mlugg
1d1e8e1105
link.Dwarf: handle avr_signal and avr_builtin callconvs 2024-10-19 19:21:32 +01:00
mlugg
1f11eed3d1
llvm: fix lowering of avr_interrupt and m68k_interrupt callconvs 2024-10-19 19:21:32 +01:00
mlugg
0b786059b5
compiler: avoid unreasonable eval branch quotas
Using `@FieldType` (#21702).
2024-10-19 19:21:17 +01:00
mlugg
d466c08e05
Sema: minor cleanup 2024-10-19 19:15:24 +01:00
mlugg
cb48376bec
cbe,translate-c: support more callconvs
There are several more that we could support here, but I didn't feel
like going down the rabbit-hole of figuring them out. In particular,
some of the Clang enum fields aren't specific enough for us, so we'll
have to switch on the target to figure out how to translate-c them. That
can be a future enhancement.
2024-10-19 19:15:24 +01:00
mlugg
a2c519ba67
link: add clarifying comment 2024-10-19 19:15:24 +01:00
mlugg
2d9a167cd2
std.Target: rename defaultCCallingConvention and Cpu.Arch.fromCallconv 2024-10-19 19:15:23 +01:00
mlugg
4be0cf30fc
test: update for CallingConvention changes
This also includes some compiler and std changes to correct error
messages which weren't properly updated before.
2024-10-19 19:15:23 +01:00
mlugg
ec19086aa0
compiler: remove @setAlignStack
This commit finishes implementing #21209 by removing the
`@setAlignStack` builtin in favour of `CallingConvention` payloads. The
x86_64 backend is updated to use the stack alignment given in the
calling convention (the LLVM backend was already updated in a previous
commit).

Resolves: #21209
2024-10-19 19:15:23 +01:00
mlugg
bc797a97b1
std: update for new CallingConvention
The old `CallingConvention` type is replaced with the new
`NewCallingConvention`. References to `NewCallingConvention` in the
compiler are updated accordingly. In addition, a few parts of the
standard library are updated to use the new type correctly.
2024-10-19 19:15:23 +01:00
mlugg
51706af908
compiler: introduce new CallingConvention
This commit begins implementing accepted proposal #21209 by making
`std.builtin.CallingConvention` a tagged union.

The stage1 dance here is a little convoluted. This commit introduces the
new type as `NewCallingConvention`, keeping the old `CallingConvention`
around. The compiler uses `std.builtin.NewCallingConvention`
exclusively, but when fetching the type from `std` when running the
compiler (e.g. with `getBuiltinType`), the name `CallingConvention` is
used. This allows a prior build of Zig to be used to build this commit.
The next commit will update `zig1.wasm`, and then the compiler and
standard library can be updated to completely replace
`CallingConvention` with `NewCallingConvention`.

The second half of #21209 is to remove `@setAlignStack`, which will be
implemented in another commit after updating `zig1.wasm`.
2024-10-19 19:08:59 +01:00
Andrew Kelley
8504e1f550
Merge pull request #21610 from alexrp/riscv-abis
Fix some RISC-V ABI issues and add ILP32/LP64 (soft float) to module tests
2024-10-17 12:54:44 -07:00
Alex Rønne Petersen
549a7eba40
std.Target: Rename OS version range functions to drop the "get" prefix. 2024-10-16 22:25:29 +02:00