@@ -386,6 +386,82 @@ pub fn emitMir(emit: *Emit) Error!void {
386
386
}, emit .lower .target ), &.{});
387
387
},
388
388
else = > unreachable ,
389
+ } else if (emit .bin_file .cast (.coff2 )) | coff | {
390
+ switch (emit .lower .target .cpu .arch ) {
391
+ else = > unreachable ,
392
+ .x86 = > {
393
+ try emit .encodeInst (try .new (.none , .mov , &.{
394
+ .{ .reg = .eax },
395
+ .{ .mem = .initSib (.qword , .{
396
+ .base = .{ .reg = .fs },
397
+ .disp = 4 * 11 ,
398
+ }) },
399
+ }, emit .lower .target ), &.{});
400
+ try emit .encodeInst (try .new (.none , .mov , &.{
401
+ .{ .reg = .edi },
402
+ .{ .mem = .initSib (.dword , .{}) },
403
+ }, emit .lower .target ), &.{.{
404
+ .op_index = 1 ,
405
+ .target = .{
406
+ .index = @intFromEnum (
407
+ try coff .globalSymbol ("__tls_index" , null ),
408
+ ),
409
+ .is_extern = false ,
410
+ .type = .symbol ,
411
+ },
412
+ }});
413
+ try emit .encodeInst (try .new (.none , .mov , &.{
414
+ .{ .reg = .eax },
415
+ .{ .mem = .initSib (.dword , .{
416
+ .base = .{ .reg = .eax },
417
+ .scale_index = .{ .index = .edi , .scale = 4 },
418
+ }) },
419
+ }, emit .lower .target ), &.{});
420
+ try emit .encodeInst (try .new (.none , lowered_inst .encoding .mnemonic , &.{
421
+ lowered_inst .ops [0 ],
422
+ .{ .mem = .initSib (lowered_inst .ops [1 ].mem .sib .ptr_size , .{
423
+ .base = .{ .reg = .eax },
424
+ .disp = std .math .minInt (i32 ),
425
+ }) },
426
+ }, emit .lower .target ), reloc_info );
427
+ },
428
+ .x86_64 = > {
429
+ try emit .encodeInst (try .new (.none , .mov , &.{
430
+ .{ .reg = .rax },
431
+ .{ .mem = .initSib (.qword , .{
432
+ .base = .{ .reg = .gs },
433
+ .disp = 8 * 11 ,
434
+ }) },
435
+ }, emit .lower .target ), &.{});
436
+ try emit .encodeInst (try .new (.none , .mov , &.{
437
+ .{ .reg = .edi },
438
+ .{ .mem = .initRip (.dword , 0 ) },
439
+ }, emit .lower .target ), &.{.{
440
+ .op_index = 1 ,
441
+ .target = .{
442
+ .index = @intFromEnum (
443
+ try coff .globalSymbol ("_tls_index" , null ),
444
+ ),
445
+ .is_extern = false ,
446
+ .type = .symbol ,
447
+ },
448
+ }});
449
+ try emit .encodeInst (try .new (.none , .mov , &.{
450
+ .{ .reg = .rax },
451
+ .{ .mem = .initSib (.qword , .{
452
+ .base = .{ .reg = .rax },
453
+ .scale_index = .{ .index = .rdi , .scale = 8 },
454
+ }) },
455
+ }, emit .lower .target ), &.{});
456
+ try emit .encodeInst (try .new (.none , lowered_inst .encoding .mnemonic , &.{
457
+ lowered_inst .ops [0 ],
458
+ .{ .mem = .initSib (lowered_inst .ops [1 ].mem .sib .ptr_size , .{
459
+ .base = .{ .reg = .rax },
460
+ .disp = std .math .minInt (i32 ),
461
+ }) },
462
+ }, emit .lower .target ), reloc_info );
463
+ },
464
+ }
389
465
} else return emit .fail ("TODO implement relocs for {s}" , .{
390
466
@tagName (emit .bin_file .tag ),
391
467
});
@@ -870,7 +946,13 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
870
946
.symbolnum = @intCast (reloc .target .index ),
871
947
},
872
948
});
873
- } else return emit .fail ("TODO implement {s} reloc for {s}" , .{
949
+ } else if (emit .bin_file .cast (.coff2 )) | coff | try coff .addReloc (
950
+ @enumFromInt (emit .atom_index ),
951
+ end_offset - 4 ,
952
+ @enumFromInt (reloc .target .index ),
953
+ reloc .off ,
954
+ .{ .AMD64 = .SECREL },
955
+ ) else return emit .fail ("TODO implement {s} reloc for {s}" , .{
874
956
@tagName (reloc .target .type ), @tagName (emit .bin_file .tag ),
875
957
}),
876
958
};
0 commit comments