From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8703 Path: news.gmane.org!not-for-mail From: Mahesh Bodapati Newsgroups: gmane.linux.lib.musl.general Subject: Re: musl mips n64 dynamic build Date: Tue, 20 Oct 2015 15:14:04 +0530 Message-ID: References: <20151019151840.GM8645@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01161d00337dbf0522861a2e X-Trace: ger.gmane.org 1445334267 6991 80.91.229.3 (20 Oct 2015 09:44:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 20 Oct 2015 09:44:27 +0000 (UTC) Cc: musl@lists.openwall.com To: Rich Felker Original-X-From: musl-return-8715-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 20 11:44:26 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZoTSt-0007g9-Jx for gllmg-musl@m.gmane.org; Tue, 20 Oct 2015 11:44:19 +0200 Original-Received: (qmail 9776 invoked by uid 550); 20 Oct 2015 09:44:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9755 invoked from network); 20 Oct 2015 09:44:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=VyhcLbKKOXgqb6CJ40fCErL9Xz8fIkSfE7loXUN67Xk=; b=LainxJZ2CIg3cgUb4DsqS2Vg428LoLUJ+ahMGluIj6yphRFY8xqGTwNhQwkpxuAafX 5Pxu7uST9wvvJBtVIafMtFYx/7s4jGVyv+HdfbjP0vOAYUihqIE2qM5JspTR7V0prBad 7wa7ybW20ZIYonIlxsg4LrIFu0W38ZMBAGV/jrYYGgDFpCE4BhX+w0sTPZewvIWGq2od 3OoVcq1+l2h1/mImCjK8yLTJspI/WLkGXClUa2xubnErMM14/4b+eXUuw9uhbhvzQPLX rDyC8UZBkqf9v+acX54u2i953cvZzKM+Q4H3Ib9YODMTSRiHw9PKORmVVrpV1166AT9L txwg== X-Received: by 10.50.112.100 with SMTP id ip4mr2765748igb.78.1445334244095; Tue, 20 Oct 2015 02:44:04 -0700 (PDT) In-Reply-To: <20151019151840.GM8645@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:8703 Archived-At: --089e01161d00337dbf0522861a2e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Rich, Thanks for Your mail I have ported musl for mips64 arch from porting guide.the list includes crt_arch.h and Now I didn't place crt assembly files for mips64 arch. > That produces a relocation in the elf32 encoding, because I just > assumes mips is elf32 when I wrote it. I believe the 64-bit version > should be: > > rel[1] =3D sym-p->syms << 32 | R_MIPS_JUMP_SLOT; this change resolved some of the relocation type errors but still i am getting some relocation type errors.I think these errors are from do_relocs () Error relocating libc.so: unsupported relocation type 4611 Error relocating libc.so: unsupported relocation type 4611 Error relocating libc.so: unsupported relocation type 4611 Error relocating libc.so: unsupported relocation type 4611 Error relocating libc.so: unsupported relocation type 4611 Error relocating libc.so: unsupported relocation type 4611 ; ; Error relocating libc.so: unsupported relocation type 4611 the relocation type value is 4611 for all the errors. > Did you make a reloc.h defining the relocation types needed for mips > n64 and mapping them to the generic-reloc names musl uses for them? > See the existing arch/*/reloc.h files. Without these being defined > directly the dynamic linker will not be able to process the > relocations it finds in itself or in the main program or other > libraries I have ported reloc.h for mips64 as *bash-3.2$ cat arch/mips64/reloc.h* #include #if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN #define ENDIAN_SUFFIX "el" #else #define ENDIAN_SUFFIX "" #endif #ifdef __mips64_soft_float #define FP_SUFFIX "-sf" #else #define FP_SUFFIX "" #endif #define LDSO_ARCH "mips64" ENDIAN_SUFFIX FP_SUFFIX #define TPOFF_K (-0x7000) *#define REL_SYM_OR_REL R_MIPS_64 /*I didn't see R_MIPS_REL64 so It is a composition of R_MIPS_64 and R_MIPS_REL relocations but i didn't see R_MIPS_REL in elf.h. * * how can i define REL_SYM_OR_REL for mips n64 abi */* #define REL_PLT R_MIPS_JUMP_SLOT #define REL_COPY R_MIPS_COPY #define REL_DTPMOD R_MIPS_TLS_DTPMOD64 #define REL_DTPOFF R_MIPS_TLS_DTPREL64 #define REL_TPOFF R_MIPS_TLS_TPREL64 ; ; #define CRTJMP(pc,sp) __asm__ __volatile__( \ "move $sp,%1 ; jr %0" : : "r"(pc), "r"(sp) : "memory" ) /* JR Rs means jump register PC <- Rs ,jump to the address in the rs*/ #define GETFUNCSYM(fp, sym, got) __asm__ ( \ ".hidden " #sym "\n" \ ".set push \n" \ ".set noreorder \n" \ " bal 1f \n" \ " nop \n" \ " .gpdword . \n" \ " .gpdword " #sym " \n" \ "1: ld %0, ($ra) \n" \ " dsubu %0, $ra, %0 \n" \ " ld $ra, 8($ra) \n" \ " daddu %0, %0, $ra \n" \ ".set pop \n" \ : "=3Dr"(*(fp)) : : "memory", "ra" ) Thanks, Mahesh On Mon, Oct 19, 2015 at 8:48 PM, Rich Felker wrote: > On Mon, Oct 19, 2015 at 02:51:12PM +0530, Mahesh Bodapati wrote: > > Hi Rich, > > > > I have ported musl libraries for MIPS n64 ABI architecture and I have > setup > > $gp as > > > > Crt1.s: > > crt1.s is obsolete and should not be used for new archs. The benefit > to you is that crt_arch.h (the new way of doing it) is a lot easier to > write. All you need to do is jump to the C entry point _start_c with > the right calling convention for a C function and the first 2 argument > slots containing the original stack pointer and a pointer to _DYNAMIC, > respectively. _start_c can be assumed to be defined in the same source > file. > > > *lui $3,%hi(%neg(%gp_rel(_start)))* > > > > * daddu > > $3,$3,$25 /* same in > dlsym.s > > and pipe.s */* > > > > * daddiu $gp,$3,%lo(%neg(%gp_rel(_start)))* > > > > ld $4, %got_disp(main)($gp) # Get main() .. > > Jumping to main from crt1 is not valid. You need to call > __libc_start_main. But if you use crt_arch.h this part happens > automatically for you. > > > I didn=E2=80=99t setup $gp as in MIPS o32 ABI as we shouldn=E2=80=99t u= se _*gp*_disp for > > setting up $gp > > > > =E2=80=9CThe special symbol name _gp_disp, used for relocating the calc= ulation > of gp > > on entry to a DSO in 32-bit files, is > > > > not supported in ELF-64 or in the new 32-bit ABI. Instead, these > relocations > > should be composed with > > > > R_MIPS_GPREL applied to an explicit symbol for the entry point of the > > subprogram > > I'm not sure what document you're quoting, but sometimes these things > express assumptions about a particular usage case that don't apply to > what musl is doing. But you should be able to avoid writing this code > anyway. > > > involves loading the difference between the entry > > > > address of a subprogram s and the runtime gp for establishing gp: > > > > A: lui rx, %hi(%neg(%gp_rel(s)))# load high part of diff > > > > B: daddiu rx, rx, %lo(%neg(%gp_rel(s)))# add low part > > > > C: dadd gp, t9, rx # add to entry address =E2=80=9C > > > > > > > > Now I am able to build dynamic n64 musl libraries and n64 dynamic > > application but it=E2=80=99s not showing any relocation with it > > > > and execution of application is giving errors like =E2=80=9Cunsupported > relocation > > type errors=E2=80=9D > > Did you make a reloc.h defining the relocation types needed for mips > n64 and mapping them to the generic-reloc names musl uses for them? > See the existing arch/*/reloc.h files. Without these being defined > directly the dynamic linker will not be able to process the > relocations it finds in itself or in the main program or other > libraries. > > But without a working crt_arch.h I'm surprised the dynamic linker can > even start at all. Are you sure you're not using the mips32 dynamic > linker? Look at the program headers (using readelf -l) for INTERP. > > > $ objdump -R main > > > > > > > > a.out: file format elf64-tradbigmips > > > > > > > > DYNAMIC RELOCATION RECORDS (none) > > > > > > > > $ ./main > > > > Error relocating libc.so: unsupported relocation type 482431 > > > > Error relocating libc.so: unsupported relocation type 482687 > > > > Error relocating libc.so: unsupported relocation type 482943 > > > > Error relocating libc.so: unsupported relocation type 483199 > > > > ; > > > > ; > > > > ; > > > > Segmentation fault > > > > > > > > So Can you suggest how can I resolve these errors? I am thinking like > > either doing changes in do_mips_reloc(),do_relocs() functions in musl > > sources or in usage of relocations. > > OK, I see what's going wrong here. The invalid relocation types are > being produced by this line in do_mips_relocs: > > rel[1] =3D sym-p->syms << 8 | R_MIPS_JUMP_SLOT; > > That produces a relocation in the elf32 encoding, because I just > assumes mips is elf32 when I wrote it. I believe the 64-bit version > should be: > > rel[1] =3D sym-p->syms << 32 | R_MIPS_JUMP_SLOT; > > Try just making that change and see if it works. If so we can work on > making a clean conditional for 32- vs 64-bit here later. > > Rich > --089e01161d00337dbf0522861a2e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Rich,
Thanks for Your mail
I have por= ted musl for mips64 ar= ch from porting guide.the list includes crt_arch.h and Now I didn't place crt assembly files for mips64 arch.
=

> That produces a r= elocation in the elf32 encoding, because I just
> assumes mips is elf32 when I wrote it. I believe = the 64-bit version
> should be:
>=C2= =A0
> =C2= =A0 =C2=A0 =C2=A0 =C2=A0rel[1] =3D sym-p->syms= << 32 | R_MIPS_JUMP_SLOT;

t= his change resolved some of the relocation type errors but still i am getti= ng some relocation type errors.I think these errors are from do_relocs()
Error relocating libc.so: unsupported relocation type 4= 611
Error relo= cating libc.so: unsupp= orted relocation type 4611
Error relocating libc.so: unsupported relocation type 4611
Error relocating libc.so: unsupported relocation type 461= 1
Error reloca= ting libc.so: unsuppo= rted relocation type 4611
Error relocating libc.so: unsupported relocation type 4611
;
;
Error relocati= ng libc.so: unsupport= ed relocation type 4611 =C2=A0

the relocation type value is = 4611 for all the errors.

> Did you = make a reloc.h defini= ng the relocation types needed for mips
> n64 and mapping them to the generic-reloc names musl uses for them?
> See the existing arch/*/reloc.h files. Without the= se being defined
> directly the dynamic linker will not be able to process th= e
>= ; relocations it find= s in itself or in the main program or other
> libraries

I have p= orted reloc.h for mip= s64 as

bash-3.2$ cat arch/mips64/reloc.h
#include <endian.h>

#if __BYTE_ORDER =3D=3D __LITTLE_ENDIAN
#define ENDIAN_SUFFIX "el&q= uot;
#else
#define ENDIAN_SUFFIX ""
#endif

#ifdef= __mips64_soft_float
#define FP_SUFFIX "-sf"
#else
#define FP_SUFFI= X ""
#endif
<= div style=3D"">
#define LDSO_ARCH "mips64" ENDIAN_SUFFIX FP_SUFFIX

#define TPOFF= _K (-0x7000)

= #define REL_SYM_OR_RE= L =C2=A0R_MIPS_64 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /*I didn't see R_MIPS_REL= 64 =C2=A0so It is a composition of R_MIPS_64 and R_MIPS_REL relocations but= i didn't see=C2=A0R_MIPS_REL i= n elf.h.=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0how can i define=C2=A0<= span style=3D"font-size:12.8px">REL_SYM_OR_REL for mips n64 abi= =C2=A0=C2=A0=C2=A0*/
#define REL_= PLT =C2=A0 =C2=A0 =C2=A0 =C2=A0 R_MIPS_JUMP_SLOT
#define REL_COPY =C2=A0 =C2=A0 = =C2=A0 =C2=A0R_MIPS_COPY
#define REL_DTPMO= D =C2=A0 =C2=A0 =C2=A0R_MIPS_TLS_DTPMOD64
#define REL_DT= POFF =C2=A0 =C2=A0 =C2=A0R_MIPS_TLS_DTPREL64
#define REL_TPOFF =C2=A0 =C2=A0 =C2=A0 R_MIPS_TLS_TPREL64
;
;
#define CRTJMP(pc,sp) = __asm__ __volatile__( \
=C2=A0"mov= e $sp,%1 ; jr %0" : : "r"(<= span class=3D"" id=3D":y7.61" tabindex=3D"-1">pc), "r"(sp) : "memory"= ) /* JR Rs =C2=A0means jump register PC <- Rs ,jump to the address in t= he rs*/

#define GETFUNCSYM(fp, sym, got) __asm__ ( \
=C2=A0".hidden " #sym "\n" \
=C2=A0".set push \n" \
=C2=A0".set noreorder \n" \
=C2=A0" bal 1f \n" \
=C2=A0" =C2=A0nop \n" \
=C2=A0" .gpdword . \n" \
=C2=A0" .gpdword " #sym " \n" \
=C2=A0"1: =C2=A0ld %0, ($ra) \n" \
=C2=A0" dsubu %0, $r= a, %0 \n" \
=C2=A0" ld $ra, 8($ra) \n" \
=C2=A0" daddu %0, %0, $ra \n" \
=C2=A0".set pop \n" \
=C2=A0: "=3Dr&quo= t;(*(fp)) : : "m= emory", "ra= " )



Thanks,
Mahesh=


On Mon, Oct 19, 2015 at 8:48 PM= , Rich Felker <dalias@libc.org> wrote:
On Mon, Oct 19, 2015 at 02:51:12PM +0530, Mahes= h Bodapati wrote:
> Hi Rich,
>
> I have ported musl libraries for MIPS n64 ABI architecture and I have = setup
> $gp as
>
> Crt1.s:

crt1.s is obsolete and should not be used for new archs. The benefit=
to you is that crt_arch.h (the new way of doing it) is a lot easier to
write. All you need to do is jump to the C entry point _start_c with
the right calling convention for a C function and the first 2 argument
slots containing the original stack pointer and a pointer to _DYNAMIC,
respectively. _start_c can be assumed to be defined in the same source
file.

> *lui=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$3,%hi(%neg(%gp_rel(_star= t)))*
>
> *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 daddu
> $3,$3,$25=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* same in dlsym.s
> and pipe.s */*
>
> *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 daddiu=C2=A0 $gp,$3,%lo(%ne= g(%gp_rel(_start)))*
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ld=C2=A0 =C2=A0 =C2=A0 = $4, %got_disp(main)($gp)=C2=A0 =C2=A0# Get main() ..

Jumping to main from crt1 is not valid. You need to call
__libc_start_main. But if you use crt_arch.h this part happens
automatically for you.

> I didn=E2=80=99t setup $gp as in MIPS o32 ABI as we shouldn=E2=80=99t = use _*gp*_disp for
> setting up $gp
>
> =E2=80=9CThe special symbol name _gp_disp, used for relocating the cal= culation of gp
> on entry to a DSO in 32-bit files, is
>
> not supported in ELF-64 or in the new 32-bit ABI. Instead, these reloc= ations
> should be composed with
>
> R_MIPS_GPREL applied to an explicit symbol for the entry point of the<= br> > subprogram

I'm not sure what document you're quoting, but sometimes the= se things
express assumptions about a particular usage case that don't apply to what musl is doing. But you should be able to avoid writing this code
anyway.

> involves loading the difference between the entry
>
> address of a subprogram s and the runtime gp for establishing gp:
>
> A: lui rx, %hi(%neg(%gp_rel(s)))# load high part of diff
>
> B: daddiu rx, rx, %lo(%neg(%gp_rel(s)))# add low part
>
> C: dadd gp, t9, rx # add to entry address=C2=A0 =E2=80=9C
>
>
>
> Now I am able to build dynamic n64 musl libraries and n64 dynamic
> application but it=E2=80=99s not showing any relocation with it
>
> and execution of application is giving errors like =E2=80=9Cunsupporte= d relocation
> type errors=E2=80=9D

Did you make a reloc.h defining the relocation types needed for mips=
n64 and mapping them to the generic-reloc names musl uses for them?
See the existing arch/*/reloc.h files. Without these being defined
directly the dynamic linker will not be able to process the
relocations it finds in itself or in the main program or other
libraries.

But without a working crt_arch.h I'm surprised the dynamic linker can even start at all. Are you sure you're not using the mips32 dynamic
linker? Look at the program headers (using readelf -l) for INTERP.

> $ objdump -R main
>
>
>
> a.out:=C2=A0 =C2=A0 =C2=A0file format elf64-tradbigmips
>
>
>
> DYNAMIC RELOCATION RECORDS (none)
>
>
>
> $ ./main
>
> Error relocating libc.so: unsupported relocation type 482431
>
> Error relocating libc.so: unsupported relocation type 482687
>
> Error relocating libc.so: unsupported relocation type 482943
>
> Error relocating libc.so: unsupported relocation type 483199
>
> ;
>
> ;
>
> ;
>
> Segmentation fault
>
>
>
> So Can you suggest how can I resolve these errors? I am thinking like<= br> > either doing changes in do_mips_reloc(),do_relocs() functions in musl<= br> > sources or in usage of relocations.

OK, I see what's going wrong here. The invalid relocation types = are
being produced by this line in do_mips_relocs:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 rel[1] =3D sym-p->syms << 8 | R_MIPS_J= UMP_SLOT;

That produces a relocation in the elf32 encoding, because I just
assumes mips is elf32 when I wrote it. I believe the 64-bit version
should be:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 rel[1] =3D sym-p->syms << 32 | R_MIPS_= JUMP_SLOT;

Try just making that change and see if it works. If so we can work on
making a clean conditional for 32- vs 64-bit here later.

Rich

--089e01161d00337dbf0522861a2e--