Skip to content

elf: native backend has no default library search path (can't find libgcc_s/libc) #116

Closed as not planned

Description

@zackees

reld's native ELF backend can't link a real Rust build because it has no default system library search paths — it only searches the -L directories rustc passes (the rust sysroot + build-script raw-dylibs).

Evidence (native self-link, CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=reld)

reld: error: Couldn't find library `gcc_s` on library search path

The linker command links -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc, but reld never finds libgcc_s.so/libc.so/etc. because the gcc driver (which normally supplies those system search paths) is bypassed when reld is the direct linker.

Why

args.lib_search_path() is populated only by -L (see args/elf.rs). Unlike mold/lld, reld adds no host/toolchain default search paths (e.g. /usr/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu, the gcc install's lib and lib/gcc/<triple>/<ver> dirs). The -B<…>/gcc-ld flag rustc passes (which would point at the toolchain) is currently a no-op.

Fix

Derive default library search paths the way a real linker does:

  • honor -B <prefix> / --sysroot to locate the toolchain's lib and lib/gcc/<triple>/<ver>,
  • plus a host-appropriate default list (/usr/lib/x86_64-linux-gnu, /lib/x86_64-linux-gnu, /usr/local/lib, …), and/or LIBRARY_PATH.

This is the next blocker after the flag-parsing fix (#115); after it, the remaining work is verifying reld's relocation/dynamic-linking paths actually produce a runnable binary.

Refs #115.

Activity

  1. zackees commented on Sep 16, 2026

    @zackees
    CollaboratorAuthor

    Same root cause and resolution as #117. reld is a pure linker; it does not (and should not) maintain its own default library search paths. When driven through clang (clang --ld-path=reld), the driver passes the -L search paths and CRT, so -lgcc_s/-lc resolve without reld adding defaults of its own.

    The correct integration is the soldr-side fix soldr#3261, not reld-side search-path injection (which would diverge from lld/mold/wild).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions