752 Commits

Author SHA1 Message Date
mlugg
b355893438
compiler: correct unnecessary uses of 'var' 2023-11-19 11:11:49 +00:00
mlugg
172c2797bd
link: fix MachO boundary symbol resolution 2023-11-19 11:11:49 +00:00
Jakub Konka
197fd41e27 macho: check for null Module before creating llvm_object 2023-11-10 13:43:43 +01:00
Jakub Konka
0f2489d8fc macho: resolve special section/segment boundary symbols
Boundary symbols have a special name prefix:

* section$start$segname$sectname
* section$stop$segname$sectname
* segment$start$segname
* segment$stop$segname

and will resolve to either start or end of the respective
section/segment if found.

If not found, we return an error stating we couldn't find the
requested section/segment rather than silently failing and resolving
the address to 0 which seems to be the case with Apple's ld64.
2023-11-10 12:52:56 +01:00
Jakub Konka
25c53f08a6 elf: redo strings management in the linker
* atom names - are stored locally and pulled from defining object's
  strtab
* local symbols - same
* global symbols - in principle, we could store them locally, but
  for better debugging experience - when things go wrong - we
  store the offsets in a global strtab used by the symbol resolver
2023-11-04 09:08:16 +01:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Jacob Young
d890e81761 mem: fix ub in writeInt
Use inline to vastly simplify the exposed API.  This allows a
comptime-known endian parameter to be propogated, making extra functions
for a specific endianness completely unnecessary.
2023-10-31 21:37:35 -04:00
Jakub Konka
2e690f5c74 macho: implement enough of extern handling to pass comptime export tests 2023-10-30 00:09:32 +01:00
Jakub Konka
a7a95ce9c4 macho: implement exporting anon decls 2023-10-29 18:55:58 +01:00
Andrew Kelley
4bc88dd116 link: support exporting constant values without a Decl
The main motivating change here is to prevent the creation of a fake
Decl object by the frontend in order to `@export()` a value.

Instead, `link.updateDeclExports` is renamed to `link.updateExports` and
accepts a tagged union which can be either a Decl.Index or a
InternPool.Index.
2023-10-26 20:32:16 -07:00
Andrew Kelley
cf9735a5e0 link: Coff, MachO, and Wasm all had the same UAF bug 2023-10-25 20:24:05 -07:00
Jacob Young
c4fcf0e22a codegen: implement lowering aligned anon decls 2023-10-21 21:38:41 -04:00
Jakub Konka
400faec10b dwarf: introduce Dwarf.Format to be able to select 32/64bit format at whim 2023-10-19 21:56:47 +02:00
Tom Read Cutting
023d1ac6bf Add search for extension-less libraries (MachO)
accessLibPath now has a `noextension` block to search for extension-less
libraries.
2023-10-15 17:11:44 +01:00
Jakub Konka
57eefe0533 macho: implement lowering anon decls 2023-10-03 12:49:17 -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
Michael Dusan
0c8bf405eb
kubkon review changes: 4
- fix `darwin_sdk_layout.?` with null checks
2023-09-26 07:51:32 -04:00
Michael Dusan
ebd0776b28
kubkon review changes: 3
- make vendored settings failure unreachable
- rename field `darwinSdkLayout` → `darwin_sdk_layout`
- make `darwin_sdk_layout` optional
2023-09-25 17:07:41 -04:00
Michael Dusan
9357973912
kubkon review changes: 1
general:
- rename `DarwinSdkLayout` → `DarwinSdkLayout`
- drop `DarwinSdkLayout.installation` (not needed for darwin)
- document struct

inferSdkVersion:
- use explicit allocator
- avoid trying to infer SDK ver from vendored path
2023-09-25 15:53:05 -04:00
Michael Dusan
5d6521d281
macos: better SDK version detection
SDK version detection:
- read SDKSettings.json before inferral from SDK path
- vendored libc: add SDKSettings.json for SDK version info

resolveLibSystem:
- adjust search order to { search_dirs, { sysroot or vendored }}
- previous search order was { sysroot, search_dirs, vendored }
2023-09-25 15:53:05 -04:00
Michael Dusan
15fd7cd154
macos: vendored libc: combine headers: part 2
- update include dirs to use combined dir
- use one libSystem.tbd (drop use of libSystem.VERSION.tbd)
- update canBuildLibC to check for minimum os version only
2023-09-25 15:53:05 -04:00
Michael Dusan
f3ff0b6e6d
macos: discontinue redundant search/link for libc 2023-09-25 15:53:04 -04: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
bff54536ff macho: check if we should emit LC_VERSION_MIN_ if target low enough 2023-09-04 09:07:49 +02:00
Jakub Konka
2187744411 macho: we actually care about stem and not basename for dependencies 2023-09-01 00:43:02 +02:00
Jakub Konka
611ddd426c macho: forgot to include dirname when resolving dependencies 2023-09-01 00:30:26 +02:00
Jakub Konka
21c04b119e macho: report missing libSystem/libc system libraries to the user 2023-08-31 23:47:55 +02:00
Jakub Konka
43adfd9689 macho: check if fallback libSystem.{d}.tbd exists in Zig's installation 2023-08-31 22:04:24 +02:00
Jakub Konka
19a1332ca1 macho: improve formatting of invalid targets in libraries 2023-08-30 22:30:42 +02:00
Jakub Konka
a7240f0c99 macho: remove error.UnhandledDwFormValue from link.File
Eventually, we will validate DWARF info upfront and report errors
to the user but this will require a rewrite of several parts of
the linker so leaving as a TODO for the near future.
2023-08-30 22:29:27 +02:00
Jakub Konka
ebe371b757 macho: report basic __eh_frame problems as errors 2023-08-30 21:48:24 +02:00
Jakub Konka
5144132320 macho: report formatted error for unhandled symbol types 2023-08-30 20:16:37 +02:00
Jakub Konka
5806e761bb macho: improve error reporting for re-exports mismatch 2023-08-30 19:02:25 +02:00
Jakub Konka
22c81740ef macho: convert error.TODOImplementWritingStaticLibFiles into an actual error 2023-08-30 12:37:05 +02:00
Jakub Konka
f21245f5e7 macho: refactor resolving and parsing dependent dylibs 2023-08-30 12:30:17 +02:00
Jakub Konka
ea9f2513a3 macho: format parse error for fat libs to include CPU archs only 2023-08-29 22:26:58 +02:00
Jakub Konka
7e167537c0 macho: simplify handling and reporting parsing errors 2023-08-29 22:16:48 +02:00
Jakub Konka
79b3285aa2 macho: handle mismatched and missing platform errors 2023-08-29 15:27:44 +02:00
Jakub Konka
1b01715a73 link: remove unused darwin_sdk_version field 2023-08-29 12:02:58 +02:00
Jakub Konka
2e28ab153c macho: parse platform info from each object file into Platform struct 2023-08-29 11:45:03 +02:00
Jakub Konka
ec03619dcf macho: make MachO.requiresCodeSignature accept link.Options 2023-08-29 11:40:20 +02:00
Jakub Konka
052984c5ae macho: remove MachO.requiresThunks as it is obsolete 2023-08-29 11:40:20 +02:00
Jakub Konka
2473ccc335 macho: create an explicit error set for parse functions 2023-08-29 11:40:20 +02:00
Jakub Konka
1820aed786 macho: convert log.err when CPU arch is mismatched into actual errors 2023-08-29 11:40:20 +02:00
Jakub Konka
68dc1a3e3f macho: report symbol collision as compiler error 2023-08-29 11:40:20 +02:00
Jakub Konka
0f02a1fcb0 macho: fix 32bit compilation issues 2023-08-29 11:40:20 +02:00
Jakub Konka
8330065a99 macho: report undefined via compiler errors in incremental driver 2023-08-29 11:40:20 +02:00
Jakub Konka
8d1ca8ce7b macho: swap sectname with segname typo when allocating sections 2023-08-29 11:40:20 +02:00
Jakub Konka
700b1e38ce macho: fix overalignment of stubs on aarch64 2023-08-29 11:40:20 +02:00