Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Jul 2014 03:45:37 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Ian Lepore <ian@FreeBSD.org>
Cc:        hackers@freebsd.org
Subject:   Re: [CFR] Adding a function to rtld-elf.so, how to handle Symbol.map?
Message-ID:  <20140717004537.GE93733@kib.kiev.ua>
In-Reply-To: <1405545833.1312.84.camel@revolution.hippie.lan>
References:  <1405545833.1312.84.camel@revolution.hippie.lan>

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

--LgQaYbqhrDFEl/u2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jul 16, 2014 at 03:23:53PM -0600, Ian Lepore wrote:
> I need to add an ARM-specific function to rtld-elf.so to help locate
> exception unwind info in shared objects.  I'm confused about how to add
> the function to Symbol.map... do I have to add a 1.4 section because it
> was first added in FreeBSD 11, or does it go into an existing section
> because it doesn't introduce changes to an existing ABI?
>=20
> -- Ian
>=20
There is no sense in continuing iterating if the pc value falls into the
segment range, but segment does not have PF_X permission bit; there may
be at most one segment mapped at the given address.  That said, the
_rtld_addr_phdr() is more suitable function to use for findexcb(), since
it provides you with the needed object directly, without iterating on
the previously loaded objects.

Why do you need the __gnu_Unwind_Find_exidx() be the part of rtld ?
I do not see a reason for e.g. libc/arm not be a good home for the
function.  We try to not extend the ABI of rtld unless there are
very strong reasons.  The function implementation does not use any
internal rtld structures, only external interfaces.

What is the supposed use of the function ? Are the consumers of it
only the system libraries, or is it planned that user binaries will
reference the symbol directly from their symbol table ?

If first, the place for the symbol is FBSDprivate_1.0 namespace.
If it must be used directly by binaries for which we provide ABI
stability guarantees, than FBSD_1.4 is the correct namespace to
put the symbol into, regardless of the shared object which would
provide it.

> diff -r 63a383d5fd3e libexec/rtld-elf/Symbol.map
> --- libexec/rtld-elf/Symbol.map	Thu May 01 08:14:39 2014 -0600
> +++ libexec/rtld-elf/Symbol.map	Wed Jul 16 15:06:30 2014 -0600
> @@ -20,6 +20,7 @@ FBSD_1.0 {
> =20
>  FBSD_1.3 {
>      fdlopen;
> +    __gnu_Unwind_Find_exidx;
>  };
> =20
>  FBSDprivate_1.0 {
> diff -r 63a383d5fd3e libexec/rtld-elf/arm/Makefile.inc
> --- libexec/rtld-elf/arm/Makefile.inc	Thu May 01 08:14:39 2014 -0600
> +++ libexec/rtld-elf/arm/Makefile.inc	Wed Jul 16 15:06:30 2014 -0600
> @@ -1,1 +1,5 @@
>  # $FreeBSD: head/libexec/rtld-elf/arm/Makefile.inc 130646 2004-06-17 17:=
53:16Z cognet $
> +
> +SRCS+=3D find_exidx.c
> +CFLAGS+=3D -I${TOPSRCDIR}/contrib/libexecinfo
> +
> diff -r 63a383d5fd3e libexec/rtld-elf/arm/find_exidx.c
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ libexec/rtld-elf/arm/find_exidx.c	Wed Jul 16 15:06:30 2014 -0600
> @@ -0,0 +1,103 @@
> +/*-
> + * Copyright (c) 2014 Ian Lepore <ian@freebsd.org>
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distributio=
n.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PU=
RPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIAB=
LE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUE=
NTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOO=
DS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S=
TRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY=
 WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include <sys/cdefs.h>
> +__FBSDID("$FreeBSD$");
> +
> +#include <sys/types.h>
> +#include <sys/elf_common.h>
> +#include <sys/link_elf.h>
> +#include <machine/elf.h>
> +#include <stddef.h>
> +#include <unwind.h>	/* This is contrib/libexecinfo/unwind.h */
> +
> +/*
> + * ARM EABI unwind helper for dynamically linked code.
> + *
> + * This code iterates all shared objects that have been loaded, looking =
for one
> + * whose in-memory text address range contains the given PC.  It returns=
 the
> + * address of the exidx section in that shared object along with the num=
ber of
> + * entries in that section, or NULL if it wasn't found.  This overrides a
> + * weak-linkage default implementation in the unwinder library that only=
 works
> + * for a static-linked application.
> + */
> +
> +struct cbdata {
> +	_Unwind_Ptr pc;
> +	_Unwind_Ptr exptr;
> +	int         excount;
> +};
> +
> +static int
> +findexcb(struct dl_phdr_info *info, size_t size, void *data)
> +{
> +	struct cbdata * cbd;
> +	const Elf_Phdr *hdr;
> +	Elf_Addr exptr, pc, vaddr;
> +	Elf_Word len;
> +	int i, exlen, found;
> +	const int FOUND_PC =3D 0x01;
> +	const int FOUND_EX =3D 0x02;
> +	const int SIZEOF_EIT_ENTRY =3D 8; /* Not available in a header file. */
> +
> +	cbd =3D data;
> +	found =3D 0;
> +	pc =3D (Elf_Addr)cbd->pc;
> +	for (i =3D 0, hdr =3D info->dlpi_phdr; i < info->dlpi_phnum; i++, hdr++=
) {
> +		vaddr =3D info->dlpi_addr + hdr->p_vaddr;
> +		len =3D hdr->p_memsz;
> +		if (hdr->p_type =3D=3D PT_LOAD && (hdr->p_flags & PF_X) !=3D 0 &&
> +		    pc >=3D vaddr && pc < vaddr + len) {
> +			found |=3D FOUND_PC;
> +		} else if (hdr->p_type =3D=3D PT_ARM_EXIDX) {
> +			found |=3D FOUND_EX;
> +			exptr =3D vaddr;
> +			exlen =3D len;
> +		}
> +		if (found =3D=3D (FOUND_PC | FOUND_EX)) {
> +			cbd->exptr =3D (_Unwind_Ptr)(exptr);
> +			cbd->excount =3D exlen / SIZEOF_EIT_ENTRY;
> +			return (1); /* Stop iterating. */
> +		}
> +	}
> +	return (0); /* Continue iterating with next object. */
> +
> +}
> +
> +_Unwind_Ptr
> +__gnu_Unwind_Find_exidx(_Unwind_Ptr pc, int * pcount)
> +{
> +	struct cbdata cbd;
> +
> +	cbd.pc =3D pc;
> +	cbd.exptr =3D NULL;
> +	cbd.excount =3D 0;
> +	dl_iterate_phdr(findexcb, &cbd);
> +	if (cbd.exptr !=3D NULL)
> +		*pcount =3D cbd.excount;
> +	return (cbd.exptr);
> +}
> +
> diff -r 63a383d5fd3e sys/arm/include/elf.h
> --- a/sys/arm/include/elf.h	Thu May 01 08:14:39 2014 -0600
> +++ b/sys/arm/include/elf.h	Wed Jul 16 15:06:30 2014 -0600
> @@ -55,6 +55,9 @@ typedef struct {        /* Auxiliary vec
> =20
>  #define	ELF_MACHINE_OK(x) ((x) =3D=3D EM_ARM)
> =20
> +/* Unwind info section type */
> +#define	PT_ARM_EXIDX (PT_LOPROC + 1)
> +
>  /*
>   * Relocation types.
>   */

> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


--LgQaYbqhrDFEl/u2
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJTxxywAAoJEJDCuSvBvK1B9BMP/1oKtgqaMfjYBAQOKrYJC9UN
z5ttsdEssRNNco+uEQz1RZjhZ1vnCk4FDR6PhTH/R5ADVUdzeIBPrks3etKe9uKb
F1wMolPyV3DLRkRX8+B/qa6i+XwMCIeEc4wAC9/6ZL7TyNrIzcWz66a+Hq07F7or
Ja0N/qsnCGNxyXp57GcvEpog95EvMyGWj3mOcH8XO8owoPBZYGa4vvESKdiP3YaZ
QTIoi/kbIA/3oLkbhTE7p+DY/eZY7CBPcaT/TxqDGWZY5uyaYhnKYjjDZwZOmQYD
ojj66YZLJU9KhkT3QL+KryNbXqvH+6b9ri21iRZOnU0VX71EdB9DRs6iv2i1VDUU
arl6OrzO4SvUWpwNRtd7n2gaeOuxy6lItsFflkY1enh7fp/drzAJRrOO9NbNH41G
2oQSTETZTknfmYn3rEbJltBG3cytH7VbuTsO91AUXMMkmGt/0evbF8y9/qFz4JMg
ChhRjwC69JHpZDY3on2p9m7d2eibAeux7EcLLm5zfV9ytyYUKuI4KWnvVF6hw+0G
b70ZUkbV2Mnx5ViyWFYMuenMre7KQwLColfReRUuaMf4LcCFXEUk3LN6bsRU3Y2j
J8RmX0M1KnG3cvMNZXzVnNGuE/PuXccl8NVxenB52yfxw67InC1y7A7ZY3IUrXJb
G/keycMglBUR9UkqWGrK
=wq5B
-----END PGP SIGNATURE-----

--LgQaYbqhrDFEl/u2--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140717004537.GE93733>