rui314 / mold

Mold: A Modern Linker 🦠
MIT License
14.23k stars 468 forks source link

Assertion 'ObjFilename.second' failed when using LLVMgold LTO #1356

Open benjamasu opened 10 hours ago

benjamasu commented 10 hours ago
ld.mold: .../llvm-19.1.1/work/llvm/tools/gold/gold-plugin.cpp:1069: std::vector<std::pair<SmallString<128>, bool>> runLTO(): Assertion `ObjFilename.second' failed

Probably related to #1355. The problem appears when using Clang + LTO + mold, but not always. When in the mentioned issue the problem occurred when building any sources, this one does not always appear.

I'll post a Dockerfile to reproduce the problem a bit later.

benjamasu commented 9 hours ago

It was my mistake to place the downloading and unpacking of the hardened_malloc sources archive in bootstrap.sh. If you still have the image from #1355, you can use it with the reproduce.sh from this comment.

### Dockerfile

# name the portage image
FROM gentoo/portage:latest AS portage

# based on stage3 image
FROM gentoo/stage3:llvm

# copy the entire portage volume in
COPY --from=portage /var/db/repos/gentoo /var/db/repos/gentoo

ADD bootstrap.sh / 
ADD reproduce.sh /

RUN chmod +x /reproduce.sh

RUN chmod +x /bootstrap.sh
RUN /bootstrap.sh

CMD [ "/bin/bash" ]
### bootstrap.sh

#!/bin/bash

echo '
CC=clang
CXX=clang++
LD=ld.lld
AR=llvm-ar
NM=llvm-nm
STRIP=llvm-strip
OBJCOPY=llvm-objcopy
OBJDUMP=llvm-objdump
READELF=llvm-readelf
RANLIB=llvm-ranlib

ACCEPT_KEYWORDS="~amd64"

FEATURES="${FEATURES} splitdebug parallel-fetch parallel-install -ipc-sandbox -network-sandbox -pid-sandbox"

USE="${USE} debug binutils-plugin verify-sig"
' >> /etc/portage/make.conf

echo "MAKEOPTS=\"-j$(nproc)\"" >> /etc/portage/make.conf

# echo "EMERGE_DEFAULT_OPTS=\"-j$(nproc) --load-average=$(($(nproc) + 1)).0\"" >> /etc/portage/make.conf

# Select fastest available mirrors
emerge -v mirrorselect
mirrorselect -S -s 3 -b 10 -o >> /etc/portage/make.conf

# Rebuild LLVM with USE=binutils-plugin to make LLVMgold available
emerge -v llvm clang lld llvmgold

## GCC and Glibc can also be rebuilt to get debug symbols.
## GCC 13 is only needed for the reason
## that the command I suggested in `reproduce.sh`
## links against GCC 13 libstdc++,
## but this can be easily changed.
# emerge -v glibc "sys-devel/gcc:13"

# emerge -v valgrind

# Build mold from git HEAD
emerge -v dev-vcs/git
# If specific commit needed,
# then just set the values of the corresponding environment variables
# *   EGIT_OVERRIDE_REPO_RUI314_MOLD
# *   EGIT_OVERRIDE_BRANCH_RUI314_MOLD
# *   EGIT_OVERRIDE_COMMIT_RUI314_MOLD
# *   EGIT_OVERRIDE_COMMIT_DATE_RUI314_MOLD
env ACCEPT_KEYWORDS="**" emerge -v mold

## Build mold with latest available release in gentoo repos
# emerge -v mold
### reproduce.sh

#!/bin/bash

# Required to add clang to PATH
source /etc/profile

wget -O git-2.47.0.tar.xz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.47.0.tar.xz

tar -xaf git-2.47.0.tar.xz

cd git-2.47.0

make CC=clang CXX=clang++ LD=ld.mold CFLAGS="-flto=thin" CXXFLAGS="-flto=thin" LDFLAGS="-flto=thin -fuse-ld=mold" V=1 -j$(nproc)