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(...@@ -2270,8 +2270,9 @@ fn setGlobalSymbolValue(
2270 }2270 }
22712271
2272 // If this symbol was previously undefined, relocations targeting it may have been lowered to2272 // 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.2273 // runtime relocations which we have now discovered we do not need, so delete those. This does
2274 if (elf.shndx.dynamic != .UNDEF) {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) {
2275 Symbol.Id.global(global_name).deleteDynamicTargetRelocs(elf);2276 Symbol.Id.global(global_name).deleteDynamicTargetRelocs(elf);
2276 }2277 }
22772278
...@@ -6925,6 +6926,9 @@ fn nodeWantsDsoRelocation(elf: *Elf, node: MappedFile.Node.Index) enum { yes, ye...@@ -6925,6 +6926,9 @@ fn nodeWantsDsoRelocation(elf: *Elf, node: MappedFile.Node.Index) enum { yes, ye
6925fn maybeAddCopyRelocation(elf: *Elf, global_name: String(.strtab)) Error!bool {6926fn maybeAddCopyRelocation(elf: *Elf, global_name: String(.strtab)) Error!bool {
6926 assert(elf.shndx.dynamic != .UNDEF);6927 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
6928 const gpa = elf.base.comp.gpa;6932 const gpa = elf.base.comp.gpa;
69296933
6930 const global_ptr = elf.globals.strong_undef.getPtr(global_name) orelse6934 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 {...@@ -6932,10 +6936,6 @@ fn maybeAddCopyRelocation(elf: *Elf, global_name: String(.strtab)) Error!bool {
69326936
6933 assert(global_ptr.dynsym_index != 0);6937 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
6939 const dso_global = elf.dso_globals.get(global_name) orelse {6939 const dso_global = elf.dso_globals.get(global_name) orelse {
6940 // We do not have a definition to provide the correct size for the symbol. If a definition6940 // We do not have a definition to provide the correct size for the symbol. If a definition
6941 // is discovered in a later DSO, we may at that point be able to add a copy relocation.6941 // is discovered in a later DSO, we may at that point be able to add a copy relocation.