Skip to content

Current LLD 20 fails to link dependency in liblldMachO.a correctly #122655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lerno opened this issue Jan 12, 2025 · 10 comments
Closed

Current LLD 20 fails to link dependency in liblldMachO.a correctly #122655

lerno opened this issue Jan 12, 2025 · 10 comments

Comments

@lerno
Copy link
Contributor

lerno commented Jan 12, 2025

linking liblldMachO.a fails on a vanilla Linux build, with the following code:

/usr/bin/ld: /usr/lib/llvm-20/lib/liblldMachO.a(BPSectionOrderer.cpp.o): in function `lld::macho::runBalancedPartitioning(llvm::StringRef, bool, bool, bool, bool)':
(.text._ZN3lld5macho23runBalancedPartitioningEN4llvm9StringRefEbbbb+0x2fc): undefined reference to `lld::BPSectionBase::reorderSectionsByBalancedPartitioning(llvm::StringRef, bool, bool, bool, bool, llvm::SmallVector<std::unique_ptr<lld::BPSectionBase, std::default_delete<lld::BPSectionBase> >, 6u>&)'

This first started happening around Dec 19 2024, so is related some change during that time.

@llvmbot llvmbot added the lld label Jan 12, 2025
@lerno
Copy link
Contributor Author

lerno commented Jan 12, 2025

The missing function seems to be reorderSectionsByBalancedPartitioning

@carlocab
Copy link
Member

Sounds like #117514.

@Colibrow
Copy link
Contributor

Let me take a look.

@Colibrow
Copy link
Contributor

@lerno Can you provide the build environment and commands for me to reproduce this? I tested on my ubuntu-22.04 with build-in ld and c/c++ but not reproduced.
Commands are below

mkdir build
cd build
cmake -G Ninja \
      -DLLVM_ENABLE_PROJECTS=lld \
      -DCMAKE_BUILD_TYPE=Release \
      ../llvm
ninja lld

@lerno
Copy link
Contributor Author

lerno commented Jan 14, 2025

This is the build script: https://github.com/c3lang/c3c/blob/master/CMakeLists.txt

Here is the CI entry to build it so you can see how it's invoked:

https://github.com/c3lang/c3c/blob/4cb984e56d658c269764c56418d93c237e7fd4df/.github/workflows/main.yml#L225

This is the build arguments for that makefile:

cmake -B build \
                -G Ninja \
                -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
                -DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \
                -DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \
                -DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \
                -DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \
                -DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \
                -DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
                -DC3_LLVM_VERSION=${{matrix.llvm_version}}
          cmake --build build

@Colibrow
Copy link
Contributor

@lerno The order of the link needs to be reversed.
https://github.com/c3lang/c3c/blob/5ba9acad5d46903c1539d5290c67a8c7e55dd5d2/CMakeLists.txt#L255-L260
e.g.

 ${LLD_WASM} 
 ${LLD_MINGW} 
 ${LLD_ELF} 
 ${LLD_MACHO} 
 ${LLD_COMMON} 

liblldMachO.a references reorderSectionsByBalancedPartitioning in liblldCommon.a.
When processing archive symbols, libraries that provide symbols must come after the libraries that use them.
For further information on symbol processing, you can visit https://maskray.me/blog/2021-06-20-symbol-processing.

@lerno
Copy link
Contributor Author

lerno commented Jan 14, 2025

Ah! I didn't even think about looking at that because I had gotten used to LLVM sometimes breaking. So I was incorrectly assuming I failed to link something that was now expected but may not in the LLD CMake scripts or something. So simple...

@lerno
Copy link
Contributor Author

lerno commented Jan 14, 2025

Might be worth adding a note to the releasenotes to make people aware of this stricter link ordering though.

@lerno
Copy link
Contributor Author

lerno commented Jan 14, 2025

I can verify that this fixed the build. Should I close this issue?

@Colibrow
Copy link
Contributor

I can verify that this fixed the build. Should I close this issue?

Since the build has been fixed, I think the issue can be closed.

@lerno lerno closed this as completed Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants