Skip to content
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

Build Chromium with thinlto fails: mmap failed: Cannot allocate memory #1416

Open
blackteahamburger opened this issue Feb 11, 2025 · 1 comment

Comments

@blackteahamburger
Copy link

I used a patch similar to #336 (comment) to try to build Chromium with thinlto with mold. All is fine except the final link:

[48401/48401] "python3.13" "../../build/toolchain/gcc_link_wrapper.py" --output="./chrome" -- x86_64-pc-linux-gnu-clang++-19 -Wl,--version-script=../../build/linux/chrome.map -fuse-ld=mold -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--icf=all -Wl,--color-diagnostics -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy=cache_size=10\%:cache_size_bytes=40g:cache_size_files=100000 -flto=thin -Wl,--thinlto-jobs=all -fwhole-program-vtables -Wl,--undefined-version -no-canonical-prefixes -Wl,-z,defs -Wl,--as-needed -rdynamic -pie -Wl,--disable-new-dtags -Wl,--lto-O2 -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -fuse-ld=mold -Wl,--lto-O3 -march=native -O3 -fno-semantic-interposition -pipe -Wl,--thread-count=4 -Wl,--thinlto-jobs=4 -o "./chrome" -Wl,--start-group @"./chrome.rsp" -Wl,--end-group   -latomic -ldl -lpthread -lrt -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -licui18n -licuuc -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 -latk-bridge-2.0 -latk-1.0 -lgio-2.0 -lfontconfig -ldbus-1 -ljsoncpp -lz -ldouble-conversion -lresolv -lzstd -lexpat -lpng16 -lwebpdemux -lwebpmux -lwebp -lfreetype -ljpeg -lharfbuzz-subset -lharfbuzz -lopus -lX11 -lXcomposite -lXdamage -lXext -lXfixes -lXrender -lXrandr -lXtst -lcrc32c -lsnappy -lxcb -lxkbcommon -lgbm -lXi -lpci -ludev -lpangocairo-1.0 -lpango-1.0 -lcairo -lasound -lFLAC -lavformat -lavcodec -lavutil -lxml2 -latspi -lminizip -lstdc++ -lxslt -lwoff2dec -lbrotlidec -lxshmfence -llcms2 -llcms2_fast_float -llcms2_threaded -lopenjp2 -lpng -Wl,--start-group  -Wl,--end-group 
FAILED: chrome 
"python3.13" "../../build/toolchain/gcc_link_wrapper.py" --output="./chrome" -- x86_64-pc-linux-gnu-clang++-19 -Wl,--version-script=../../build/linux/chrome.map -fuse-ld=mold -Wl,--build-id=sha1 -fPIC -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--icf=all -Wl,--color-diagnostics -Wl,--thinlto-cache-dir=thinlto-cache -Wl,--thinlto-cache-policy=cache_size=10\%:cache_size_bytes=40g:cache_size_files=100000 -flto=thin -Wl,--thinlto-jobs=all -fwhole-program-vtables -Wl,--undefined-version -no-canonical-prefixes -Wl,-z,defs -Wl,--as-needed -rdynamic -pie -Wl,--disable-new-dtags -Wl,--lto-O2 -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -fuse-ld=mold -Wl,--lto-O3 -march=native -O3 -fno-semantic-interposition -pipe -Wl,--thread-count=4 -Wl,--thinlto-jobs=4 -o "./chrome" -Wl,--start-group @"./chrome.rsp" -Wl,--end-group   -latomic -ldl -lpthread -lrt -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -licui18n -licuuc -lsmime3 -lnss3 -lnssutil3 -lplds4 -lplc4 -lnspr4 -latk-bridge-2.0 -latk-1.0 -lgio-2.0 -lfontconfig -ldbus-1 -ljsoncpp -lz -ldouble-conversion -lresolv -lzstd -lexpat -lpng16 -lwebpdemux -lwebpmux -lwebp -lfreetype -ljpeg -lharfbuzz-subset -lharfbuzz -lopus -lX11 -lXcomposite -lXdamage -lXext -lXfixes -lXrender -lXrandr -lXtst -lcrc32c -lsnappy -lxcb -lxkbcommon -lgbm -lXi -lpci -ludev -lpangocairo-1.0 -lpango-1.0 -lcairo -lasound -lFLAC -lavformat -lavcodec -lavutil -lxml2 -latspi -lminizip -lstdc++ -lxslt -lwoff2dec -lbrotlidec -lxshmfence -llcms2 -llcms2_fast_float -llcms2_threaded -lopenjp2 -lpng -Wl,--start-group  -Wl,--end-group 
mold: fatal: /var/tmp/portage/www-client/ungoogled-chromium-132.0.6834.159_p1-r1/temp/lto-llvm-014f27.o: mmap failed: Cannot allocate memory
x86_64-pc-linux-gnu-clang++-19: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

I set MOLD_JOBS=1, -Wl,--thread-count=4 and -Wl,--thinlto-jobs=4 but still failed. When it fails I notice that my memory usage is less than half.

After some search, I found "Having plenty of memory is not enough. Hardware requires each page be contiguous range of physical memory aligned by page size." I already have kernel config CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS=y. Any suggestions to eliminate the error? Or is this an issue with the mold itself?

@rui314
Copy link
Owner

rui314 commented Feb 17, 2025

Can you build it with lld?

It looks like an mmap(2) failure caused the issue. Did you set a limitation of the virtual address space or something with ulimit?

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

No branches or pull requests

2 participants