From: Marek Behun Date: Mon, 8 Mar 2021 11:11:03 +0100 Subject: [PATCH u-boot 16/39] build: use thin archives instead of incremental linking In-Reply-To: References: <20210307042538.21229-1-marek.behun@nic.cz> <20210307042538.21229-17-marek.behun@nic.cz> Message-ID: <20210308111103.2be27c52@nic.cz> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Mon, 8 Mar 2021 17:16:03 +0800 Bin Meng wrote: > Hi Marek, > > On Sun, Mar 7, 2021 at 12:26 PM Marek Beh?n wrote: > > > > Currently we use incremental linking (ld -r) to link several object > > files from one directory into one built-in.o object file containing the > > linked code from that directory (and its subdirectories). > > > > Linux has, some time ago, moved to thin archives instead. > > > > Thin archives are archives (.a) that do not really contain the object > > files, only references to them. > > > > Using thin archives instead of incremental linking > > - saves disk space > > - apparently works better with dead code elimination > > - makes things easier for LTO > > > > The third point is the important one for us. With incremental linking > > there are several options how to do LTO, and that would unnecessarily > > complicate things. > > > > On the other hand, by using thin archives we can make (via the > > --whole-archive use flag) the final linking behave as if we passed all > > the object files from the archives to the linking program as arguments. > > I don't think --whole-archive is required for LTO to work. It is. Linking fails if it is not used, for example for nokia_rx51_defconfig. > Switching to --whole-archive should be made conditionally when LTO is on, > otherwise for targets that don't have > -ffunction-sections/data-sections/--gc-sections specified, it will > create unnecessary bloat. OK I will push into CI without this flag for non-LTO and if it passes all tests I shall remove this flag for non-LTO. Marek