| ... | @@ -2554,6 +2554,63 @@ fn initHeaders( | ... | @@ -2554,6 +2554,63 @@ fn initHeaders( |
| 2554 | elf.nodes.appendAssumeCapacity(.{ .segment = tls_phndx }); | 2554 | elf.nodes.appendAssumeCapacity(.{ .segment = tls_phndx }); |
| 2555 | elf.phdrs.items[tls_phndx] = elf.ni.tls; | 2555 | elf.phdrs.items[tls_phndx] = elf.ni.tls; |
| 2556 | } | 2556 | } |
| | 2557 | |
| | 2558 | // Create any always-provided linker-defined symbols. The symbols marking the `INIT_ARRAY`/ |
| | 2559 | // `FINI_ARRAY`/`PREINIT_ARRAY` sections are instead created by `createInitFiniArraySection` |
| | 2560 | // when needed (it seems to be legal to leave those undefined if the section doesn't exist). |
| | 2561 | |
| | 2562 | try elf.ensureUnusedSymbolCapacity(4, .maybe_global); |
| | 2563 | // Despite the name, `__dso_handle` is necessary even in static binaries. |
| | 2564 | _ = elf.addGlobalSymbolAssumeCapacity(.{ |
| | 2565 | .node = Section.Index.text.get(elf).ni, |
| | 2566 | .name = try .string(elf, "__dso_handle"), |
| | 2567 | .value = Section.Index.text.vaddr(elf), |
| | 2568 | .size = 0, |
| | 2569 | .type = .NOTYPE, |
| | 2570 | .bind = .strong, |
| | 2571 | .visibility = .HIDDEN, |
| | 2572 | .shndx = .text, |
| | 2573 | }) catch |err| switch (err) { |
| | 2574 | error.MultipleDefinitions => unreachable, // no inputs are processed yet |
| | 2575 | }; |
| | 2576 | _ = elf.addGlobalSymbolAssumeCapacity(.{ |
| | 2577 | .node = elf.shndx.plt.get(elf).ni, |
| | 2578 | .name = try .string(elf, "_PROCEDURE_LINKAGE_TABLE_"), |
| | 2579 | .value = elf.shndx.plt.vaddr(elf), |
| | 2580 | .size = 0, |
| | 2581 | .type = .NOTYPE, |
| | 2582 | .bind = .strong, |
| | 2583 | .visibility = .HIDDEN, |
| | 2584 | .shndx = elf.shndx.plt, |
| | 2585 | }) catch |err| switch (err) { |
| | 2586 | error.MultipleDefinitions => unreachable, // no inputs are processed yet |
| | 2587 | }; |
| | 2588 | _ = elf.addGlobalSymbolAssumeCapacity(.{ |
| | 2589 | .node = elf.shndx.got.get(elf).ni, |
| | 2590 | .name = try .string(elf, "_GLOBAL_OFFSET_TABLE_"), |
| | 2591 | .value = elf.shndx.got.vaddr(elf), |
| | 2592 | .size = 0, |
| | 2593 | .type = .NOTYPE, |
| | 2594 | .bind = .strong, |
| | 2595 | .visibility = .HIDDEN, |
| | 2596 | .shndx = elf.shndx.got, |
| | 2597 | }) catch |err| switch (err) { |
| | 2598 | error.MultipleDefinitions => unreachable, // no inputs are processed yet |
| | 2599 | }; |
| | 2600 | if (have_dynamic_section) { |
| | 2601 | _ = elf.addGlobalSymbolAssumeCapacity(.{ |
| | 2602 | .node = elf.shndx.dynamic.get(elf).ni, |
| | 2603 | .name = try .string(elf, "_DYNAMIC"), |
| | 2604 | .value = elf.shndx.dynamic.vaddr(elf), |
| | 2605 | .size = 0, |
| | 2606 | .type = .NOTYPE, |
| | 2607 | .bind = .strong, |
| | 2608 | .visibility = .HIDDEN, |
| | 2609 | .shndx = elf.shndx.dynamic, |
| | 2610 | }) catch |err| switch (err) { |
| | 2611 | error.MultipleDefinitions => unreachable, // no inputs are processed yet |
| | 2612 | }; |
| | 2613 | } |
| 2557 | } else { | 2614 | } else { |
| 2558 | assert(maybe_interp == null); | 2615 | assert(maybe_interp == null); |
| 2559 | assert(!have_dynamic_section); | 2616 | assert(!have_dynamic_section); |