Bug 253716

Summary: LTO seems to be broken in 13-BETA3
Product: Base System Reporter: dmilith <dmilith>
Component: binAssignee: Kubilay Kocak <koobs>
Status: Closed Overcome By Events    
Severity: Affects Some People CC: dim, kevans, lwhsu, toolchain
Priority: --- Keywords: needs-qa, regression
Version: 13.0-STABLEFlags: koobs: mfc-stable13?
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
LTO error none

Description dmilith 2021-02-20 10:10:51 UTC
My software build system's been using LTO for builds for years now.
I append "-flto=thin -ffat-lto-objects -fuse-linker-plugin -Wl,--thinlto-jobs=8" to CFLAGS/CXXFLAGS and it worked nicely until 13-BETA1 (last tested one).

Yesterday I updated to 13-BETA3, and same options now cause linker issues.

Example for Make 4.3:

http://s.verknowsys.com/a1b9805fa9c33b148d5ef8d479f3f47c.png

(it also breaks with fat LTO enabled, not only with Thin)

It builds fine if I just remove "-flto" option.
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2021-02-22 13:50:38 UTC
I took a little bit of a look at this, and noted that lib/findprog-in.o -> lib/libgnu.a which does appear on the cut off part of the linker command that fails in the picture. AFAICT find_in_given_path does make the trip into libgnu.a, annotated like so:

define dso_local i8* @find_in_given_path(i8* %0, i8* %1, i1 zeroext %2) local_unnamed_addr #0 {
^4 = gv: (name: "find_in_given_path", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 119, calls: ((callee: ^9), (callee: ^5), (callee: ^8), (callee: ^3), (callee: ^13), (callee: ^11), (callee: ^2), (callee: ^6), (callee: ^10)), refs: (^14, ^15)))) ; guid = 1239841682990232801
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2021-02-22 14:19:22 UTC
Can you come up with an actual test case? Saying "it doesn't work for my application which I'm not giving any details about except a screenshot" is not very helpful...
Comment 3 Kyle Evans freebsd_committer freebsd_triage 2021-02-22 14:21:57 UTC
(In reply to Dimitry Andric from comment #2)

This reproduces easily enough with devel/gmake (the port representation of what they're trying to build) and the listed CFLAGS/CXXFLAGS pushed into the port's Makefile
Comment 4 dmilith 2021-03-06 22:16:01 UTC
It's not only gmake. Also db 6.2.23 fails with:

ld.lld: error: undefined symbol: __db_getulong
>>> referenced by db_load.c:1606 (/Software/Imagemagick/.src_7f0a4dfd9c5d9e10/db-6.2.23/build_unix/../util/db_load.c:1606)
>>>               /User/.sofin/lto-cache/Thin-c858dd.tmp.o:(dbt_to_recno)
>>> referenced by db_load.c:1585 (/Software/Imagemagick/.src_7f0a4dfd9c5d9e10/db-6.2.23/build_unix/../util/db_load.c:1585)
>>>               /User/.sofin/lto-cache/Thin-c858dd.tmp.o:(dbt_rrecno)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It's from 13.0-RC1
Comment 5 Kubilay Kocak freebsd_committer freebsd_triage 2021-03-26 01:09:15 UTC
Created attachment 223592 [details]
LTO error

Attach image referenced in comment 0 so it doesn't link rot
Comment 6 dmilith 2021-04-14 15:10:24 UTC
Can't reproduce anymore on 13-RC5 and 13.0-RELEASE :)
Comment 7 Kubilay Kocak freebsd_committer freebsd_triage 2021-04-15 02:38:53 UTC
^Triage: 

- Correct resolution (FIXED is resolution by way of change (commit, usually)). Closing OBE unless resolving commit(s) are identified

- Assign to committer resolving