388 Commits

Author SHA1 Message Date
Jakub Konka
540ef3e010 elf: sort sections by their rank to combine them by segment flags
Currently this ignores ZigModule, however, I believe we can make it
so that this is done excluding sections/segments emitted by ZigModule
and everything should work out just fine.
2023-10-16 19:33:04 +02:00
Jakub Konka
679accd887 elf: initialize output sections from input objects in a separate step 2023-10-16 19:33:04 +02:00
Jakub Konka
509da2316c elf: run populateMissingMetadata only if ZigModule exists 2023-10-16 19:33:04 +02:00
Jakub Konka
f0f19e18c7 elf: write shdr_table in flush 2023-10-16 19:33:04 +02:00
Jakub Konka
87602092fa elf: write .got in bulk after scanning objects 2023-10-16 19:33:04 +02:00
Jakub Konka
d565f8bef2 elf: check for null atom in ZigModule 2023-10-16 19:33:04 +02:00
Jakub Konka
75f4420c2d elf: increase Atom.Index resolution to u32 2023-10-16 19:33:04 +02:00
Jakub Konka
43406c0696 elf: update .strtab with GOT symbols 2023-10-16 19:33:03 +02:00
Jakub Konka
d06aa21e48 elf: for now always update .shstrtab and .strtab sections 2023-10-16 19:33:03 +02:00
Jakub Konka
ff1423c4ce elf: reuse addSection in alloc functions 2023-10-16 19:33:03 +02:00
Jakub Konka
c8c50a058e elf: do not prealloc space for .symtab 2023-10-16 19:33:03 +02:00
Jakub Konka
52f8a1a24c elf: move initializing string buffers out of populateMissingMetadata 2023-10-16 19:33:03 +02:00
Andrew Kelley
f708c5fafc CLI: finish updating module API usage
Finish the work started in 4c4fb839972f66f55aa44fc0aca5f80b0608c731.
Now the compiler compiles again.

Wire up dependency tree fetching code in the CLI for `zig build`.
Everything is hooked up except for `createDependenciesModule` is not yet
implemented.
2023-10-08 16:54:31 -07:00
Jakub Konka
cbdf4858e8 elf: assert llvm_object is null in getAnonDeclVAddr 2023-10-03 12:49:24 -07:00
Jakub Konka
0134e5d2a1 codegen: separate getAnonDeclVAddr into lowerAnonDecl and the former
Implement the stub for Elf.

I believe that separating the concerns, namely, having an interface
function that is responsible for signalling the linker to lower
the anon decl only, and a separate function to obtain the decl's
vaddr is preferable since it allows us to handle codegen errors
in a simpler way.
2023-10-03 12:49:12 -07:00
Andrew Kelley
0483b4a512 link: stub out getAnonDeclVAddr 2023-10-03 12:12:51 -07:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Jakub Konka
e72fd185e0 elf: skip writing out zerofill atoms to file 2023-09-30 00:52:10 +02:00
Jakub Konka
6c50ad6e9f elf: set sh_size to 0 for nobit sections in collision detection
`SHT_NOBITS` sections take no file space after all.
2023-09-29 22:37:59 +02:00
Jakub Konka
e5e6984652 elf: dump state for debugging after writing it all out 2023-09-29 22:29:06 +02:00
Jakub Konka
5381bfd348 elf: fix setting st_value of _end synthetic symbol 2023-09-29 22:18:38 +02:00
Jakub Konka
8e90b41ae0 elf: set shdr/phdr file size before growing in VM 2023-09-29 21:43:01 +02:00
Jakub Konka
304d38e844 elf: simplify logic for growing non-alloc sections 2023-09-29 20:35:28 +02:00
Jakub Konka
0524a3c83d elf: fix calculating current allocated section size when growing alloc sections 2023-09-29 19:06:02 +02:00
Jakub Konka
89c2151a97 elf: move logic for extracing atom's code into input files 2023-09-28 18:35:26 +02:00
Jakub Konka
785bd270ed elf: correctly allocate TLS segment 2023-09-28 14:59:09 +02:00
Jakub Konka
af00ac53b5 elf: report fatal linker error for unhandled relocation types 2023-09-28 14:06:12 +02:00
Jakub Konka
a63ce5a37c elf: allocate .tdata and .tbss sections 2023-09-28 13:29:04 +02:00
Jakub Konka
22127a8792 elf: pre-allocate TLS load segment and PT_TLS phdr 2023-09-28 12:06:21 +02:00
Jakub Konka
42011a8249 elf: remove explicit load segment alloc - we can replicate programmatically now 2023-09-28 11:46:40 +02:00
Jakub Konka
df285949f7 elf: do not assume segments laid out in increasing order in VM space 2023-09-28 08:47:58 +02:00
Jakub Konka
8f90dbba55 elf: fix typo in selecting larger addrspace for load segments 2023-09-27 20:05:46 +02:00
Jakub Konka
8b7255c22a elf: hint allocateSegment where to put the segment at 2023-09-27 19:41:59 +02:00
Jakub Konka
111349f83c elf: do not update globals not defined by the object 2023-09-27 19:22:57 +02:00
Jakub Konka
85132965f4 elf: use new error reporting API 2023-09-27 16:40:51 +02:00
Jakub Konka
09863fc970 elf: emit fatal linker error if we run out of VM space with self-hosted backends 2023-09-27 15:07:05 +02:00
Jakub Konka
e178580d86 elf: pre-allocate large VM capacity per segment 2023-09-27 10:00:20 +02:00
Jakub Konka
1200a5a240 elf: allow expanding segments in virtual memory 2023-09-27 09:59:59 +02:00
Jakub Konka
7a43f45908
Merge pull request #17284 from ziglang/elf-tests
elf: link against musl libc, add ELF test harness, dynamically allocate misc SHF_ALLOC sections
2023-09-27 07:39:58 +02:00
LinuxUserGD
ceaae42e90 Add '--compress-debug-sections=zstd' 2023-09-26 14:18:01 -07:00
Jakub Konka
eb497c50e3 elf: dynamically allocate remaining alloc sections (and segments) 2023-09-26 21:07:47 +02:00
Jakub Konka
5e617e4b0c elf: put libc on the linker line if requested 2023-09-26 21:07:47 +02:00
Jakub Konka
e7c6dfde3d elf: do not try to create LlvmObject if module is null 2023-09-26 21:07:47 +02:00
Jakub Konka
ab8a5bfe83 elf: implement markLive for ZigModule 2023-09-23 17:17:20 +02:00
Jakub Konka
8960df0c01 elf: encapsulate logic for creating non-alloc shdrs in a helper 2023-09-23 17:17:18 +02:00
Jakub Konka
29ebd96818 elf: improve decl-to-section mapping logic 2023-09-23 17:15:41 +02:00
Jakub Konka
9f05cb318b elf: put logic for allocating load segments in a helper 2023-09-23 17:14:27 +02:00
Jakub Konka
d9c5a26cfb elf: add helper for calculating available VM size for phdr 2023-09-23 17:11:20 +02:00
Andrew Kelley
accd5701c2 compiler: move struct types into InternPool proper
Structs were previously using `SegmentedList` to be given indexes, but
were not actually backed by the InternPool arrays.

After this, the only remaining uses of `SegmentedList` in the compiler
are `Module.Decl` and `Module.Namespace`. Once those last two are
migrated to become backed by InternPool arrays as well, we can introduce
state serialization via writing these arrays to disk all at once.

Unfortunately there are a lot of source code locations that touch the
struct type API, so this commit is still work-in-progress. Once I get it
compiling and passing the test suite, I can provide some interesting
data points such as how it affected the InternPool memory size and
performance comparison against master branch.

I also couldn't resist migrating over a bunch of alignment API over to
use the log2 Alignment type rather than a mismash of u32 and u64 byte
units with 0 meaning something implicitly different and special at every
location. Turns out you can do all the math you need directly on the
log2 representation of alignments.
2023-09-21 14:48:40 -07:00
Jakub Konka
d4c1e85a13 elf: skip writing non-alloc and zerofill atoms 2023-09-13 21:51:43 +02:00