Skip to content

elf: honor .deplibs (SHT_LLVM_DEPENDENT_LIBRARIES) natively (reld#123 Phase 2) #180

Closed

Description

@zackees

Sub-issue of #123 (Phase 2 — deplibs_are_linked).

Why

An object can carry a .deplibs section (SHT_LLVM_DEPENDENT_LIBRARIES, type 0x6fff4c04): NUL-separated library specifiers that clang emits for #pragma comment(lib, "m") on ELF. ld.lld links them by default. reld references the section type nowhere, so a native link of such an object silently drops the dependency and then fails with an undefined symbol the user never asked to resolve by hand — or, worse, links against something else of the same name that happens to be on the line. #123 lists it as not referenced | honored by default.

Scope

  • While loading inputs, read every SHT_LLVM_DEPENDENT_LIBRARIES section and add each specifier as a library input, with lld's semantics: try the specifier as a path relative to the library search directories first, then as -l<spec>. Match lld's behaviour for duplicates and for a specifier that cannot be found (check lld's ELF/InputFiles.cpp / Driver.cpp handling of DependentLibraries and record what it does in the code).
  • Match lld's --no-dependent-libraries flag if it is cheap to add; otherwise note it as a follow-up.
  • An acceptance fixture under crates/reld/tests/sources/elf/ whose object carries .deplibs naming m and calls a libm function, linked without -lm, and run. Use only frozen acceptance directives — a deferred one silently skips the whole fixture (see test(acceptance): activate NoDynamic so the RPATH tag is actually pinned (reld#123) #164).

Out of scope

args.rs, args/*.rs, bridge.rs and lib.rs are being changed by other sub-issues in flight; if this genuinely needs one of them, say so rather than editing it.

Acceptance

deplibs_are_linked: the fixture links natively without -lm and runs, and fails without this change.

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