Skip to content

Adding LTO options#692

Merged
quic-seaswara merged 10 commits intomainfrom
lto-options-2
Feb 4, 2026
Merged

Adding LTO options#692
quic-seaswara merged 10 commits intomainfrom
lto-options-2

Conversation

@quic-akaryaki
Copy link
Copy Markdown
Contributor

No description provided.

@quic-akaryaki quic-akaryaki force-pushed the lto-options-2 branch 3 times, most recently from 0e3fe1c to 5f1c4cc Compare January 8, 2026 20:02
@quic-akaryaki quic-akaryaki force-pushed the lto-options-2 branch 3 times, most recently from efde665 to 16da071 Compare January 20, 2026 20:50
@quic-akaryaki quic-akaryaki marked this pull request as ready for review January 20, 2026 21:25
@quic-akaryaki quic-akaryaki changed the title Refactor LTO compilation Adding LTO options Jan 20, 2026
@quic-akaryaki quic-akaryaki marked this pull request as draft January 20, 2026 23:09
@quic-akaryaki quic-akaryaki force-pushed the lto-options-2 branch 2 times, most recently from 6511b66 to c03a043 Compare January 21, 2026 21:15
@quic-akaryaki quic-akaryaki marked this pull request as ready for review January 22, 2026 16:48
@quic-seaswara
Copy link
Copy Markdown
Contributor

Overall it LGTM with some minor nits.

Sorry for my late initial review.

I have few comments to begin with before I start doing a thorough review

  • The tests added assume that they run on linux, they would need to be made UNSUPPORTED for windows

This is the most important for now, since we are at the 22.0 release point. Other comments can wait and can be done in a follow up.

  • Diagnostics improvements such as the below (ld.eld --lto-obj-path=/usr/bin/ 1.o --save-temps) can be early detected before the linker ? Compare lld behavior and error out.
  • Help menu options can be spelled of what kind of values they take.
  • Please document the options being added with a close attention on any behavioral changes to options, I hope there is none.

Do we need to make any changes to LTO and linker script support related to these options ? Just trying to make sure.

Any changes to LTO (plugin) infrastructure ?

I will try to go over the code in detail and have comments.

@quic-akaryaki
Copy link
Copy Markdown
Contributor Author

Overall it LGTM with some minor nits.

Sorry for my late initial review.

I have few comments to begin with before I start doing a thorough review

  • The tests added assume that they run on linux, they would need to be made UNSUPPORTED for windows

I disabled one test that uses /dev/null. I don;t see other linux assumptions. The windows builder for a branch is broken, unfortunately.

This is the most important for now, since we are at the 22.0 release point. Other comments can wait and can be done in a follow up.

  • Diagnostics improvements such as the below (ld.eld --lto-obj-path=/usr/bin/ 1.o --save-temps) can be early detected before the linker ? Compare lld behavior and error out.

I don't think lld does any of that.

  • Help menu options can be spelled of what kind of values they take.

Options that take paths or numbers describe that in the help string. --lto-obj-path was missing the description, which I will add.

  • Please document the options being added with a close attention on any behavioral changes to options, I hope there is none.

Will be done separately.

Do we need to make any changes to LTO and linker script support related to these options ? Just trying to make sure.

No.

Any changes to LTO (plugin) infrastructure ?

No.

I will try to go over the code in detail and have comments.

Copy link
Copy Markdown
Contributor

@quic-seaswara quic-seaswara left a comment

Choose a reason for hiding this comment

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

$ ld.lld --lto-obj-path=/usr/bin/ 1.o
ld.lld: error: cannot create /usr/bin/: Is a directory
LLVM ERROR: IO failure on output stream: Bad file descriptor

With your patch, we get

"UNEXPECTED LINKER BEHAVIOR"

Comment thread lib/Object/ObjectLinker.cpp
Comment thread test/lld/ELF/obj-path.test
Comment thread test/lld/ELF/obj-path.test Outdated
Comment thread test/lld/ELF/obj-path.test Outdated
Comment thread test/lld/ELF/obj-path.test Outdated
Comment thread lib/Object/ObjectLinker.cpp
Comment thread include/eld/Driver/GnuLinkerOptions.td
Comment thread include/eld/Driver/GnuLinkerOptions.td
Comment thread include/eld/Config/GeneralOptions.h
Comment thread include/eld/Config/GeneralOptions.h
@quic-akaryaki
Copy link
Copy Markdown
Contributor Author

quic-akaryaki commented Jan 30, 2026

--lto-obj-path=/usr/bin/ 1.o

This happens due to report_fatal_error() in the LTO backend on the compiler side. Unfortunately, there is no graceful error handling. To fix this, we need changes in the upstream compiler code. lld does not suffer from this problem because it provides memory streams to the compiler and then saves the content in files later. eld's approach seems overall better to me as additional copy is avoided. I don't see a good fix here, other than creating a dummy file before which seems a little gross to me.

TMP=/usr/bin ld.eld 1.o may be similar (but note exactly the same).

@quic-akaryaki quic-akaryaki force-pushed the lto-options-2 branch 3 times, most recently from 403ca69 to ea7a0ce Compare January 30, 2026 21:47
ObjectLinker::doLto() had convoluted flow, duplicated pieces of code
in different branches, etc. Simplify and clarify it.

There is no functional change, except when both `lto-asm-file` and
`lto-output-file` specified, on Hexagon only, a misleading message
about using the asm file is not printed. When `lto-output-file`,
the assembly inputs are ignored, this did not change, and the message
was incorrect.

Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
These options have aliases:

--plugin-opt=cs-profile-generate
--plugin-opt=cs-profile-path=

Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
--lto-obj-path will work differently than in lld. In lld, it creates
copies of LTO output files, which means with `-save-temps` each object
file will be written twice. Instead, we will redirect output files
to the location specified by `--lto-obj-path`, which means these files
will not be written to the `-save-temps` location if it is specified.

Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
Add missing MetaVarName and group to --dwodir, --lto-O, and
--lto-sample-profile. Fix MetaVarName for --save-temps=.

Signed-off-by: Alexey Karyakin <akaryaki@qti.qualcomm.com>
@quic-seaswara quic-seaswara merged commit 5e4b9cc into main Feb 4, 2026
3 checks passed
@quic-seaswara quic-seaswara deleted the lto-options-2 branch February 4, 2026 20:32
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.

2 participants