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

Support whole-program LTO #150

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Support whole-program LTO #150

wants to merge 1 commit into from

Conversation

sunfishcode
Copy link
Member

Build and install an LTO version of libc.a and the startup files,
alongside the non-LTO versions.

This also adds support for the proposed __main_argc_argv convention,
supporting compilers both with and without that change.

This doesn't depend on https://reviews.llvm.org/D70700, but contains code that anticipates it.

This does depend on WebAssembly/wasi-sdk#89.

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to split the renaming of the math sources into a separate PR.

Also, it looks like a lot of the Makefile refactoring could be split out? I can't tell which parts of that relate to this change directly.

@sbc100
Copy link
Member

sbc100 commented Dec 20, 2019

BTW, I'm working an wasm-ld fix that will allow compiler-to be part of LTO too: https://reviews.llvm.org/D71738 :)

@sunfishcode
Copy link
Member Author

sunfishcode commented Dec 20, 2019

Is it possible to split the renaming of the math sources into a separate PR.

Done, in #151.

Also, it looks like a lot of the Makefile refactoring could be split out? I can't tell which parts of that relate to this change directly.

I've now split out the main code changes in #152

Assuming those land, when I rebase this PR over them this PR will be just a Makefile change.

Build and install an LTO version of libc.a and the startup files,
alongside the non-LTO versions.
@sunfishcode
Copy link
Member Author

The dependencies for this PR all landed, and this PR is now rebased, so it's now just changes to the top-level Makefile to support LTO, and ready for review!

@@ -9,13 +9,17 @@ SYSROOT ?= $(CURDIR)/sysroot
# A directory to install to for "make install".
INSTALL_DIR ?= /usr/local
# single or posix
THREAD_MODEL = single
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There still seem to be a lot of non-LTO related changes here? Some kind of re-base issue maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now filed #186 to pull out several refactorings.

Base automatically changed from master to main January 19, 2021 23:28
@abrown abrown marked this pull request as draft July 11, 2023 23:01
@yamt
Copy link
Contributor

yamt commented May 27, 2024

@sunfishcode are you still interested in this? or may i (or someone) take it over?

@TerrorJack
Copy link
Contributor

To avoid duplicate effort: you can apply https://gitlab.haskell.org/ghc/wasi-libc/-/commit/eecc0942af95a90447e6bad8c58d8c133ec82fa2 to wasi-libc, then disable the predefined macro/symbol check, after which you can enable either thin/full LTO for wasi-libc as well as compiler-rt/libc++.

Distributing different sysroots both with/without LTO is harder though.

@sunfishcode
Copy link
Member Author

@yamt I'm not actively working on this, so you are welcome to take this over!

# which runs after LLVM LTO, so LTO libraries don't satisfy them. They're
# also relatively uninteresting to LTO, as LLVM recognizes most of them
# even without seeing their definitions.
override LIBC_NONLTO_SOURCES = \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunfishcode
@sbc100
this exclusion is no longer necessary after https://reviews.llvm.org/D71738, right?

@yamt
Copy link
Contributor

yamt commented Jun 4, 2024

To avoid duplicate effort: you can apply https://gitlab.haskell.org/ghc/wasi-libc/-/commit/eecc0942af95a90447e6bad8c58d8c133ec82fa2 to wasi-libc, then disable the predefined macro/symbol check, after which you can enable either thin/full LTO for wasi-libc as well as compiler-rt/libc++.

Distributing different sysroots both with/without LTO is harder though.

thank you. i guess i will look at full lto first though.

as thin lto seems to have more obstacles.
eg.
llvm/llvm-project#91711
llvm/llvm-project#91700

yamt added a commit to yamt/wasi-libc that referenced this pull request Jun 4, 2024
An old PR which I used as a base:
WebAssembly#150

Co-Authored-by: Dan Gohman <dev@sunfishcode.online>
@yamt yamt mentioned this pull request Jun 4, 2024
abrown pushed a commit that referenced this pull request Jul 12, 2024
* Add LTO build option

An old PR which I used as a base:
#150

Co-Authored-by: Dan Gohman <dev@sunfishcode.online>

* Exclude atexit.c from LTO

This fixes a failure in wasi-sdk "make check".
("undefined symbol: __cxa_atexit" for ctors_dtors.c test)

* avoid specifying multiple lto flags for LIBC_NONLTO_OBJS

---------

Co-authored-by: Dan Gohman <dev@sunfishcode.online>
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.

4 participants