Commit Graph

1257 Commits (01c24c45093f70b5a9c1e415ed69c274cb61b303)

Author SHA1 Message Date
Vexu 0833c8d06b
translate-c: support sizeof and _Alignof in macros
Closes  #6301
2020-09-10 13:04:03 +03:00
Vexu 749417a1f3
translate-c: check for builtin typedef macro identifiers
Closes #6292
2020-09-09 16:29:16 +03:00
Jakub Konka edbfd04ec1
Do not pad out text blocks
It seems MachO does not like padding between text block in __text
section. Unlike in Elf, there is no size information in symbol
struct `nlist_64`.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-08 22:00:31 +02:00
Jakub Konka 9306dbd619
Fix bug where __text section would get overwritten
Fixes a bug where the last written load command would accidentally
override the beginning of the __text section. Also defines missing
MachO constants and relocation structs/enums.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-08 20:55:06 +02:00
Andrew Kelley d7268cbb24
Merge pull request #6232 from LemonBoy/fix-readall
std: Don't trust stat() size in readAllAlloc fns
2020-09-06 19:19:57 -04:00
LemonBoy 90743881cf std: Minor changes to the fs module
* Add a size_hint parameter to the read{toEnd,File}AllocOptions fns
* Rename readAllAlloc{,Options} to readToEndAlloc{,Options} as they
  don't rewind the file before reading
* Fix missing rewind in test case
2020-09-04 10:17:00 +02:00
Alexandros Naskos e9807418e7 Added .pe ObjectFormat
MachO linker no longer collects unused dwarf debug information
2020-09-04 05:22:26 +03:00
Alexandros Naskos e9b137f23a Completed basic PE linker for stage2
Added std.coff.MachineType
Added image characteristic and section flag valued to std.coff
Added std.Target.Cpu.Arch.toCoffMachine
Fixed stage2 --watch flag on windows
2020-09-04 05:15:03 +03:00
Alexandros Naskos fe0ad8d6e9 Write PE section table 2020-09-04 05:12:27 +03:00
Alexandros Naskos fac9a4e286 Start working on PE/COFF linking. 2020-09-04 05:12:26 +03:00
Andrew Kelley 17f36566de stage2: upgrade Scope.Container decls from ArrayList to HashMap 2020-09-03 15:02:38 -07:00
Andrew Kelley f2bbd8a548
Merge pull request #6242 from Vexu/stage2
Stage2: slicing and split container scope from file scope
2020-09-03 17:22:57 -04:00
Jakub Konka dac1cd7750 Write out simple Mach-O object file
This commit adds enough Mach-O linker implementation to write out simple
Mach-O object file. Be warned however, the object file is largely incomplete:
misses relocation info, debug symbols, etc. However, it seemed like a
good starting to get the basic understanding right.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-03 16:43:47 -04:00
Vexu 6f0126e957
stage2: split Scope.Container from Scope.File 2020-09-03 15:06:45 +03:00
Vexu 6ab0ac161e
stage2: slice return type analysis 2020-09-03 15:05:47 +03:00
Vexu 2a628fd401
stage2: astgen slice 2020-09-03 15:05:46 +03:00
Vexu ff7c6e1e3c
stage2: astgen orelse 2020-09-03 15:05:43 +03:00
Vexu 9a59cdcd41
stage2: various small type fixes 2020-09-03 15:05:10 +03:00
Andrew Kelley 405c7215a8
Merge pull request #6194 from LakeByTheWoods/fmt_indentation
Refactor zig fmt indentation. Remove indent from rendering code
2020-09-02 18:14:28 -04:00
Lachlan Easton bb848dbeee zig fmt: Patch rename stream to ais (auto indenting stream) & other small refactors 2020-09-02 20:16:28 +10:00
LemonBoy 73a8c9beaa std: Don't trust stat() size in readAllAlloc fns
Some files such as the ones in /proc report a st_size of zero, try to
read the file anyway if we hit that case.
2020-09-02 11:11:57 +02:00
Andrew Kelley 12ce6eb8f6 stage2: support dbg_stmt at comptime 2020-09-02 00:09:24 -07:00
Sahnvour 575fbd5e35 hash_map: rename to ArrayHashMap and add new HashMap implementation 2020-09-02 00:17:50 +02:00
Andrew Kelley 4c13d020db stage2: proper split of requireRuntimeBlock and requireFunctionBlock
* improve the ZIR generated of variable decls
   - utilize the same ZIR for the type and init value when possible
   - init value gets a result location with the variable type.
     no manual coercion is required.
 * no longer use return instructions to extract values out of comptime
   blocks. Instead run the analysis and then look at the corresponding
   analyzed instruction, relying on the comptime mechanism to report
   errors when something could not be comptime evaluated.
2020-09-01 12:39:47 -07:00
Lachlan Easton 671b3abe5d Merge remote-tracking branch 'ziglang/master' into fmt_indentation 2020-09-01 18:41:23 +10:00
Andrew Kelley 717b0e8275 stage2: introduce the ability for Scope.Block to be comptime
This gives zir_sema analysis the ability to check if the current scope
is expected to be comptime.
2020-08-31 23:34:58 -07:00
Andrew Kelley 212fe21d68 zen of zig: reword the last one a little bit 2020-08-31 14:40:08 -07:00
Tadeo Kondrak 82273f1a2a translate_c: fix shadowing on nested blocks 2020-08-31 20:29:57 +03:00
Tadeo Kondrak d3e5105ecc
std.zig.ast: make getTrailer/setTrailer private and add getters/setters 2020-08-30 17:18:25 -06:00
Lachlan Easton a72b9d403d Refactor zig fmt indentation. Remove indent from rendering code and have a stream handle automatic indentation 2020-08-29 13:35:00 +10:00
Tadeo Kondrak 3c87872dc5
stage2: Update to new std.meta.TrailerFlags API 2020-08-27 15:21:19 -06:00
Andrew Kelley b0995cb9f9 stage2: correct logic for analyzeIsNull 2020-08-26 19:53:36 -07:00
Vexu cc26cb9b23 stage2: codegen needed for basic for loop 2020-08-26 19:50:56 -07:00
Vexu fb28349349 stage2: astgen catch 2020-08-26 19:50:56 -07:00
Vexu bf014d529a stage2: array access astgen 2020-08-26 19:50:56 -07:00
Vexu bcd04089eb stage2: add helpful error message for invalid for operands 2020-08-26 19:50:56 -07:00
Vexu b1aa2857ff stage2: astgen for loops 2020-08-26 19:50:56 -07:00
Andrew Kelley 0c5faa61ae stage2: codegen: fix reuseOperand not doing death bookkeeping 2020-08-26 01:00:04 -07:00
Andrew Kelley 237d9a105d stage2: support debug dumping zir as a build option
So that it's not needed to manually comment and uncomment the debug
code.
2020-08-25 22:44:18 -07:00
Andrew Kelley e97157f71c stage2: codegen for conditional branching
* Move branch-local register and stack allocation metadata to the
   function-local struct. Conditional branches clone this data in order
   to restore it after generating machine code for a branch.
   Branch-local data is now only the instruction table mapping *ir.Inst
   to MCValue.
 * Implement conditional branching
   - Process operand deaths
   - Handle register and stack allocation metadata
 * Avoid storing unreferenced or void typed instructions into
   the branch-local instruction table.
 * Fix integer types reporting the wrong value for hasCodeGenBits.
 * Remove the codegen optimization for eliding length-0 jumps. I need to
   reexamine how this works because it was causing invalid jumps to be
   emitted.
2020-08-25 22:44:18 -07:00
Andrew Kelley b68fa9970b stage2 codegen: Rework genCondBr
so that the arch-independent logic isn't buried and duplicated.
2020-08-25 22:44:18 -07:00
Jakub Konka 982ab7df6c
Merge pull request #6161 from kubkon/macho-text
Add (empty) __TEXT segment load command
2020-08-26 07:03:58 +02:00
Jakub Konka 55dc81ba2a
Hardcode runtime (libSystem) version to minimum possible
While we try to work out what the correlation between the OS and runtime
versions is, this commit hardcodes the latter to the minimum (compat)
version of 1.0.0.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-26 06:30:54 +02:00
Andrew Kelley ea6a076065 stage2: fix use-after-free in elf linker code 2020-08-25 13:36:15 -07:00
Andrew Kelley 84d50c892d stage2: astgen: kill the "lvalue" ResultLoc tag 2020-08-24 16:13:10 -07:00
Andrew Kelley 16d54c70eb stage2: getErrorValue takes advantage of HashMap getOrPut API 2020-08-24 15:41:59 -07:00
Vexu 5de9aac749 stage2: error set types 2020-08-24 15:36:42 -07:00
Vexu bc1d55a1d1 stage2: fix field access of array pointers 2020-08-24 15:36:42 -07:00
Vexu 1520e084cb stage2: implement accessing error values 2020-08-24 15:36:42 -07:00
Vexu e9b15ac9a0 stage2: error set declarations 2020-08-24 15:36:42 -07:00