diff --git a/src/link/Elf.zig b/src/link/Elf.zig index ebb1cbdfb8efc867d34e0315256e6efa4c90a035..30c88fe9b2004109ef024ea08f58557ad02b3229 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1753,11 +1753,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(); @@ -1836,6 +1831,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);