Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Mar 2012 13:24:46 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        ia64@freebsd.org
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r233674 - head/libexec/rtld-elf
Message-ID:  <20120330102446.GF2358@deviant.kiev.zoral.com.ua>
In-Reply-To: <20120329181125.GB2358@deviant.kiev.zoral.com.ua>
References:  <201203291750.q2THo1Pu003875@svn.freebsd.org> <20120329181125.GB2358@deviant.kiev.zoral.com.ua>

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

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

On Thu, Mar 29, 2012 at 09:11:25PM +0300, Konstantin Belousov wrote:
> On Thu, Mar 29, 2012 at 05:50:01PM +0000, Konstantin Belousov wrote:
> > Author: kib
> > Date: Thu Mar 29 17:50:01 2012
> > New Revision: 233674
> > URL: http://svn.freebsd.org/changeset/base/233674
> >=20
> > Log:
> >   Fix ia64 build after r233655.
> >  =20
> >   MFC after:	1 week
> >=20
> > Modified:
> >   head/libexec/rtld-elf/rtld.c
> >=20
> > Modified: head/libexec/rtld-elf/rtld.c
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
> > --- head/libexec/rtld-elf/rtld.c	Thu Mar 29 17:39:18 2012	(r233673)
> > +++ head/libexec/rtld-elf/rtld.c	Thu Mar 29 17:50:01 2012	(r233674)
> > @@ -2618,7 +2618,9 @@ do_dlsym(void *handle, const char *name,
> >      const Elf_Sym *def;
> >      SymLook req;
> >      RtldLockState lockstate;
> > +#ifndef __ia64__
> >      tls_index ti;
> > +#endif
> >      int res;
> > =20
> >      def =3D NULL;
> > @@ -2734,9 +2736,13 @@ do_dlsym(void *handle, const char *name,
> >  	else if (ELF_ST_TYPE(def->st_info) =3D=3D STT_GNU_IFUNC)
> >  	    return (rtld_resolve_ifunc(defobj, def));
> >  	else if (ELF_ST_TYPE(def->st_info) =3D=3D STT_TLS) {
> > +#ifdef __ia64__
> > +	    return (__tls_get_addr(defobj->tlsindex, def->st_value));
> > +#else
> >  	    ti.ti_module =3D defobj->tlsindex;
> >  	    ti.ti_offset =3D def->st_value;
> >  	    return (__tls_get_addr(&ti));
> > +#endif
> >  	} else
> >  	    return (defobj->relocbase + def->st_value);
> >      }
> While this band-aid fixes the build, the change is obviously bad.
> The reason to have this #ifdef is that ia64 is the only architecture
> that declares __tls_get_addr() as
>=20
> void *__tls_get_addr(unsigned long module, unsigned long offset);
>=20
> while all other architectures do
>=20
> typedef struct {
>     unsigned long ti_module;
>     unsigned long ti_offset;
> } tls_index;
> void *__tls_get_addr(tls_index *ti);
>=20
> But e.g. on amd64 the ABI of both declarations is the same. From my
> cursory look at ia64 ABI document, the same hold for ia64.
Answering my own question, no, it is not the same ABI on amd64.
It would be if __tls_get_addr() took tls_index, and not pointer to
tls_index. This is the part which I missed.

It is indeed the same ABI on ia64, but due to different calling conventions
(pass by value on ia64 vs. pointer to structure on everything else) the
patch below cannot work.

Sorry for the noise.
>=20
> Can anybody with ia64 clue and test machine confirm that the following
> works, i.e. ABI is not broken ?
>=20
> diff --git a/libexec/rtld-elf/ia64/reloc.c b/libexec/rtld-elf/ia64/reloc.c
> index 01e20b8..31319f3 100644
> --- a/libexec/rtld-elf/ia64/reloc.c
> +++ b/libexec/rtld-elf/ia64/reloc.c
> @@ -650,9 +650,9 @@ allocate_initial_tls(Obj_Entry *list)
>      __asm __volatile("mov r13 =3D %0" :: "r"(tpval));
>  }
> =20
> -void *__tls_get_addr(unsigned long module, unsigned long offset)
> +void *__tls_get_addr(tls_index *ti)
>  {
>      register Elf_Addr** tp __asm__("r13");
> =20
> -    return tls_get_addr_common(tp, module, offset);
> +    return tls_get_addr_common(tp, ti->ti_module, ti->ti_offset);
>  }
> diff --git a/libexec/rtld-elf/ia64/rtld_machdep.h b/libexec/rtld-elf/ia64=
/rtld_machdep.h
> index 4a68ff7..df877f2 100644
> --- a/libexec/rtld-elf/ia64/rtld_machdep.h
> +++ b/libexec/rtld-elf/ia64/rtld_machdep.h
> @@ -64,7 +64,12 @@ void call_init_pointer(const struct Struct_Obj_Entry *=
, Elf_Addr);
>  	round(prev_offset + prev_size, align)
>  #define calculate_tls_end(off, size) 	((off) + (size))
> =20
> -extern void *__tls_get_addr(unsigned long module, unsigned long offset);
> +typedef struct {
> +    unsigned long ti_module;
> +    unsigned long ti_offset;
> +} tls_index;
> +
> +extern void *__tls_get_addr(tls_index *ti);
> =20
>  #define	RTLD_DEFAULT_STACK_PF_EXEC	0
>  #define	RTLD_DEFAULT_STACK_EXEC		0
> diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
> index d3ce3c6..828b8b4 100644
> --- a/libexec/rtld-elf/rtld.c
> +++ b/libexec/rtld-elf/rtld.c
> @@ -2618,9 +2618,7 @@ do_dlsym(void *handle, const char *name, void *reta=
ddr, const Ver_Entry *ve,
>      const Elf_Sym *def;
>      SymLook req;
>      RtldLockState lockstate;
> -#ifndef __ia64__
>      tls_index ti;
> -#endif
>      int res;
> =20
>      def =3D NULL;
> @@ -2736,13 +2734,9 @@ do_dlsym(void *handle, const char *name, void *ret=
addr, const Ver_Entry *ve,
>  	else if (ELF_ST_TYPE(def->st_info) =3D=3D STT_GNU_IFUNC)
>  	    return (rtld_resolve_ifunc(defobj, def));
>  	else if (ELF_ST_TYPE(def->st_info) =3D=3D STT_TLS) {
> -#ifdef __ia64__
> -	    return (__tls_get_addr(defobj->tlsindex, def->st_value));
> -#else
>  	    ti.ti_module =3D defobj->tlsindex;
>  	    ti.ti_offset =3D def->st_value;
>  	    return (__tls_get_addr(&ti));
> -#endif
>  	} else
>  	    return (defobj->relocbase + def->st_value);
>      }



--PTB34xPa4pLPpogV
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAk91ie4ACgkQC3+MBN1Mb4gNDgCglpceGqsElMwUlWjHlwOxSkBa
u+4AoJVZmVTqHeEQZ6dDbS/t2GcWc9SN
=rZYw
-----END PGP SIGNATURE-----

--PTB34xPa4pLPpogV--



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