• Stars
    star
    203
  • Rank 186,386 (Top 4 %)
  • Language
    Zig
  • License
    MIT License
  • Created over 3 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zig's ld drop-in replacement

zld

Zig's ld drop-in replacement, called ZigLD or zld for short

Quick start guide

Building

You will need latest Zig in your path. You can get nightly binaries from here.

$ zig build

This will create the ld.zld (Elf), ld64.zld (MachO), link-zld (Coff) and wasm-zld (Wasm) binaries in zig-out/bin/. You can then use it like you'd use a standard linker.

$ cat <<EOF > hello.c
#include <stdio.h>

int main() {
    fprintf(stderr, "Hello, World!\n");
    return 0;
}
EOF

# Create .o using system clang
$ clang -c hello.c

# Or, create .o using zig cc
$ zig cc -c hello.c

# On macOS
$ ./zig-out/bin/ld64.zld hello.o -o hello

# On Linux
$ ./zig-out/bin/ld.zld hello.o -o hello

# Run!
$ ./hello

Testing

If you'd like to run unit and end-to-end tests, run the tests like you'd normally do for any other Zig project.

$ zig build test

Why did you decide to unarchive this repo?

Excellent question! If you recall, back in March 2021, I've moved the development of the linker directly to upstream (Zig master), and since then, zld (or zig ld in fact) has been able to link a variety of projects targeting Mach-O file format. Now I am in the process of implementing a traditional ELF linker, so I've decided to repeat the process which in my humble opinion worked out pretty well for Mach-O. The idea is to start small by adding basic linking in a standalone repo (separate from Zig master), and when the linker matures enough, upstream it into Zig. I think this approach makes sense and allows me to focus on the target file format only rather than try and tackle both a new file format and challenges of incremental linking.

Having said that, I've also decided to downstream all latest developments to the traditional Mach-O linker back into this repo, thus making zld a capable standalone linker when it comes to linking Mach-O. I'll strive to make it a direct replacement for any system linker, however, note that my priority will always be advancing of zig ld (which is not to say that I won't backport fixes from one to another). At the end of the day, the idea will be to swap in zig ld in place of any other linker.

Supported backends

  • Mach-O
  • ELF (non-PIE static and dynamic, x86_64)
  • ELF (PIE, DSO, x86_64)
  • ELF (aarch64)
  • ELF (other architectures)
  • COFF/PE
  • Wasm (static)

Contributing

You are welcome to contribute to this repo, but ask you to see if you could also contribute the same fix to Zig too. This will make my life easier and you will have made many Zig developers happy!

More Repositories

1

zig-ios-example

Minimal build.zig for targeting iOS
Zig
114
star
2

zig-yaml

YAML parser for Zig
Zig
101
star
3

rust-wasi-tutorial

Rust version of the excellent WASI tutorial https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-tutorial.md
Rust
78
star
4

ZigKit

Zig bindings for low-level macOS frameworks
Zig
60
star
5

zig-snapshots

Preview Zig's incremental linker state in interactive HTML
Zig
41
star
6

protozig

The protozig(uana), or protocol buffers implementation in Zig
Zig
40
star
7

zacho

Zig's Mach-O parser
Zig
38
star
8

powercrust

Original implementation of powercrust algorithm by N. Amenta
C
33
star
9

zig-dis-x86_64

x86_64 disassembler library written in Zig
Zig
32
star
10

zcoff

Like dumpbin.exe but cross-platform
Zig
30
star
11

zdb

Simple debugger in Zig for Zig
C
28
star
12

zig-deploy

Deploy your iOS apps written with Zig!
Zig
25
star
13

zig-dwarfdump

dwarfdump utility but in Zig
Zig
24
star
14

zignature

codesign your Apple apps with Zig!
Zig
22
star
15

zig-hcs-client

A simple REPL for controlling Zig's hot-code swapping compilation mode
Zig
21
star
16

zig-wasi-tutorial

Zig version of WASI tutorial https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md
Zig
20
star
17

zelf

Zig's ELF parser utility
Zig
17
star
18

zig-objdump

objdump but in Zig and for Zig
Zig
12
star
19

syclld

SYCL 2023 - linker workshop
Zig
11
star
20

py-game-theory

Python library implementing algorithms for solving games (as defined in game theory), written in py3k.
Python
8
star
21

gmm

My implementation of the Gaussian Mixture Model (GMM).
Python
8
star
22

wasi-compute

Experimental minimal example of deterministic compute functions in WASI
Rust
6
star
23

wiggle

Experimental wig implementation
Rust
4
star
24

espresso-zig

Zig bindings for espresso C library
Zig
4
star
25

Thesis

Thesis repo
TeX
3
star
26

hotcode-macos

Hotcode reloading on macOS, or first steps at writing a debugger from scratch on macOS
Zig
3
star
27

dotfiles

dot dot dot
Vim Script
3
star
28

zig-pdbdump

Zig
3
star
29

calctax

Simple tax calculator for employees in Poland after Nowy Lad changes in 2022
Zig
3
star
30

wasmtime-bench

Simple wasmtime vs native benchmarks
Rust
2
star
31

espresso

Espresso fork packaged as a static library with Zig
C
2
star
32

des-in-python

Discrete Event Simulation (DES) in py3k
Python
2
star
33

string-matching

Some toy implementations of string matching algorithms in Rust
Rust
2
star
34

checkmem

Wrapper around ChildProcess to get the max rss out
Zig
2
star
35

deqnap

Simple utility for removing extraneous files created by QNAP's rename merging policy
Rust
1
star
36

kmeans

My attempts at implementation of K-Means algorithm (and its variants)
Python
1
star
37

kubkon.github.com

My weblog
HTML
1
star
38

kalman

Kalman filtering and smoothing in Rust.
Rust
1
star
39

Phd-python

Python scripts
Python
1
star
40

DM-Simulator

Discrete-event simulator for the Digital Marketplace written in py3k.
Python
1
star
41

hkmeans

Simple implementation of K-Means clustering algorithm in Haskell
Haskell
1
star
42

Footsteps

An iOS 6 app which records and displays historical locations of the user on the Apple Map.
Objective-C
1
star
43

DM-Numerical

Scripts for numerical analysis of the Digital Marketplace
Python
1
star
44

gitrev

A simple command line utility that is meant to serve as a replacement for SubWCRev.exe on Windows
Rust
1
star
45

email-chattifier

Google Chrome extension that re-formats your email conversation
CoffeeScript
1
star
46

conduit-persistent-example

This code demonstrates how to use Conduit together with Persistent to stream data in constant memory in Haskell.
Haskell
1
star
47

ee106-additional-material

Additional coding examples for EE106 class.
Python
1
star