| ... | ... | @@ -435,6 +435,8 @@ pub const GotSection = struct { |
| 435 | 435 | const cpu_arch = elf_file.getTarget().cpu.arch; |
| 436 | 436 | try elf_file.rela_dyn.ensureUnusedCapacity(gpa, got.numRela(elf_file)); |
| 437 | 437 | |
| 438 | relocs_log.debug(".got", .{}); |
| 439 | |
| 438 | 440 | for (got.entries.items) |entry| { |
| 439 | 441 | const symbol = elf_file.symbol(entry.ref); |
| 440 | 442 | const extra = if (symbol) |s| s.extra(elf_file) else null; |
| ... | ... | @@ -447,6 +449,7 @@ pub const GotSection = struct { |
| 447 | 449 | .offset = offset, |
| 448 | 450 | .sym = extra.?.dynamic, |
| 449 | 451 | .type = relocation.encode(.glob_dat, cpu_arch), |
| 452 | .target = symbol, |
| 450 | 453 | }); |
| 451 | 454 | continue; |
| 452 | 455 | } |
| ... | ... | @@ -455,6 +458,7 @@ pub const GotSection = struct { |
| 455 | 458 | .offset = offset, |
| 456 | 459 | .type = relocation.encode(.irel, cpu_arch), |
| 457 | 460 | .addend = symbol.?.address(.{ .plt = false }, elf_file), |
| 461 | .target = symbol, |
| 458 | 462 | }); |
| 459 | 463 | continue; |
| 460 | 464 | } |
| ... | ... | @@ -465,6 +469,7 @@ pub const GotSection = struct { |
| 465 | 469 | .offset = offset, |
| 466 | 470 | .type = relocation.encode(.rel, cpu_arch), |
| 467 | 471 | .addend = symbol.?.address(.{ .plt = false }, elf_file), |
| 472 | .target = symbol, |
| 468 | 473 | }); |
| 469 | 474 | } |
| 470 | 475 | }, |
| ... | ... | @@ -486,17 +491,20 @@ pub const GotSection = struct { |
| 486 | 491 | .offset = offset, |
| 487 | 492 | .sym = extra.?.dynamic, |
| 488 | 493 | .type = relocation.encode(.dtpmod, cpu_arch), |
| 494 | .target = symbol, |
| 489 | 495 | }); |
| 490 | 496 | elf_file.addRelaDynAssumeCapacity(.{ |
| 491 | 497 | .offset = offset + 8, |
| 492 | 498 | .sym = extra.?.dynamic, |
| 493 | 499 | .type = relocation.encode(.dtpoff, cpu_arch), |
| 500 | .target = symbol, |
| 494 | 501 | }); |
| 495 | 502 | } else if (is_dyn_lib) { |
| 496 | 503 | elf_file.addRelaDynAssumeCapacity(.{ |
| 497 | 504 | .offset = offset, |
| 498 | 505 | .sym = extra.?.dynamic, |
| 499 | 506 | .type = relocation.encode(.dtpmod, cpu_arch), |
| 507 | .target = symbol, |
| 500 | 508 | }); |
| 501 | 509 | } |
| 502 | 510 | }, |
| ... | ... | @@ -508,12 +516,14 @@ pub const GotSection = struct { |
| 508 | 516 | .offset = offset, |
| 509 | 517 | .sym = extra.?.dynamic, |
| 510 | 518 | .type = relocation.encode(.tpoff, cpu_arch), |
| 519 | .target = symbol, |
| 511 | 520 | }); |
| 512 | 521 | } else if (is_dyn_lib) { |
| 513 | 522 | elf_file.addRelaDynAssumeCapacity(.{ |
| 514 | 523 | .offset = offset, |
| 515 | 524 | .type = relocation.encode(.tpoff, cpu_arch), |
| 516 | 525 | .addend = symbol.?.address(.{}, elf_file) - elf_file.tlsAddress(), |
| 526 | .target = symbol, |
| 517 | 527 | }); |
| 518 | 528 | } |
| 519 | 529 | }, |
| ... | ... | @@ -525,6 +535,7 @@ pub const GotSection = struct { |
| 525 | 535 | .sym = if (symbol.?.flags.import) extra.?.dynamic else 0, |
| 526 | 536 | .type = relocation.encode(.tlsdesc, cpu_arch), |
| 527 | 537 | .addend = if (symbol.?.flags.import) 0 else symbol.?.address(.{}, elf_file) - elf_file.tlsAddress(), |
| 538 | .target = symbol, |
| 528 | 539 | }); |
| 529 | 540 | }, |
| 530 | 541 | } |
| ... | ... | @@ -681,6 +692,9 @@ pub const PltSection = struct { |
| 681 | 692 | const gpa = comp.gpa; |
| 682 | 693 | const cpu_arch = elf_file.getTarget().cpu.arch; |
| 683 | 694 | try elf_file.rela_plt.ensureUnusedCapacity(gpa, plt.numRela()); |
| 695 | |
| 696 | relocs_log.debug(".plt", .{}); |
| 697 | |
| 684 | 698 | for (plt.symbols.items) |ref| { |
| 685 | 699 | const sym = elf_file.symbol(ref).?; |
| 686 | 700 | assert(sym.flags.import); |
| ... | ... | @@ -688,6 +702,14 @@ pub const PltSection = struct { |
| 688 | 702 | const r_offset: u64 = @intCast(sym.gotPltAddress(elf_file)); |
| 689 | 703 | const r_sym: u64 = extra.dynamic; |
| 690 | 704 | const r_type = relocation.encode(.jump_slot, cpu_arch); |
| 705 | |
| 706 | relocs_log.debug(" {s}: [{x} => {d}({s})] + 0", .{ |
| 707 | relocation.fmtRelocType(r_type, cpu_arch), |
| 708 | r_offset, |
| 709 | r_sym, |
| 710 | sym.name(elf_file), |
| 711 | }); |
| 712 | |
| 691 | 713 | elf_file.rela_plt.appendAssumeCapacity(.{ |
| 692 | 714 | .r_offset = r_offset, |
| 693 | 715 | .r_info = (r_sym << 32) | r_type, |
| ... | ... | @@ -1053,6 +1075,9 @@ pub const CopyRelSection = struct { |
| 1053 | 1075 | const gpa = comp.gpa; |
| 1054 | 1076 | const cpu_arch = elf_file.getTarget().cpu.arch; |
| 1055 | 1077 | try elf_file.rela_dyn.ensureUnusedCapacity(gpa, copy_rel.numRela()); |
| 1078 | |
| 1079 | relocs_log.debug(".copy.rel", .{}); |
| 1080 | |
| 1056 | 1081 | for (copy_rel.symbols.items) |ref| { |
| 1057 | 1082 | const sym = elf_file.symbol(ref).?; |
| 1058 | 1083 | assert(sym.flags.import and sym.flags.has_copy_rel); |
| ... | ... | @@ -1525,6 +1550,7 @@ const elf = std.elf; |
| 1525 | 1550 | const math = std.math; |
| 1526 | 1551 | const mem = std.mem; |
| 1527 | 1552 | const log = std.log.scoped(.link); |
| 1553 | const relocs_log = std.log.scoped(.link_relocs); |
| 1528 | 1554 | const relocation = @import("relocation.zig"); |
| 1529 | 1555 | const std = @import("std"); |
| 1530 | 1556 | |