From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8808 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.linux.lib.musl.general Subject: RE: PE target support in configure & Makefile Date: Wed, 04 Nov 2015 19:18:24 -0700 Message-ID: <20151104191824.dc30d64f61e5ec441c34ffd4f788e58e.f47e91edac.wbe@email15.secureserver.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1446689935 4110 80.91.229.3 (5 Nov 2015 02:18:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Nov 2015 02:18:55 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8821-gllmg-musl=m.gmane.org@lists.openwall.com Thu Nov 05 03:18:43 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 1ZuA8Q-0004hT-8E for gllmg-musl@m.gmane.org; Thu, 05 Nov 2015 03:18:42 +0100 Original-Received: (qmail 11696 invoked by uid 550); 5 Nov 2015 02:18:40 -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 11678 invoked from network); 5 Nov 2015 02:18:39 -0000 X-SID: deJT1r0012Zk7fR01 X-Originating-IP: 71.206.170.124 User-Agent: Workspace Webmail 5.15.9 Xref: news.gmane.org gmane.linux.lib.musl.general:8808 Archived-At: On 11/04/2015 08:52 PM, Rich Felker wrote:=0A> On Wed, Nov 04, 2015 at 05:3= 9:55PM -0700, writeonce@midipix.org wrote:=0A>> Greetings,=0A>>=0A>> As man= y of you know, musl has been ported to winnt (and has an already=0A>> worki= ng bash/dash, core shell utilities, and a native toolchain) without=0A>> ap= plying any patches to the upstream source tree.[1] Thus far, however,=0A>> = we have been building musl using a deviant script that we now hope to=0A>> = retire.=0A> =0A> Thanks for the report/info/patch. Since build system overh= aul is=0A> already on the roadmap for this release cycle, I'm including som= e=0A> general comments on things that could be changed as part of this repl= y=0A> where they're related to things you want to change.=0A> =0A>> As musl= 's build system is currently being revisited, I would like=0A>> propose (wi= th the attached patch as a reference) the addition of the=0A>> following fe= atures:=0A>>=0A>> 1. add rules for $(ARCH)/%.c: C-language arch-specific fi= les.=0A> =0A> After discussing this briefly on IRC I think this is a change= that=0A> would be welcome in general as part of the build overhaul in this= =0A> release cycle. There are actually a number of reasons we might want to= =0A> transition from asm source files to C files with inline asm for _most_= =0A> (not all; see below) of the arch-specific asm:=0A> =0A> - Enabling LTO= inlining.=0A> =0A> - Ability to generate code for multiple calling convent= ions/ABIs from=0A> the same sources.=0A> =0A> - Eliminating the issue of= missing CFI in asm source files.=0A> =0A> - Eliminating most ugly non-code= directives in asm source files.=0A> =0A> Of course some functions cannot b= e written in C at all: mainly vfork,=0A> setjmp, the tlsdesc functions, and= anything else that returns twice or=0A> has a nonstandard calling conventi= on.=0A> =0A> No decision needs to be made at this time however; enabling ar= ch=0A> replacements via C files in addition to just asm files does not=0A> = require that we change anything.=0A> =0A>> 2. --arch=3DARCH: alternate arch= -specific source files.=0A>> at the present, ARCH is derived from TARGET an= d has no corresponding=0A>> configure switch. Adding --arch support would a= llow setting nt32 and=0A>> nt64 as the arch directories for winnt's i686 an= d x86_64 targets,=0A>> respectively.=0A> =0A> I think this should be derive= d from target (by default, obtained from=0A> $CC -dumpmachine). Adding yet = another option that can be set=0A> inconsistently and which has not-widely-= known interaction with the=0A> standard options seems like a bad idea.=0A> = =0A=0AThat works too, of course, but would require special-casing the PE=0A= targets since -dumpmachine returns x86_64-nt64-midipix=0A(i686-nt32-midipix= ), whereas the arch-specific files are in nt64 (nt32).=0A=0A>> 3. PE target= detection, shared library linker flags.=0A>> at the present, musl's config= ure script assumes ELF targets as well as=0A>> its own loader routine (_dls= tart). PE target support could be added with=0A>> only a minimal effort if = we a) detect PE targets using the compiler, and=0A>> b) set PE/ELF-specific= linker flags accordingly.=0A> =0A> See my comments below interleaved with = the patch.=0A> =0A>> diff -u musl-1.1.12/configure musl-1.1.12.alt/configur= e=0A>> --- musl-1.1.12/configure=092015-10-19 19:12:57.000000000 -0400=0A>>= +++ musl-1.1.12.alt/configure=092015-11-04 18:08:50.676855247 -0500=0A>> @= @ -22,6 +22,7 @@=0A>> System types:=0A>> --target=3DTARGET co= nfigure to run on target TARGET [detected]=0A>> --host=3DHOST = same as --target=0A>> + --arch=3DARCH use alternate ARCH-sp= ecific source files for TARGET=0A>> =0A>> Optional features:=0A>> -= -enable-optimize=3D... optimize listed components for speed over size [au= to]=0A>> @@ -166,6 +167,7 @@=0A>> --enable-gcc-wrapper|--enable-gcc-wrapp= er=3Dyes) wrapper=3Dyes ; gcc_wrapper=3Dyes ;;=0A>> --disable-gcc-wrapper= |--enable-gcc-wrapper=3Dno) wrapper=3Dno ;;=0A>> --enable-*|--disable-*|-= -with-*|--without-*|--*dir=3D*|--build=3D*) ;;=0A>> +--arch=3D*) ARCH=3D${a= rg#*=3D} ;;=0A>> --host=3D*|--target=3D*) target=3D${arg#*=3D} ;;=0A>> = -* ) echo "$0: unknown option $arg" ;;=0A>> CC=3D*) CC=3D${arg#*=3D} ;;= =0A>> @@ -280,7 +282,7 @@=0A>> #=0A>> # Convert to just ARCH=0A>> #= =0A>> -case "$target" in=0A>> +test -z "$ARCH" && case "$target" in=0A>> = # Catch these early to simplify matching for 32-bit archs=0A>> mips64*|po= werpc64*) fail "$0: unsupported target \"$target\"" ;;=0A>> arm*) ARCH=3D= arm ;;=0A>> @@ -504,6 +506,10 @@=0A>> CFLAGS_AUTO=3D"${CFLAGS_AUTO# }"=0A= >> fi=0A>> =0A>> +# detect PE targets=0A>> +test -z "$PE_TARGET" && "$C= C" -dM -E - < /dev/null \=0A>> +=09| grep __PE__ >/dev/null && PE_TARGET=3D= yes=0A>> +=0A>> # Some patched GCC builds have these defaults messed up..= .=0A>> tryldflag LDFLAGS_AUTO -Wl,--hash-style=3Dboth=0A> =0A> Why not ju= st use the $ARCH names for midipix rather than probing the=0A> compiler for= something you already know?=0A> =0A=0AIndeed. And if end up special-casing= the targets for ARCH, then=0APE_TARGET should probably be set as part of t= hat same check.=0A=0A>> @@ -513,7 +519,7 @@=0A>> # runtime library; imple= mentation error is also a possibility.=0A>> tryldflag LDFLAGS_AUTO -Wl,--= no-undefined=0A>> =0A>> -test "$shared" =3D "no" || {=0A>> +test "$shared= " =3D "no" || test "$PE_TARGET" =3D "yes" || {=0A>> # Disable dynamic lin= king if ld is broken and can't do -Bsymbolic-functions=0A>> LDFLAGS_DUMMY= =3D=0A>> tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {=0A>> @@ -5= 23,6 +529,19 @@=0A>> }=0A>> }=0A> =0A> I think we can actually make -Bs= ymbolic-functions optional and just=0A> detect it. As an aside, we could su= pport interposing malloc (a widely=0A> requested feature, though one that r= equires a lot of care to make=0A> safe) by using --dynamic-list-data and --= dynamic-list FILE, where FILE=0A> contains a list of the malloc-related sym= bols, instead of=0A> -Bsymbolic-functions. Or we could just drop it alltoge= ther and let=0A> visibility do the work for us instead.=0A> =0A>> +# PE/ELF= -specific LDFLAGS=0A>> +test "$shared" =3D "no" || {=0A>> +=0A>> +test "$PE= _TARGET" =3D "yes" && "$CC" -dM -E - < /dev/null \=0A>> +=09| grep __SIZEOF= _POINTER__ | grep 4 >/dev/null && underscore=3D'_'=0A>> +=0A>> +test "$PE_T= ARGET" =3D "yes" && \=0A>> +=09LDFLAGS_IMG_FMT=3D"-Wl,-e,${underscore}__lib= c_entry_point -Wl,--subsystem,windows"=0A>> +=0A>> +test "$PE_TARGET" =3D "= yes" || \=0A>> +=09LDFLAGS_IMG_FMT=3D"-Wl,-e,_dlstart -Wl,-Bsymbolic-functi= ons"=0A>> +}=0A> =0A> Why not just arrange for the name to always be the sa= me at the C=0A> source level by using one fewer underscore in the 32-bit ve= rsion?=0A> Complex logic like this should be minimized at the configure lev= el.=0A=0AIndeed :-)=0A=0A> =0A> Rich=0A> =0A> =0A=0A