1305 Commits

Author SHA1 Message Date
Luuk de Gram
7f508480f4 wasm-linker: convert relocation addend to i32
Addends in relocations are signed integers as theoretically it could
be a negative number. As Atom's offsets are relative to their parent
section, the relocation value should still result in a postive number.
For this reason, the final result is stored as an unsigned integer.

Also, rather than using `null` for relocations that do not support
addends. We set the value to 0 for those that do not support addends,
and have to call `addendIsPresent` to determine if an addend exists
or not. This means each Relocation costs 4 bytes less than before,
saving memory while linking.
2022-10-08 17:23:13 +02:00
Luuk de Gram
3beef5a94f
CheckObjectStep: parsing and dumping producers 2022-10-08 09:43:40 +02:00
Luuk de Gram
43b55ea9f4
wasm-linker: generate 'producers' section
The `producers` section contains meta data of the binary and/or
object file. It *can* contain the source language, the tool it
was processed by, and/or the SDK that was used to produce the file.

For now, we always set the language and processed-by fields to Zig.
In the future we will parse linked object files to detect their
producers sections and append (if different) their language, SDK
and processed-by fields.
2022-10-08 09:43:35 +02:00
Jakub Konka
4474f8dd6e macho: cleanup how we collect dyld data in incremental linker 2022-09-18 15:13:45 +02:00
Jakub Konka
f4706c23e9 macho: fix after sync with master 2022-09-18 11:01:29 +02:00
Jakub Konka
372acb8350 macho: ensure we extend section size when updating last atom 2022-09-18 10:00:04 +02:00
Jakub Konka
275abf7c57 macho: fix overlapping segments in file offset 2022-09-18 10:00:04 +02:00
Jakub Konka
66942cbc1a macho: make sure both vmsize and filesize for segments match always 2022-09-18 10:00:04 +02:00
Jakub Konka
e35a16c7e0 macho: make sure both vmsize and filesize for segments match 2022-09-18 10:00:04 +02:00
Jakub Konka
7f7669a09e macho: fix building on 32bit targets 2022-09-18 10:00:04 +02:00
Jakub Konka
dc6480dba5 macho: allow for add and ldr when resolving GOT_LOAD_* relocs 2022-09-18 10:00:04 +02:00
Jakub Konka
618c7a3546 macho: add logic for expanding segments in memory 2022-09-18 10:00:04 +02:00
Jakub Konka
e601969244 macho: rewrite how we allocate space in incremental context 2022-09-18 10:00:04 +02:00
Jakub Konka
79ab46ec91 macho: start separating linking contexts 2022-09-18 10:00:04 +02:00
Jakub Konka
53bd7bd044 macho: move to incremental writes and global relocs for incremental 2022-09-18 10:00:04 +02:00
Jakub Konka
34f9360ea2 macho: do not call populateMissingMetadata in full link mode 2022-09-18 10:00:04 +02:00
Jakub Konka
e5da251635 macho: clean up use of section ids 2022-09-18 10:00:04 +02:00
Jakub Konka
05d0c42894 macho: move main driver loop for one-shot into standalone zld module 2022-09-18 10:00:03 +02:00
Jakub Konka
26af8d254a macho: separate in structure and logic incremental relocs and file relocs 2022-09-18 10:00:03 +02:00
Jakub Konka
5391541f11 macho: do not assume every object has a symtab
For example, building stage2 requires an empty `empty.cc` source file
compiling which generates a valid translation unit with no symtab/strtab.
In this case, we cannot simply assume that every translation unit will
have a valid symtab; instead, we cautiously default the input symtab
and strtab fields to optional `null` to signal symtab's presence or its lack of.
In case the symtab is not present, we catch this fact when splitting
input sections into subsections and create a synthetic symbol per every
suitable section.
2022-09-17 18:42:47 +02:00
Andrew Kelley
0a4cfb81bc Merge remote-tracking branch 'origin/master' into llvm15 2022-09-13 13:50:25 -07:00
Andrew Kelley
c25ce5bba0
Merge pull request #12820 from ziglang/pointless-discard-error
introduce compile error for pointless discards
2022-09-13 13:01:42 -04:00
Andrew Kelley
bec70a1a39 stage2: remove pointless discards from source code
Good riddance!
2022-09-13 02:04:20 -07:00
Luuk de Gram
3edf8c7a6c
wasm-linker: reset file pointer for incremental
On each invocation of `flush()` the file pointer is moved.
This means that rather than overwriting the binary file,
we're appending to the file. With this commit, we're resetting
said pointer to '0' and overwrite the existing binary in incremental
mode.
2022-09-12 21:35:28 +02:00
Luuk de Gram
61f317e386
wasm-linker: rename self to descriptive name 2022-09-12 21:19:16 +02:00
Luuk de Gram
6dbf5f1d86
wasm-linker: write to file at once
Rather than writing to the file using a writer, we now first write to
an arraylist and store the binary in memory. Once the full binary
data was written, we write all data to disk at once. This reduces
the amount of syscalls tremendously, increasing the performance of
the linker in exchange for increased memory usage during flush.
2022-09-12 21:19:16 +02:00
Luuk de Gram
a01b1448e2
wasm-linker: write magic bytes only on success
By writing them at the very end, we can easily detect
where the writing of the binary went wrong as tools will
indicate the missing of the magic bytes.
2022-09-12 21:19:13 +02:00
Andrew Kelley
ab3ac291ac Merge remote-tracking branch 'origin/master' into llvm15 2022-09-11 20:26:53 -07:00
Jakub Konka
a1b8545265 coff: remove unused function 2022-09-10 00:59:46 +02:00
Jakub Konka
0824808444 macho: refactor direct use of locals container in favour of helpers 2022-09-10 00:58:16 +02:00
Jakub Konka
fc5a6e0e32 x86_64: combine got_load, direct_load and imports_load into linker_load MCV 2022-09-10 00:18:39 +02:00
Jakub Konka
d8f2103545 macho+coff: return index into global table from getGlobalSymbol 2022-09-09 23:30:31 +02:00
Jakub Konka
bac065c7cf coff: use global accessor abstractions from MachO 2022-09-09 22:29:50 +02:00
Jakub Konka
8d44e03161 macho: use globals free list like in COFF linker 2022-09-09 22:10:27 +02:00
Andrew Kelley
37cdb5dbf9 Merge remote-tracking branch 'origin/master' into llvm15 2022-09-09 10:26:17 -07:00
Jakub Konka
56b96cd61b
Merge pull request #12772 from ziglang/coff-basic-imports
coff: implement enough of the incremental linker to pass behavior and incremental tests on Windows
2022-09-09 13:08:58 +02:00
Jakub Konka
5006fb6846 macho: fix compilation for 32bit targets 2022-09-09 08:30:27 +02:00
Motiejus Jakštys
a833bdcd7e [ld] add --print-* for diagnostics
This adds the following for passthrough to lld:
- `--print-gc-sections`
- `--print-icf-sections`
- `--print-map`

I am not adding these to the cache manifest, since it does not change
the produced artifacts.

Tested with an example from #11398: it successfully prints the resulting
map and the GC'd sections.
2022-09-08 22:30:32 -04:00
Jakub Konka
8378cde743 macho: prefill any space between __DATA and __LINKEDIT with 0s if required
If there are zerofill sections, the loader may copy the contents of
the physical space in file directly into memory and attach that to
the zerofill section. This is a performance optimisation in the loader
but requires us, the linker, to properly zero-out any space between
__DATA and __LINKEDIT segments in file. This is of course completely
skipped if there are no zerofill sections present.
2022-09-09 00:01:22 +02:00
Jakub Konka
0ae2ea671b wasm: temporarily save curr file pointer before pwriting on Win
This is a temporary workaround to an unclear platform-dependence
behavior we have in libstd for `std.fs.File` abstraction. See
https://github.com/ziglang/zig/issues/12783 for more information.
2022-09-08 14:29:54 +02:00
Jakub Konka
678e07b924 macho+wasm: unify and clean up closing file handles 2022-09-07 22:42:59 +02:00
Jakub Konka
639237c7b4 macho: set file instance in linkOneShot only if not already set 2022-09-07 22:42:59 +02:00
Jakub Konka
8ef1c62f2e macho: properly close file handles owned by the linker in deinit() 2022-09-07 22:42:59 +02:00
Jakub Konka
215fce8c51 coff: fix tracking of got and import entries; free relocs in update* fns 2022-09-07 22:42:59 +02:00
Jakub Konka
99c2cb72e8 coff: track globals in contiguous array to allow for tombstones 2022-09-07 22:42:59 +02:00
Jakub Konka
f3e4e44a2b coff: fix memory leak in incorrectly disposing of globals table 2022-09-07 22:42:58 +02:00
Jakub Konka
7b8cc599d9 coff: use more generous initial memory sizes for sections 2022-09-07 22:42:58 +02:00
Jakub Konka
16ca47b9b8 coff: remove redundant bits and clean up 2022-09-07 22:42:58 +02:00
Jakub Konka
2b373b0579 coff: grow section in virtual address space when required 2022-09-07 22:42:58 +02:00
Jakub Konka
9116e0f746 coff: find new file space for a section (file offsets) 2022-09-07 22:42:58 +02:00