18875 Commits

Author SHA1 Message Date
Luuk de Gram
cb28fc2e63 wasm-linker: Resolve symbols from archives
Lazily load object files by default, and only load the object file
when an unresolved symbol has been found within an archive.
2022-06-24 08:12:17 +02:00
Luuk de Gram
0606fbbc4b wasm-linker: Implement Archive parsing
This implements a very basic archive file parser that validates
the magic bytes, and then parses the symbol table and stores
the symbol and their position.
2022-06-24 08:12:17 +02:00
Luuk de Gram
4d3715d89f wasm-linker: de-duplicate functions+atom sorting
Multiple symbols can point to the same function, this means that when we loop over
the symbol list, we must deduplicate those functions being added twice.
Additionaly, we must also ensure that when we append a new type and set the type
index on a function, we must not do this again for the same function.

This commit also implements sorting of code atoms to ensure their order matches
the order of the function section to ensure the function signature matches
that of the function body.
2022-06-24 08:12:17 +02:00
Luuk de Gram
8d03e4fc6b link: Implement API to get global symbol index 2022-06-24 08:12:17 +02:00
Luuk de Gram
359b61aec3 wasm: Create compiler-rt symbols and lowering
Implements the creation of an undefined symbol for a compiler-rt intrinsic.
Also implements the building of the function call to said compiler-rt intrinsic.
2022-06-24 08:12:17 +02:00
Jakub Konka
291c08f7b0
Merge pull request #11910 from ziglang/linker-tests 2022-06-24 00:02:12 +02:00
FlandreScarlet
87d8cb19e4
std.debug: fix ConfigurableTrace.dump OOB
The for-loop in dump() would index out of bounds if `t.index` is greater
than size, because `end` is the maximum of `t.index` and `size` rather than the
minimum.
2022-06-23 15:07:08 +03:00
Jakub Konka
03ddb42b8b link-tests: rename check() to checkStart()
Do not hardcode the symtab label; instead allow each parser to define
its own.

Check for missing extractor value in the matcher when matching `{}`.
2022-06-23 13:16:03 +02:00
Jakub Konka
6e04c2faab link-tests: fix parsing symtab for macho 2022-06-23 13:16:03 +02:00
Jakub Konka
4497e422f0 macho: fix aligning linkedit sections
Align by file offsets and not file size.
2022-06-23 13:16:00 +02:00
Jakub Konka
ab8a670a57 link-tests: enable on macos CI host only for now 2022-06-22 23:04:47 +02:00
Jakub Konka
e6c012c743 link-tests: add better docs 2022-06-22 22:40:05 +02:00
Jakub Konka
51f2442fc4 link-tests: clean up error messages in case of failure 2022-06-22 22:24:52 +02:00
Jakub Konka
ba768614ac link-tests: frameworks example can test for libobjc autolink in safety modes 2022-06-22 18:51:35 +02:00
Jakub Konka
b35e434cae link-tests: clean up linker testing harness 2022-06-22 18:34:39 +02:00
frmdstryr
6de0c622ff Add missing adddf3
```
LLD Link... ld.lld: error: undefined symbol: __aeabi_dadd
>>> referenced by errol.zig:366 (/home/usr/projects/zig/build/lib/zig/std/fmt/errol.zig:366)
```
2022-06-22 14:32:52 +02:00
Jakub Konka
211de9b63b link-tests: fix dumping of LOAD_DYLIB: name instead of path field 2022-06-22 10:40:10 +02:00
Jakub Konka
23a63f4ce4 link-tests: rename CheckMachOStep to CheckObjectStep and accept obj format 2022-06-22 10:27:51 +02:00
Jakub Konka
b5601a2da6 link-tests: extract values into variables
We can then collect multiple variables (currently assumed always
in global scope) and run a comparison with some very basic
arithmetic on the values.
2022-06-22 00:49:22 +02:00
Jakub Konka
3bb4d65b2f link-tests: move macho tests to subfolder
Handle `-e` option in MachO linker allowing the user to set a custom
entrypoint address.
2022-06-21 23:01:09 +02:00
Jakub Konka
937464f398 link-tests: dump metadata to string and grep results
This approach is more inline with what LLVM/LLD does for testing
of their output, and seems to be more generic and easier to extend
than implementing a lot of repetitive and nontrivial comparison
logic when working directly on structures.
2022-06-21 22:19:57 +02:00
Jakub Konka
5fbdfb3f34 link-tests: add CheckMachOStep
CheckMachOStep specialises CheckFileStep into directed (surgical)
MachO file fuzzy searches. This will be the building block for
comprehensive MachO linker tests.
2022-06-21 15:44:24 +02:00
Veikka Tuominen
d980c6a38d
Merge pull request #11899 from Vexu/stage2
Stage2: fixes for std tests
2022-06-21 13:56:38 +03:00
Jonathan Marler
ca98625789
std.os.execvpe: fix buffer overflow
The NameTooLong check isn't taking the sentinel 0 into account which
would result in a buffer overflow on the stack.
2022-06-21 11:21:45 +02:00
Jakub Konka
2d09540a63 link-tests: test pagezero_size option for macho 2022-06-20 18:25:20 +02:00
Jakub Konka
6e56a8df20 link-tests: CheckFileStep to do grep test on the binary 2022-06-20 17:59:17 +02:00
Jakub Konka
38edef35bf test: introduce link(er) tests - builds on standalone tests 2022-06-20 17:59:17 +02:00
Jakub Konka
74ed7c1f09
Merge pull request #11875 from motiejus/pagezero-size
[MachO] add -pagezero_size
2022-06-20 17:51:20 +02:00
Veikka Tuominen
d0d5052b39 std.fmt: update test to stage2 fn pointer semantics 2022-06-20 16:12:40 +03:00
Jakub Konka
8752db3285 macho: -pagezero_size is always in hex
This matches the behavior of other linkers out there including
`ld64` and `lld`.
2022-06-20 14:26:59 +02:00
Veikka Tuominen
38a1222c87 std.crypto: fix invalid pass by value 2022-06-20 15:11:22 +03:00
Jakub Konka
753e2b8639 macho: verbose print pagezero size if specified 2022-06-20 13:52:39 +02:00
Jakub Konka
ea9b7a0626 macho: round down pagezero size to page size
If page aligned requested pagezero size is 0, skip generating
__PAGEZERO segment.

Add misc improvements to the pipeline, and correctly transfer the
requested __PAGEZERO size to the linker.
2022-06-20 13:39:33 +02:00
Motiejus Jakštys
98138ba78c [MachO] add -pagezero_size
Pass `-pagezero_size` to the MachO linker. This is the final
"unsupported linker arg" that I could chase that CGo uses. After this
and #11874 we may be able to fail on an "unsupported linker arg" instead
of emiting a warning.

Test case:

    zig=/code/zig/build/zig
    CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="$zig cc -target x86_64-macos" CXX="$zig c++ -target x86_64-macos" go build -a -ldflags "-s -w" cgo.go

I compiled a trivial CGo program and executed it on an amd64 Darwin
host.

To be honest, I am not entirely sure what this is doing. This feels
right after reading what this argument does in LLVM sources, but I am by
no means qualified to make MachO pull requests. Will take feedback.
2022-06-20 13:39:33 +02:00
Jakub Konka
a97a39bea6
Merge pull request #11893 from Luukdegram/wasm-sat
stage2: wasm - saturating arithmetic
2022-06-20 08:48:46 +02:00
Jakub Konka
74442f3503
Merge pull request #11847 from ziglang/better-libcompiler_rt 2022-06-20 00:26:39 +02:00
Jakub Konka
1d4dbf8d3c macos: run test-cases single threaded in the CI 2022-06-19 21:08:53 +02:00
Luuk de Gram
4957c7cbbd
wasm: enable passing behavior tests
This also splits the test cases for addition and subtraction as the wasm
backend does not yet provide support for 128bit saturating arithmetic.
2022-06-19 17:27:56 +02:00
Luuk de Gram
a50147bfff
wasm: fixes for signed saturation 2022-06-19 17:26:44 +02:00
Luuk de Gram
05600a6d84
wasm: saturating shift-left for signed integers 2022-06-19 15:50:03 +02:00
Jakub Konka
b4f2c0dcb9 compiler-rt: fix logic for choosing __gnu_{f2h,h2f}_ieee
Similar to wasm32-wasi-musl, Apple targets also want standard
symbol names.
2022-06-19 15:12:08 +02:00
Luuk de Gram
53831442ef
wasm: saturating shift-left for unsigned integers 2022-06-19 14:30:17 +02:00
Luuk de Gram
ce5d934f5f
wasm: saturating add and sub for signed integers 2022-06-19 14:30:17 +02:00
Luuk de Gram
fcd4280a8c
wasm: implement saturating add, sub for unsigned
Implements +| and -| for unsigned integers <= 64 bits.
2022-06-19 14:30:13 +02:00
Jakub Konka
091238254e macho: return from flushModule if building object for static lib 2022-06-18 22:55:55 +02:00
Veikka Tuominen
8f9b31af92 value: handle slices in canMutateComptimeVarState 2022-06-18 20:04:49 +03:00
Andrew Kelley
30ef033693 compiler-rt: fix logic for choosing __gnu_{f2h,h2f}_ieee
wasm32-wasi-musl wants the standard symbol names however Linux requires
the `__gnu_*` flavors. I did not find any authoritative source on what
decides which symbol flavors to use. If we run into more trouble in the
future we can go back to having both.
2022-06-17 20:25:17 -07:00
Andrew Kelley
e4092d4442 stage2: rip out multi-compilation-unit compiler-rt
After doing performance testing, it seems that multi-compilation-unit
compiler-rt did not bring the performance improvements that we expected
it to. The idea is that it makes linking faster, however, it incurred a
cost in the frontend that was not offset by any gains in linking.

Furthermore, the single-object compiler-rt (with -ffunction-sections and
--gc-sections) ends up being fewer bytes on disk and so it's actually
the same or faster linking speed than the multi-compilation-unit
version.

So we are planning to keep using single-compilation-unit compiler-rt for
the foreseeable future, but may experiment with this again in the
future, in which case this commit can be reverted.
2022-06-17 18:34:11 -07:00
Andrew Kelley
2064d86298 update CMakeLists.txt source files 2022-06-17 18:24:57 -07:00
Andrew Kelley
ebab5288c3 compiler-rt: fix aeabi logic
Before, compiler-rt would have the wrong symbols for ARM targets.
2022-06-17 18:22:35 -07:00