31393 Commits

Author SHA1 Message Date
Alex Rønne Petersen
6c1e306484
llvm: Add some missing fnptr alignment specifications in DataLayoutBuilder. 2024-10-20 09:21:17 +02:00
Alex Rønne Petersen
43344833c5
link.Dwarf: Fix function alignment calculation to match the rest of the linker.
In particular, for user-specified alignment values, we need to do
max(user_align, minFunctionAlignment()) to respect the ABI minimum.
2024-10-20 09:21:17 +02:00
Alex Rønne Petersen
762ad4c6f4
link: Use defaultFunctionAlignment() when function alignment is unspecified.
max(user_align, minFunctionAlignment()) is only appropriate when the user has
actually given an explicit, non-zero alignment value.
2024-10-20 09:21:17 +02:00
Alex Rønne Petersen
ef72b91ac2
compiler: Remove uses of defaultFunctionAlignment() in the frontend.
minFunctionAlignment() is something we can know ahead of time for any given
target because it's a matter of ABI. However, defaultFunctionAlignment() is a
matter of optimization and every backend can do it differently depending on any
number of factors. For example, LLVM will base the choice on the CPU model in
its aarch64 backend. So just don't use this value in the frontend.
2024-10-20 09:21:17 +02:00
Alex Rønne Petersen
d2f04e919c
compiler: Update defaultFunctionAlignment()/minFunctionAlignment() for more targets.
defaultFunctionAlignment() can be made more sophisticated over time based on the
CPU model and/or features. For now, I've picked some reasonable values for the
CPUs that are most commonly used in practice. (Values are sourced from LLVM.)
2024-10-20 09:21:17 +02:00
Alex Rønne Petersen
40104f2145
compiler: Disallow function alignment for nvptx and spirv. 2024-10-20 09:21:14 +02:00
gabeuehlein
7b8fc18c66
Sema: fail if analyzing return in noreturn-declared function before coercing undefined
Just switches logic around in coerceExtra to check for returning in a noreturn function before coercing undefined to anything
2024-10-14 15:02:14 +03:00
Andrew Kelley
9fd61f7460 std.MultiArrayList: add clear methods 2024-10-14 03:33:23 -07:00
Andrew Kelley
3bf89f55c2
Merge pull request #21682 from der-teufel-programming/remove-packedintarray
Remove PackedIntArray
2024-10-13 18:46:51 -07:00
tgschultz
ba569bb8e9
Rewrite bit_reader and bit_writer to take advantage of current zig semantics and enhance readability (#21689)
Co-authored-by: Tanner Schultz <tgschultz@tgschultz-dl.tail7ba92.ts.net>
2024-10-13 18:44:42 -07:00
Robin Voetter
e2e79960d2
Merge pull request #21688 from Snektron/spirv-fix
spirv: fix some bitrot
2024-10-13 22:33:03 +02:00
Alex Rønne Petersen
7185ccad14
Merge pull request #21686 from alexrp/glibc-fixes
`glibc`: Emit some fill data for stub symbols, thus giving each a unique address.
2024-10-13 13:00:00 +02:00
David Rubin
e131a2c8e2
implement packed struct equality (#21679) 2024-10-12 20:59:12 -07:00
Robin Voetter
86b88ea7da
spirv: skip range switch tests
This is not yet implemented
2024-10-13 01:58:11 +02:00
Robin Voetter
c1132edd53
spirv: don't generate OpUnreachable after noreturn call
It seems that these are now automatically added to AIR in Sema.
2024-10-13 01:57:35 +02:00
Robin Voetter
973f846251
spirv: implement repeat and dbg_arg_inline 2024-10-13 01:57:06 +02:00
Robin Voetter
3cd19b8884
spirv: don't try to lower types which have no runtime bits 2024-10-13 01:56:33 +02:00
DravenK
ba1331090c
std.Target.Query: fix compilation error (#21669)
closes #21668

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2024-10-12 23:15:11 +00:00
Andrew Kelley
f7c588286d
Merge pull request #21681 from ziglang/reduce-flush
link.Elf: eliminate an O(N^2) algorithm in flush()
2024-10-12 14:39:17 -07:00
Alex Rønne Petersen
87b1f14015
glibc: Align stub symbols to the target word size.
Ideally we'd like to use whatever alignment glibc actually ends up using in the
real libc.so.6. But we don't really have a way of getting at that information at
the moment, and it's not present in the abilist files. I haven't yet seen a
symbol that wasn't word-aligned, though, so I think this should be good enough
for 99% of symbols, if not actually 100%.
2024-10-12 23:01:05 +02:00
Alex Rønne Petersen
7b376b1c54
glibc: Emit some fill data for stub symbols, thus giving each a unique address.
This prevents LLVM from...cleverly...merging all of the global variable stub
symbols that we emit under certain circumstances. This was observed in practice
when using zig-bootstrap for arm-linux-gnueabi(hf).
2024-10-12 23:01:05 +02:00
Krzysztof Wolicki
04c182274c Fix index calculation in WasmPageAllocator 2024-10-12 22:53:02 +02:00
Andrew Kelley
de04a8a1ef std.dynamic_library: update to new elf API 2024-10-12 10:44:17 -07:00
Andrew Kelley
49637f5372 objcopy: check both global and local when remapping 2024-10-12 10:44:17 -07:00
Andrew Kelley
344a21b14f fix 32-bit build 2024-10-12 10:44:17 -07:00
Andrew Kelley
9b0a3942ef objcopy: update for std.elf type safety
the new types make this code seem a bit strange
2024-10-12 10:44:17 -07:00
Andrew Kelley
1ba3fc90be link.Elf: eliminate an O(N^2) algorithm in flush()
Make shared_objects a StringArrayHashMap so that deduping does not
need to happen in flush. That deduping code also was using an O(N^2)
algorithm, which is not allowed in this codebase. There is another
violation of this rule in resolveSymbols but this commit does not
address it.

This required reworking shared object parsing, breaking it into
independent components so that we could access soname earlier.

Shared object parsing had a few problems that I noticed and fixed in
this commit:
* Many instances of incorrect use of align(1).
* `shnum * @sizeOf(elf.Elf64_Shdr)` can overflow based on user data.
* `@divExact` can cause illegal behavior based on user data.
* Strange versyms logic that wasn't present in mold nor lld. The logic
  was not commented and there is no git blame information in ziglang/zig
  nor kubkon/zld. I changed it to match mold and lld instead.
* Use of ArrayList for slices of memory that are never resized.
* finding DT_VERDEFNUM in a different loop than finding DT_SONAME.
  Ultimately I think we should follow mold's lead and ignore this
  integer, relying on null termination instead.
* Doing logic based on VER_FLG_BASE rather than ignoring it like mold
  and LLD do. No comment explaining why the behavior is different.
* Mutating the original ELF symbols rather than only storing the mangled
  name on the new Symbol struct.

I noticed something that I didn't try to address in this commit: Symbol
stores a lot of redundant information that is already present in the ELF
symbols. I suspect that the codebase could benefit from reworking Symbol
to not store redundant information.

Additionally:
* Add some type safety to std.elf.
* Eliminate 1-3 file system reads for determining the kind of input
  files, by taking advantage of file name extension and handling error
  codes properly.
* Move more error handling methods to link.Diags and make them
  infallible and thread-safe
* Make the data dependencies obvious in the parameters of
  parseSharedObject. It's now clear that the first two steps (Header and
  Parsed) can be done during the main Compilation pipeline, rather than
  waiting for flush().
2024-10-12 10:44:17 -07:00
Krzysztof Wolicki
8a4bcc4ec3 Change (read/write)PackedInt to (read/write)PackedIntNative in aro/Preprocessor 2024-10-12 17:59:41 +02:00
Krzysztof Wolicki
b1eaed6c8d Remove packed_int_array usage from WasmPageAllocator and BigInt 2024-10-12 12:55:35 +02:00
Krzysztof Wolicki
278eb06b98 Remove PackedIntArray usage from bundled Aro 2024-10-12 12:00:36 +02:00
Krzysztof Wolicki
ce27ae1c68 Remove packed_int_array.zig from std 2024-10-12 12:00:09 +02:00
Jakub Konka
7e530c13b3 macho: create dummy atom of size 0 marking end of a section
Some compilers such as Go reference the end of a section (addr + size)
which cannot be contained in any non-zero atom (since then this atom
would exceed section boundaries). In order to facilitate this behaviour,
we create a dummy zero-sized atom at section end (addr + size).
2024-10-12 02:53:15 -07:00
Krzysztof Wolicki
008acd0547
Replace tidy with superhtml as HTML validator (#21664)
Also add `$HOME/local/bin` to `PATH` in linux CI
2024-10-11 21:27:30 -07:00
poypoyan
0367f18cb9
std.mem.readVarInt: assert ReturnType is large enough (#20946)
Fixes #20521
2024-10-11 19:32:10 +00:00
Andrew Kelley
13fb68c064 link: consolidate diagnostics
By organizing linker diagnostics into this struct, it becomes possible
to share more code between linker backends, and more importantly it
becomes possible to pass only the Diag struct to some functions, rather
than passing the entire linker state object in. This makes data
dependencies more obvious, making it easier to rearrange code and to
multithread.

Also fix MachO code abusing an atomic variable. Not only was it using
the wrong atomic operation, it is unnecessary additional state since
the state is already being protected by a mutex.
2024-10-11 10:36:19 -07:00
Andrew Kelley
5e53203e82
Merge pull request #21666 from ziglang/reduce-flush
link.Elf: fix phdr_gnu_stack_index not included in sortPhdrs
2024-10-11 10:34:17 -07:00
Andrew Kelley
38458c6f70 work around C backend bug 2024-10-11 10:33:54 -07:00
Andrew Kelley
05157e820a link.Elf.sortShdrs: tease out data dependencies
In order to reduce the logic that happens in flush() we need to see
which data is being accessed by all this logic, so we can see which
operations depend on each other.
2024-10-11 10:33:54 -07:00
Andrew Kelley
7b69738a06 link.Elf: fix merge sections namespacing
`link.Elf.merge_section.MergeSection` -> `link.Elf.Merge.Section`
2024-10-11 10:33:54 -07:00
Andrew Kelley
2c4e05eda7 link.Elf: group section indexes
so they cannot be forgotten when updating them after sorting them.
2024-10-11 10:33:54 -07:00
Andrew Kelley
c3148988a3 link.Elf.ZigObject: make resetShdrIndexes non generic 2024-10-11 10:33:54 -07:00
Andrew Kelley
4669269673 link.Elf: fix phdr_gnu_stack_index not included in sortPhdrs
Adds type safety for program header indexes.

Reduce the amount of state sortPhdrs has access to, helping make the
data dependencies clear.
2024-10-11 10:33:54 -07:00
Andrew Kelley
ec67d6e03a std.MultiArrayList: add empty initalizer value 2024-10-11 10:33:54 -07:00
Jan200101
41dbd0d0da cmake: correct PIE support detection, add error output for debugging
`check_pie_supported` only uses the `OUTPUT_VARIABLE` to to signify errors
if PIE is actually supported is signaled by `CMAKE_<lang>_LINK_PIE_SUPPORTED`.

Checking if `OUTPUT_VARIABLE` is empty is not enough either since the check
is bypassed if its results are cached but the output variable is not cached.
2024-10-11 17:07:54 +02:00
Jean-Baptiste "Jiboo" Lepesme
901f344be2 IoUring: fix an issue in tests where InvalidVersion might get thrown by skipKernelLessThan, due to some kernel versions not being SemVer compliant. 2024-10-11 17:07:34 +02:00
YANG Xudong
a9a88aa428 add loongarch valist support 2024-10-11 02:49:00 -07:00
Andrew Kelley
1340565e22
Merge pull request #21654 from ziglang/embrace-path-abstraction
link: fix false positive crtbegin/crtend detection
2024-10-10 22:30:04 -07:00
Alex Rønne Petersen
92ae5818d2 musl: Align _init/_fini symbols correctly on arm.
See upstream patch: https://www.openwall.com/lists/musl/2024/10/10/4
2024-10-11 03:20:39 +02:00
Alex Rønne Petersen
2309d07e20 std.os.linux: Use the Thumb-specific syscall helpers for thumbeb too.
Fixes a "write to reserved register r7" compile error for thumbeb-linux-*.
2024-10-11 02:38:30 +02:00
Andrew Kelley
2857a3bcb6 link.Elf tests: update for new static lib behavior
the new code in this branch correctly only stores basenames in the
static archive; update the test to reflect that.
2024-10-10 14:21:52 -07:00