authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-12 12:17:54+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-16 09:30:29+01:00
log44449730c731a50dcdaaef04dff2755418f2546c
tree27b44fb96c194d65cee80ce417d8d57cbb41eeb5
parentc6d7ab8a234cedf08cd63f14db6e020ee5bd6c34
signaturelock-open Commit is signed but in an unrecognized format.

Elf2: fix crashes when emitting dynamic libraries


1 files changed, 6 insertions(+), 6 deletions(-)

src/link/Elf2.zig+6-6
......@@ -2270,8 +2270,9 @@ fn setGlobalSymbolValue(
22702270 }
22712271
22722272 // If this symbol was previously undefined, relocations targeting it may have been lowered to
2273 // runtime relocations which we have now discovered we do not need, so delete those.
2274 if (elf.shndx.dynamic != .UNDEF) {
2273 // runtime relocations which we have now discovered we do not need, so delete those. This does
2274 // not apply if the symbol is preemptible, which we check with `classifySymbolValue`.
2275 if (elf.shndx.dynamic != .UNDEF and elf.classifySymbolValue(.global(global_name)) != .dynamic) {
22752276 Symbol.Id.global(global_name).deleteDynamicTargetRelocs(elf);
22762277 }
22772278
......@@ -6925,6 +6926,9 @@ fn nodeWantsDsoRelocation(elf: *Elf, node: MappedFile.Node.Index) enum { yes, ye
69256926fn maybeAddCopyRelocation(elf: *Elf, global_name: String(.strtab)) Error!bool {
69266927 assert(elf.shndx.dynamic != .UNDEF);
69276928
6929 // Only dynamic executables may contain `R_*_COPY` relocations.
6930 if (elf.base.comp.config.output_mode != .Exe) return false;
6931
69286932 const gpa = elf.base.comp.gpa;
69296933
69306934 const global_ptr = elf.globals.strong_undef.getPtr(global_name) orelse
......@@ -6932,10 +6936,6 @@ fn maybeAddCopyRelocation(elf: *Elf, global_name: String(.strtab)) Error!bool {
69326936
69336937 assert(global_ptr.dynsym_index != 0);
69346938
6935 // Only dynamic executables may contain `R_*_COPY` relocations.
6936 if (elf.shndx.dynamic == .UNDEF) return false;
6937 if (elf.base.comp.config.output_mode != .Exe) return false;
6938
69396939 const dso_global = elf.dso_globals.get(global_name) orelse {
69406940 // We do not have a definition to provide the correct size for the symbol. If a definition
69416941 // is discovered in a later DSO, we may at that point be able to add a copy relocation.