14479 Commits

Author SHA1 Message Date
Andrew Kelley
4e61af404e stage2: Cache system handles shared objects
Fixes #9139
Fixes #9187
2021-06-29 14:25:04 -07:00
Andrew Kelley
6ba6b98b72 std add fs.File.setLock
Windows implementation is still missing.
2021-06-29 14:25:04 -07:00
Jakub Konka
2c385e58f9
Merge pull request #9242 from ziglang/zld-link-system-libsystem-when-native
zld: link against system libSystem when available
2021-06-28 21:06:12 +02:00
Jakub Konka
9b5a463111 zld: if libSystem.dylib found, then need to link libc.dylib too 2021-06-28 17:42:59 +02:00
Jakub Konka
eca12b74b8 zld: recurse dylibs reexports when defined and desired 2021-06-28 15:14:50 +02:00
Jakub Konka
5aff1d5d6f zld: frameworks do not need dylib ext on older macs 2021-06-28 12:17:26 +02:00
Andrew Kelley
6d47b4f39e Revert "Include package root dir in stage2 error messages"
This reverts commit 15a030ef3d2d68992835568f2fb9d5deab18f39f.

ast-check started crashing after this commit. Needs more QA before
merging.
2021-06-27 17:30:29 -07:00
J.C. Moyer
15a030ef3d Include package root dir in stage2 error messages 2021-06-27 14:53:46 +03:00
Isaac Freund
f398ac3ee4 std/fmt: add fmtDurationSigned
When working with durations it often makes sense to use signed integers
and allow negative durations, and there is currently no nice way to
format these in std.fmt. This patch adds a simple wrapper for the
existing fmtDurtion to fit this need.
2021-06-27 12:54:31 +03:00
g-w1
ef56e42a2a
stage2: fix unreachable in union(enum) with anytype payload 2021-06-27 12:26:29 +03:00
Evan Haas
3be682bac9
translate-c: Add documentation for zig translate-c 2021-06-27 12:25:32 +03:00
Jakub Konka
b94787afd7 zld: link against system libSystem.tbd
when native OS _and_ `libSystem.tbd` can be found. Otherwise,
fallback to linking against Zig-provided `lib/libc/darwin/libSystem.B.tbd`.
2021-06-26 10:11:39 +02:00
Emil Lerch
2ac769eab9 allow json scientific notation to coerce to integers as long as they actually resolve to int type 2021-06-26 10:10:36 +03:00
Robin Voetter
dacc5e624e Export isValidId, remove pub on unexported functions 2021-06-26 09:59:40 +03:00
Andrew Kelley
1534cd2f88
Merge pull request #9148 from marler8997/windowsChildOutput
finish ChildProcess collectOutputWindows
2021-06-25 21:42:18 -04:00
Jakub Konka
7a85dc6935
Merge pull request #9202 from ifreund/sysroot
stage2: add --sysroot link option
2021-06-25 22:37:46 +02:00
Andrew Kelley
73f77f3080 AstGen: fix O(N^2) perf for many decls with same parent
AstGen was calling findLineColumn() for every sibling Decl, using the
parent Decl as the starting point for the search for newlines. This
resulted in poor performance for large numbers of Decls with the same
parent.

The solution is simple: since AstGen progresses monotonically through
the AST, keep a single cursor into the source file, and whenever
line/column information is needed, advance the cursor. This guarantees
O(N) on the number of bytes in the file.

Perf:
As an example I ran ast-check on zigwin32/win32/everything.zig
(a 17 MiB file) in master branch, and after this commit.
With master branch, I killed the process after 17 seconds out of
boredom. With this commit, it completed in 300 milliseconds.

Closes #9234
2021-06-25 12:58:21 -07:00
Jakub Konka
49b3986417 zld: fix section mapping for Go specific sections
which include:
* `__TEXT,__rodata` => `__DATA_CONST,__const`
* `__TEXT,__typelink` => `__DATA_CONST,__const`
* `__TEXT,__itablink` => `__DATA_CONST,__const`
* `__TEXT,__gosymtab` => `__DATA_CONST,__const`
* `__TEXT,__gopclntab` => `__DATA_CONST,__const`

Also, we treat section as containing machine code and mapping
it to `__TEXT,__text` if it is `S_REGULAR` and contains either
`S_ATTR_PURE_INSTRUCTIONS` or `S_ATTR_SOME_INSTRUCTIONS` or both.
2021-06-25 20:32:58 +02:00
Isaac Freund
f9171bf542
std/build: add --sysroot general option 2021-06-25 19:13:43 +02:00
Isaac Freund
260c5aed86
stage2: add --sysroot link option
This feature is necessary for cross-compiling code that dynamically
links system libraries, at least with the current feature set of lld.
2021-06-25 19:13:43 +02:00
xackus
411f9c60b1 mark tsan as linguist-vendored 2021-06-25 12:46:23 +03:00
Tom Maenan Read Cutting
177b1b6bf9 Add fat/universal dylib support to zig ld
With this change zig ld can link with dynamic libraries
contained within a fat/universal file that had multiple
seperate binaries embedded within it for multi-arch
support (in macOS).

Whilst zig can still only create single-architecture
executables - the ability to link with fat libraries is
useful for cases where they are the easiest (or only)
option to link against.
2021-06-25 08:38:47 +02:00
Jacob G-W
2d2a6ed1a4 stage2: implement @setRuntimeSafety 2021-06-25 08:57:03 +03:00
Jacob G-W
4adcd560ce langref: make @setRuntimeSafety more correct 2021-06-25 08:57:03 +03:00
Jakub Konka
350ead9cb2
Merge pull request #9229 from ziglang/zld-objc-frameworks
zig ld: link Obj-C, link frameworks, improve linker's implementation
2021-06-25 07:51:21 +02:00
Jakub Konka
ddd2cd7330 zld: fix Dylib.Id parsing logic for string values 2021-06-24 23:34:31 +02:00
Jakub Konka
264f5f4544 Apply AST fixes 2021-06-24 23:08:24 +02:00
Jakub Konka
8fc5b5a087 zld: put DICE and CodeSig load commands last
after `LC_LOAD_DYLIB` commands to match ld64 and make the binaries
compatible with Apple tools.
2021-06-24 22:40:19 +02:00
Jakub Konka
ad0be78577 zld: parse dylib's id from tbd 2021-06-24 22:19:44 +02:00
Jakub Konka
5e0e7b2cb4 zld: exclude libs part of the umbrella
when parsing the umbrella lib
2021-06-24 20:27:23 +02:00
Jakub Konka
8669e3d46b zld: when parsing dylibs, allow multiple return values 2021-06-24 18:57:21 +02:00
Jakub Konka
5ac5cd9de7 zld: naively parse all dylib deps in stubs 2021-06-24 18:57:11 +02:00
Jakub Konka
3cb6b6bd90 zld: merge Stub with Dylib struct
After giving it more thought, it doesn't make sense to separate
the two structurally. Instead, there should be two constructors
for a Dylib struct: one from binary file, and the other from a stub
file. This cleans up a lot of code and opens the way for recursive
parsing of re-exports from a dylib which are a hard requirement for
native feel when linking frameworks.
2021-06-24 18:57:04 +02:00
Jakub Konka
3f57468c8b Classify .m as ObjC, compile using clang and link with zld 2021-06-24 18:56:56 +02:00
Jakub Konka
52a9d3f037 zld: clean up memory management and refactor 2021-06-24 18:56:48 +02:00
Jakub Konka
1ff3ebffa3 zld: handle dynamic binding of proxies for objc correctly 2021-06-24 18:56:41 +02:00
Jakub Konka
0736365fa4 zld: fix finding pointers for rebasing 2021-06-24 18:56:33 +02:00
Jakub Konka
d1fcb99848 zld+macho: populate segname from SegmentCommand when adding section 2021-06-24 18:56:17 +02:00
Jakub Konka
a480ae6e37 zld: handle objc-specific sections 2021-06-24 18:56:09 +02:00
Jakub Konka
5f9b4cba6d zld: clean up logic for matching and mapping sections 2021-06-24 18:55:43 +02:00
Jakub Konka
852e1ed23c zld+stage2: refactor creating segments and sections
Move the logic into default-init structs part of constructors in
`SegmentCommand` struct in `commands.zig` module.
2021-06-24 18:53:42 +02:00
Jakub Konka
72f2f68938 zld: parse framework dirs and names 2021-06-24 18:53:28 +02:00
Jakub Konka
8216ce6789
Merge pull request #9171 from ziglang/zld-tapi
zld: add TAPI parser for linkers, ship libSystem.B.tbd with Zig, and parse tbd stubs on macOS
2021-06-24 18:41:33 +02:00
Jakub Konka
cea8a2f500 tapi: apply ast fixes 2021-06-24 15:01:14 +02:00
Jakub Konka
b55a3cefa4 zld: extract path to libc in the linker proper 2021-06-24 14:45:45 +02:00
Jakub Konka
bc78b02c04 zld: introduce Stub.zig which represents parsed stub file
Instead of trying to fit a stub file into the frame of a Dylib struct,
I think it makes more sense to keep them as separate entities with
possibly shared interface (which would be added in the future).

This cleaned up a lot of logic in Dylib as well as Stub. Also, while
here I've made creating actual *Symbols lazy in the sense Dylib and
Stub only store hash maps of symbol names that they expose but we
defer create and referencing given dylib/stub until link time when
a symbol is actually referenced. This should reduce memory usage
and speed things up a bit.
2021-06-24 14:45:45 +02:00
Jakub Konka
09b46198ff zld: move logic unpacking path to libc stub to Compilation 2021-06-24 14:45:45 +02:00
Jakub Konka
a600d41880 zld: apply AST fixes 2021-06-24 14:45:45 +02:00
Jakub Konka
4854c96bc5 zld: create a synthetic ___dso_handle symbol self-referenced 2021-06-24 14:45:45 +02:00
Jakub Konka
96a0479db2 zld: parse lib stubs as tbds on the linker line 2021-06-24 14:45:45 +02:00