Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Mar 2018 22:54:25 +0100
From:      Dimitry Andric <dim@FreeBSD.org>
To:        Shawn Webb <shawn.webb@hardenedbsd.org>
Cc:        FreeBSD Toolchain <freebsd-toolchain@freebsd.org>, Rafael Avila de Espindola <rafael.espindola@gmail.com>
Subject:   Re: Compiling libc with LTO
Message-ID:  <71B87A25-2909-47A2-9606-2508CA674A94@FreeBSD.org>
In-Reply-To: <20180304231106.57dvw6psfpwnedbd@mutt-hbsd>
References:  <20180304231106.57dvw6psfpwnedbd@mutt-hbsd>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_CFA94E0E-9FED-4ACE-81D7-236D0B003962
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

On 5 Mar 2018, at 00:11, Shawn Webb <shawn.webb@hardenedbsd.org> wrote:
>=20
> I'm working on Cross-DSO CFI support in HardenedBSD. I've noticed
> certain libraries do not like to be compiled with -flto, libc being
> one of them. I'm scratching my head a bit, but unsure where to go from
> here, so a little direction would be helpful.
>=20
> In the hardened/current/cross-dso-cfi feature branch of the
> hardenedBSD-playground repo[1], ld.lld, llvm-ar, llvm-nm, and
> llvm-objdump are the default ld, ar/ranlib, nm, and objdump
> respectively. The first step for Cross-DSO CFI support is compiling
> all shared and static libraries with LTO.
>=20
> I'm curious if this is a shortcoming of ld.lld and I should file a bug
> with the llvm project (if one's not already filed). I've heard that
> someone got FreeBSD compiled with LTO already, so I'm hoping to borrow
> some of their expertise.
>=20
> Here's a log of the build (warning: large file):
> =
https://gist.githubusercontent.com/anonymous/f8617d629fd054479142cc4b6de35=
81e/raw/b94579fac987556c01ae0aab7e2943d25d27bcc4/libc.log
>=20
> Essentially, the erroring lines are:
>=20
> /usr/obj/scratch/src/cross-dso-cfi/amd64.amd64/tmp/usr/bin/ld: error: =
swapcontext.pico: symbol swapcontext@@@FBSD_1.2 has undefined version =
@FBSD_1.2
> /usr/obj/scratch/src/cross-dso-cfi/amd64.amd64/tmp/usr/bin/ld: error: =
openat.pico: symbol openat@@@FBSD_1.2 has undefined version @FBSD_1.2
> /usr/obj/scratch/src/cross-dso-cfi/amd64.amd64/tmp/usr/bin/ld: error: =
setcontext.pico: symbol setcontext@@@FBSD_1.2 has undefined version =
@FBSD_1.2

I can at least reproduce these errors, and it seems strange that the
symbols in question end up with three @ signs, e.g. the LLVM IR in
swapcontext.pico has:

module asm ".ident\09\22$FreeBSD$\22"
module asm ".weak __swapcontext"
module asm ".equ __swapcontext, __sys_swapcontext"
module asm ".symver __impl_swapcontext, swapcontext@FBSD_1.0"
module asm ".weak __impl_swapcontext"
module asm ".equ __impl_swapcontext, swapcontext"
module asm ".symver swapcontext, swapcontext@@@FBSD_1.2"

It seems the linker has special handling for @@@, as per:

https://github.com/llvm-mirror/lld/blob/master/ELF/SymbolTable.cpp#L320

but I am unsure as to why this does not appear to work with -flto.
Maybe Rafael has any ideas?

-Dimitry


--Apple-Mail=_CFA94E0E-9FED-4ACE-81D7-236D0B003962
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename=signature.asc
Content-Type: application/pgp-signature;
	name=signature.asc
Content-Description: Message signed with OpenPGP

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.2

iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCWp28kQAKCRCwXqMKLiCW
oxHDAJ4qREeMeWQpo/w9msC2fe/Ms9fYoQCfXNDKntjz0ZaE/Xs6Rii/acstaSI=
=B+Oq
-----END PGP SIGNATURE-----

--Apple-Mail=_CFA94E0E-9FED-4ACE-81D7-236D0B003962--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?71B87A25-2909-47A2-9606-2508CA674A94>