zig/lib/std
Jakub Konka b79884eaf0 macho: implement pruning of unused segments and sections
This is a prelude to a more elaborate work which will implement
`-dead_strip` flag - garbage collection of unreachable atoms. Here,
when sorting sections, we also check that the section is actually
populated with some atoms, and if not, we exclude it from the final
linked image. This can happen when we do not import any symbols
from dynamic libraries in which case we will not be populating
the stubs sections or the GOT table, implying we can skip allocating
those sections. Furthermore, we also make a check that a segment
is actually occupied too, with the exception of `__TEXT` segment
which is non-optional given that it wraps the header and load commands
and thus is required by the `dyld` to perform dynamic linking, and
`__PAGEZERO` which is generally non-optional when the linked image
is an executable. For any other segment, if its section count is
zero, we mark it as dead and skip allocating it and generating
a load command for it.

This commit also includes some minor improvements to the linker such
as refactoring of the segment allocating codepaths, skipping
`__PAGEZERO` generation for dylibs, and skipping generation of zero-sized
atoms for special symbols such as `__mh_execute_header` and `___dso_handle`.
These special symbols are only allocated local and global symbol pair
and their VM addresses is set to the start of the `__TEXT` segment,
but no `Atom` is created, as it's not necessary given that they never
carry any machine code.

Finally, we now always force-link against `libSystem` which turns out
to be required for `dyld` to properly handle `LC_MAIN` load command
on older macOS versions such as 10.15.7.
2022-07-01 22:05:22 +02:00
..
atomic std: replace usage of std.meta.bitCount() with @bitSizeOf() 2022-04-27 11:10:52 +02:00
build link-tests: do not save global extracted var unless a match 2022-06-28 10:23:25 +02:00
c add const to msghdr_const iov and control pointers 2022-06-07 15:23:44 -04:00
compress stage2: make error{} the same size as anyerror 2022-06-11 23:49:33 +03:00
crypto crypto: add the Xoodoo permutation, prepare for Gimli deprecation (#11866) 2022-07-01 13:18:08 +02:00
dwarf wasm: Implement debug info for parameters 2022-05-09 18:51:46 +02:00
event std.event: use .{} to initiate Lock to unlocked state 2022-07-01 00:09:36 +03:00
fmt add more corner case tests to float_parse (#11727) 2022-05-26 22:05:53 -04:00
fs math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
hash std: fix crypto and hash benchmark 2022-04-24 23:01:06 -04:00
heap Move sys_can_stack_trace from GPA to std.debug so that it can be re-used as needed 2022-06-25 21:27:56 -07:00
http std: add http definitions for Method and Status (#10661) 2022-05-11 15:43:18 -04:00
io Sema: add missing set_union_tag 2022-06-12 19:17:41 +03:00
json std.json: Support disabling indent (#11823) 2022-06-29 11:53:01 +02:00
math stage2: lower float negation explicitly 2022-06-30 00:02:00 -07:00
mem Allocator: correct PanicFree function name 2022-05-02 15:29:27 -04:00
meta std.meta.TrailerFlags: improve init type 2022-05-04 21:26:48 +02:00
net LLVM: fix lowering of untagged union types 2022-06-30 02:43:05 -04:00
os zig fmt: fix idempotency with newlines surrounding doc comment 2022-06-28 21:38:28 +02:00
rand crypto: add the Xoodoo permutation, prepare for Gimli deprecation (#11866) 2022-07-01 13:18:08 +02:00
target
testing Move sys_can_stack_trace from GPA to std.debug so that it can be re-used as needed 2022-06-25 21:27:56 -07:00
Thread math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
time
tz
unicode
valgrind
x std.x.os.net: make error set consistent across targets 2022-06-27 18:26:50 -07:00
zig zig fmt: fix idempotency with newlines surrounding doc comment 2022-06-28 21:38:28 +02:00
array_hash_map.zig Sema: solve a false positive "depends on itself" 2022-05-06 22:40:57 -07:00
array_list.zig std.ArrayList: use variable for local mutable state 2022-03-11 22:47:24 -07:00
ascii.zig
atomic.zig std.Thread.Futex improvements (#11464) 2022-04-19 19:42:15 -05:00
base64.zig std.base64: upgrade to new function pointer semantics 2022-03-30 20:38:01 -07:00
bit_set.zig stage2: check that struct is a tuple when value tags differ in eql 2022-06-17 21:04:21 +03:00
bounded_array.zig std/bounded_array.zig: Add Writer interface 2022-04-14 02:56:40 -04:00
buf_map.zig reverse some of the now unneeded changes from squeek 2022-05-11 18:41:23 -06:00
buf_set.zig std.BufSet.clone: fix key ownership 2022-03-01 13:28:47 -05:00
build.zig build: handle weakly imported libs and frameworks 2022-06-28 09:19:01 +02:00
builtin.zig Sema: improve index out of bounds panic message 2022-05-16 17:42:51 -07:00
c.zig std.c: Move Darwin-unspecific functions from std/c/darwin.zig to std/c.zig 2022-05-07 00:02:15 +09:00
child_process.zig math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
coff.zig std.coff: parse out codebase and entrypoint from optionalheader 2022-04-28 18:31:20 +03:00
compress.zig stage2: small fixes + adjustments to std tests 2022-06-11 23:49:33 +03:00
comptime_string_map.zig
crypto.zig crypto: add the Xoodoo permutation, prepare for Gimli deprecation (#11866) 2022-07-01 13:18:08 +02:00
cstr.zig
debug.zig Merge pull request #11919 from squeek502/failing-allocator-stacktrace 2022-06-28 14:44:00 -04:00
dwarf.zig math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
dynamic_library.zig math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
elf.zig target: Rename sparcv9 -> sparc64 2022-05-13 16:43:59 -04:00
enums.zig deprecated TypeInfo in favor of Type 2022-03-08 20:38:12 +02:00
event.zig
fifo.zig
fmt.zig stage2: lower float negation explicitly 2022-06-30 00:02:00 -07:00
fs.zig std.fs: fix incorrect passing of pointer to temporary 2022-06-06 13:11:50 -07:00
hash.zig
hash_map.zig std: fix missing hash map safety 2022-04-20 17:18:06 -07:00
heap.zig std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
http.zig std: add http definitions for Method and Status (#10661) 2022-05-11 15:43:18 -04:00
io.zig stage2: progress towards stage3 2022-04-14 10:12:45 -07:00
json.zig std.json: Support disabling indent (#11823) 2022-06-29 11:53:01 +02:00
leb128.zig
linked_list.zig
log.zig
macho.zig macho: implement pruning of unused segments and sections 2022-07-01 22:05:22 +02:00
math.zig math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
mem.zig mem: add splitBackwards (#11908) 2022-06-29 08:23:09 +02:00
meta.zig std: update tests to stage2 semantics 2022-06-03 20:21:20 +03:00
multi_array_list.zig std.MultiArrayList: add functions addOne, pop, and popOrNull (#11553) 2022-04-29 22:51:53 -04:00
net.zig std: adjust for stage2 semantics 2022-06-07 21:27:07 +03:00
once.zig
os.zig std.os.execvpe: fix buffer overflow 2022-06-21 11:21:45 +02:00
packed_int_array.zig zig fmt: remove trailing whitespace on doc comments 2022-04-05 18:08:33 +03:00
pdb.zig std.pdb: fix incorrect use of packed struct 2022-05-02 22:06:02 -07:00
priority_dequeue.zig
priority_queue.zig Revert "AstGen: preserve inferred ptr result loc for breaks" 2022-06-28 18:38:25 -07:00
process.zig document that on Windows, all key arguments in EnvMap must be valid utf8 2022-05-11 18:41:23 -06:00
Progress.zig std.Progress.log: adjust API 2022-05-26 21:58:19 -07:00
rand.zig crypto: add the Xoodoo permutation, prepare for Gimli deprecation (#11866) 2022-07-01 13:18:08 +02:00
segmented_list.zig std: disable tests that crash stage2 2022-06-03 20:21:20 +03:00
SemanticVersion.zig
simd.zig std: adjust for stage2 semantics 2022-06-07 21:27:07 +03:00
sort.zig std: add sort method to ArrayHashMap and MultiArrayList 2022-03-10 13:13:17 -05:00
start.zig target: Rename sparcv9 -> sparc64 2022-05-13 16:43:59 -04:00
start_windows_tls.zig
std.zig std: add http definitions for Method and Status (#10661) 2022-05-11 15:43:18 -04:00
target.zig Bump support macOS versions; clean up allocs in llvm.targetTriple 2022-05-22 22:31:41 +02:00
testing.zig checkAllAllocationFailures: add possibility of SwallowedOutOfMemoryError (split from NondeterministicMemoryUsage) 2022-06-23 17:20:24 -07:00
Thread.zig math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
time.zig math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
treap.zig treap: zig fmt 2022-04-15 17:01:01 -05:00
tz.zig std.tz: fix function returning pointer to local variable 2022-06-17 21:04:21 +03:00
unicode.zig Sema: handle tuple and anon_struct in resolveTypeFully 2022-06-11 11:02:56 +03:00
valgrind.zig
wasm.zig
x.zig stage2: small fixes + adjustments to std tests 2022-06-11 23:49:33 +03:00
zig.zig stage2 parser: UTF-8 encode \u{NNNNNN} escape sequences 2022-03-02 14:45:19 -05:00