Skip to content

feat(core): honor .deplibs (SHT_LLVM_DEPENDENT_LIBRARIES) natively (#180) - #181

Merged
zackees merged 1 commit into
mainfrom
feat/meta-work-180
Sep 18, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/meta-work-180

Conversation

@zackees

@zackees zackees commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Closes #180

reld now reads the .deplibs section (SHT_LLVM_DEPENDENT_LIBRARIES) that clang emits for #pragma comment(lib, ...), and links the libraries it names itself, the same way ld.lld does.

What changed

  • Reading the section (platform.rs, elf.rs): two new trait methods, ObjectFile::dependent_libraries and SectionHeader::is_dependent_libraries. Only relocatable ELF objects are read. parse_dependent_libraries has unit tests.
  • Loading the libraries (input_data.rs): each specifier is looked up in lld's addDependentLibrary order: first as -l<spec>, then as a bare name on the library search path, then as a literal path. The libraries are loaded after all command-line inputs, in the order they were found. Linker-script results (e.g. glibc's libm.so) and nested .deplibs go through a queue. A specifier that can't be found fails with lld's wording: unable to find library from dependent library specifier: <spec>. Nothing is resolved under -r or for --start-lib objects.
  • Output (layout_rules.rs): a full link drops .deplibs. A -r link keeps it, as lld does.
  • Fixture elf/deplibs:
    • deplibs-are-linked builds with clang and links cbrt through #pragma comment(lib, "m") with no -lm. It compares the output against lld and checks that no .deplibs section is left.
    • deplibs-missing checks lld's error message.
    • Two DiffIgnore entries (section.got.plt.entsize, section.gnu.version_r.alignment), both already tracked under Track and remove inherited reld-diff ignore patterns #13. They are general differences on dynamic links that other lld-compared fixtures also ignore, not .deplibs behaviour.

Known limitations

  • .deplibs is not yet read from archive members, --start-lib objects or LTO bitcode.
  • There is no --no-dependent-libraries switch yet.
  • The library settings used for .deplibs (static vs shared, --as-needed) are taken from the last input on the command line. lld uses whatever was in effect where each object appeared, so this only approximates it.

Validation

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test -p reld-core --lib: 216 passed
  • cargo test -p reld --test acceptance-policy: 11 passed
  • cargo test -p reld --test acceptance -- deplibs: deplibs-are-linked and deplibs-missing both pass
  • Negative check: with input_data.rs, elf.rs, platform.rs and layout_rules.rs put back to origin/main, both deplibs configs fail with reld: error: Undefined symbol cbrt.
  • act, act -W .github/workflows/ci.yml -j phase1-native --matrix kind:linux-gnu -P ubuntu-24.04=catthehacker/ubuntu:act-24.04 --pull=false --action-offline-mode: Job succeeded
    • Linux build and native tests ✅
    • relocation malfunction oracle ✅
    • LTO reference fixture compatibility ✅
    • Linux acceptance tests ✅ (239 passed, 0 failed, 621 ignored)
    • differential tests ✅
    • mold corpus ✅

🤖 Generated with Claude Code

)

Resolve dependent-library specifiers from relocatable objects in lld's
addDependentLibrary order (-l<spec>, bare name on search path, literal
path), load them after command-line inputs, and discard .deplibs from
full-link output (kept under -r).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees merged commit bc412bf into main Sep 18, 2026
18 checks passed
@zackees
zackees deleted the feat/meta-work-180 branch September 18, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant