diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 20ad8bef6f..e55af7f211 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1698,11 +1698,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v try argv.append(ssp.full_object_path); } - // compiler-rt - if (compiler_rt_path) |p| { - try argv.append(p); - } - // Shared libraries. if (is_exe_or_dyn_lib) { const system_libs = self.base.options.system_libs.keys(); @@ -1781,6 +1776,13 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v } } + // compiler-rt. Since compiler_rt exports symbols like `memset`, it needs + // to be after the shared libraries, so they are picked up from the shared + // libraries, not libcompiler_rt. + if (compiler_rt_path) |p| { + try argv.append(p); + } + // crt postlude if (csu.crtend) |v| try argv.append(v); if (csu.crtn) |v| try argv.append(v);