Skip to content

Commit f58200e

Browse files
jacobly0andrewrk
authored andcommitted
Elf2: create a new linker from scratch
This iteration already has significantly better incremental support. Closes #24110
1 parent 2a97e0a commit f58200e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4141
-536
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ set(ZIG_STAGE2_SOURCES
583583
src/link/Elf/relocatable.zig
584584
src/link/Elf/relocation.zig
585585
src/link/Elf/synthetic_sections.zig
586+
src/link/Elf2.zig
586587
src/link/Goff.zig
587588
src/link/LdScript.zig
588589
src/link/Lld.zig
@@ -612,6 +613,7 @@ set(ZIG_STAGE2_SOURCES
612613
src/link/MachO/synthetic.zig
613614
src/link/MachO/Thunk.zig
614615
src/link/MachO/uuid.zig
616+
src/link/MappedFile.zig
615617
src/link/Queue.zig
616618
src/link/StringTable.zig
617619
src/link/Wasm.zig

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub fn build(b: *std.Build) !void {
202202
});
203203
exe.pie = pie;
204204
exe.entitlements = entitlements;
205+
exe.use_new_linker = b.option(bool, "new-linker", "Use the new linker");
205206

206207
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
207208
exe.use_llvm = use_llvm;

ci/x86_64-linux-debug-llvm.sh

100644100755
File mode changed.

lib/compiler_rt/fma.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn add_adjusted(a: f64, b: f64) f64 {
203203
if (uhii & 1 == 0) {
204204
// hibits += copysign(1.0, sum.hi, sum.lo)
205205
const uloi: u64 = @bitCast(sum.lo);
206-
uhii += 1 - ((uhii ^ uloi) >> 62);
206+
uhii = uhii + 1 - ((uhii ^ uloi) >> 62);
207207
sum.hi = @bitCast(uhii);
208208
}
209209
}
@@ -217,7 +217,7 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) f64 {
217217
const bits_lost = -@as(i32, @intCast((uhii >> 52) & 0x7FF)) - scale + 1;
218218
if ((bits_lost != 1) == (uhii & 1 != 0)) {
219219
const uloi: u64 = @bitCast(sum.lo);
220-
uhii += 1 - (((uhii ^ uloi) >> 62) & 2);
220+
uhii = uhii + 1 - (((uhii ^ uloi) >> 62) & 2);
221221
sum.hi = @bitCast(uhii);
222222
}
223223
}
@@ -259,7 +259,7 @@ fn add_adjusted128(a: f128, b: f128) f128 {
259259
if (uhii & 1 == 0) {
260260
// hibits += copysign(1.0, sum.hi, sum.lo)
261261
const uloi: u128 = @bitCast(sum.lo);
262-
uhii += 1 - ((uhii ^ uloi) >> 126);
262+
uhii = uhii + 1 - ((uhii ^ uloi) >> 126);
263263
sum.hi = @bitCast(uhii);
264264
}
265265
}
@@ -284,7 +284,7 @@ fn add_and_denorm128(a: f128, b: f128, scale: i32) f128 {
284284
const bits_lost = -@as(i32, @intCast((uhii >> 112) & 0x7FFF)) - scale + 1;
285285
if ((bits_lost != 1) == (uhii & 1 != 0)) {
286286
const uloi: u128 = @bitCast(sum.lo);
287-
uhii += 1 - (((uhii ^ uloi) >> 126) & 2);
287+
uhii = uhii + 1 - (((uhii ^ uloi) >> 126) & 2);
288288
sum.hi = @bitCast(uhii);
289289
}
290290
}

lib/std/Build/Step/Compile.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ want_lto: ?bool = null,
192192

193193
use_llvm: ?bool,
194194
use_lld: ?bool,
195+
use_new_linker: ?bool,
195196

196197
/// Corresponds to the `-fallow-so-scripts` / `-fno-allow-so-scripts` CLI
197198
/// flags, overriding the global user setting provided to the `zig build`
@@ -441,6 +442,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
441442

442443
.use_llvm = options.use_llvm,
443444
.use_lld = options.use_lld,
445+
.use_new_linker = null,
444446

445447
.zig_process = null,
446448
};
@@ -1096,6 +1098,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
10961098

10971099
try addFlag(&zig_args, "llvm", compile.use_llvm);
10981100
try addFlag(&zig_args, "lld", compile.use_lld);
1101+
try addFlag(&zig_args, "new-linker", compile.use_new_linker);
10991102

11001103
if (compile.root_module.resolved_target.?.query.ofmt) |ofmt| {
11011104
try zig_args.append(try std.fmt.allocPrint(arena, "-ofmt={s}", .{@tagName(ofmt)}));

0 commit comments

Comments
 (0)