From owner-freebsd-toolchain@freebsd.org Mon Aug 1 21:40:29 2016 Return-Path: Delivered-To: freebsd-toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 15505BAB317 for ; Mon, 1 Aug 2016 21:40:29 +0000 (UTC) (envelope-from carpeddiem@gmail.com) Received: from mail-it0-x22f.google.com (mail-it0-x22f.google.com [IPv6:2607:f8b0:4001:c0b::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D4A7A1D6E for ; Mon, 1 Aug 2016 21:40:28 +0000 (UTC) (envelope-from carpeddiem@gmail.com) Received: by mail-it0-x22f.google.com with SMTP id j124so185612370ith.1 for ; Mon, 01 Aug 2016 14:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to :content-transfer-encoding; bh=3M31D53slzTYxWhYaS5/bHmxo+Sxuww85hv1WXfg7rE=; b=k3V5RX4LY25juNMbYUhKT9Ucq1GxttZGbdyh0/VJWVdlmd5hWCNIveJwtBroEu+zaR r95BYmyG0bkFkCIuZudXr3O53rFKl2M2pa90SzwE7osZd71WR3hqeTYdUe6fJxIBzkSF Carbbj4RTlDzvMfoAT+jABf9q9caLfikZH2DH4XXJig8IshZiSmaXqOSM8HFApGG2EE6 oeZtTiQXT630gV0znqhWesb8Yaxqe5N4+uzLWpBqFqyXQGIpCbd1eyRShzAQ+goAAfSk DG1aBfTCpDUFOASbyv4hTec0C9sTS9CcBtDLwHqg4IFkixOGIe9Wr6f3c7Fq+yDsfV5j K1xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:content-transfer-encoding; bh=3M31D53slzTYxWhYaS5/bHmxo+Sxuww85hv1WXfg7rE=; b=STBVLIpLz4/IkUpPi1+t1NBVDOCbuJFbaEhrL+vVoTvKNz2WSOeBowPllCM9QcK6Zk 7teuh4kzbS5o2x3QTkbgIvGOJnhOVFtVHnd89TxqbglSNcxe6BQgZscka+aOAqzeaCTp RldAjgHM6PBUyvJ+Ud+SiKy+xjkflsCvBhtMeJD0DbgAf1B2W6t+RngvyNbasiAUIpZS Qsf6Jn7u0zN/eILfnOKMyhG8DjLt2KWSe3OXWDfw9FV9qQUgAlHSPo+2ZXiW2/9uI2WW kjqAOzRhtyGxE5RXR9O1jbUi+mX7y9XgwsakELgRo9vDl62TRKQfJUe9cs1Rq+S9fqjQ 2xgA== X-Gm-Message-State: AEkoous/vUAjOitURHwlLOh8zTtmmwOp/AVUqCVpB34x0VTBKl8ACiB6MwrulGD9BwkY7lU5Doq3V0UzBsqofw== X-Received: by 10.36.86.134 with SMTP id o128mr63373879itb.5.1470087628002; Mon, 01 Aug 2016 14:40:28 -0700 (PDT) MIME-Version: 1.0 Sender: carpeddiem@gmail.com Received: by 10.107.138.28 with HTTP; Mon, 1 Aug 2016 14:40:07 -0700 (PDT) From: Ed Maste Date: Mon, 1 Aug 2016 17:40:07 -0400 X-Google-Sender-Auth: op7nd7ahyYIsdlOfGRorcQT_9X8 Message-ID: Subject: Update on using LLVM's lld linker in the FreeBSD base system To: "freebsd-toolchain@freebsd.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2016 21:40:29 -0000 Over the past year or so I have been investigating the state of LLVM's lld linker for use in the FreeBSD base system, to see if it could be used as FreeBSD's system linker. Why do we need a new linker? Compared to the GNU ld 2.17.50 that we have in the FreeBSD base system, lld will bring: * AArch64 (arm64) support * Link Time Optimization (LTO) * New ABI support * Other linker optimization * Much faster link times * Maintained code base I've posted a couple of status updates on the LLVM mailing list: http://lists.llvm.org/pipermail/llvm-dev/2015-November/092572.html http://lists.llvm.org/pipermail/llvm-dev/2016-March/096449.html Since the last update in March several lld developers have implemented much of the missing functionality. The main blockers were symbol version support and expression evaluation in the linker script expression parser. Both are now nearly complete. There are a few features used by the FreeBSD base system that lld developers (intentionally) do not expect to implement, unless they're reasonably widely used in a variety of different software. If they're not implemented we can modify FreeBSD to avoid using them. I'm aware of: -N/--omagic, used by some boot loader components. We can achieve the same effect with a linker script. -dc, used by the rescue build. As long as object files are built specifically for rescue we can probably use -fno-common instead. -r binary to convert binary files into ELF objects, used by some device drivers in kernel and module builds. We can use objcopy(elfcopy) instead. Davide Italiano and Rafael =C3=81vila de Esp=C3=ADndola presented an update= on the state of lld at BSDCan 2016: https://www.bsdcan.org/2016/schedule/events/656.en.html At this point I'm confident that lld is going to be a viable linker for the FreeBSD base system, and am beginning to plan its import. I expect the process will look something like this: 1. Update lld along with the Clang/LLVM 3.9 update that dim@ is working on. 2. Add the bmake build infrastructure, installing as /usr/bin/ld.lld on the same architectures that use Clang (amd64, arm, arm64, i386). I don't think there's a need for a WITH_LLD src.conf knob, but will add one if desired. 3. Update lld again (most likely to a snapshot from upstream SVN) once it is able to link an unmodified FreeBSD kernel. 4. Modify the boot loader and kernel builds to avoid using features not implemented by lld. 5. Introduce a WITH_LLD_AS_LD knob to have /usr/bin/ld be a ld.lld hardlink instead of /usr/bin/ld.bfd. 6. Request ports exp-runs and issue a call for testing with 3rd party software. Fix issues found during this process. 7. Switch /usr/bin/ld to ld.lld by default in head for the Clang-using architectures. Add a WITHOUT_LLD_AS_LD knob to switch back to GNU ld. There is (some) support for mips and powerpc in lld, but I'm not sure how well tested it is. RISC-V is not yet supported but there is a desire to have a full LLVM-based RISC-V toolchain. I'm not aware of any plan with respect to sparc64 in lld. In any case, I do not plan to address these architectures in the initial lld work. In the near term they will continue to use GNU ld 2.17.50. I'm interested in your comments, questions and concerns about this plan.