mailing list of musl libc
 help / color / mirror / code / Atom feed
From: <writeonce@midipix.org>
To: musl@lists.openwall.com
Subject: PE target support in configure & Makefile
Date: Wed, 04 Nov 2015 17:39:55 -0700	[thread overview]
Message-ID: <20151104173955.dc30d64f61e5ec441c34ffd4f788e58e.50d5ba8c08.wbe@email15.secureserver.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]

Greetings,

As many of you know, musl has been ported to winnt (and has an already
working bash/dash, core shell utilities, and a native toolchain) without
applying any patches to the upstream source tree.[1] Thus far, however,
we have been building musl using a deviant script that we now hope to
retire.

As musl's build system is currently being revisited, I would like
propose (with the attached patch as a reference) the addition of the
following features:

1. add rules for $(ARCH)/%.c: C-language arch-specific files.

2. --arch=ARCH: alternate arch-specific source files.
at the present, ARCH is derived from TARGET and has no corresponding
configure switch. Adding --arch support would allow setting nt32 and
nt64 as the arch directories for winnt's i686 and x86_64 targets,
respectively.

3. PE target detection, shared library linker flags.
at the present, musl's configure script assumes ELF targets as well as
its own loader routine (_dlstart). PE target support could be added with
only a minimal effort if we a) detect PE targets using the compiler, and
b) set PE/ELF-specific linker flags accordingly.

Best regards,
z.g.

[1] git://midipix.org/mmglue


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: musl-pe-support.patch --]
[-- Type: text/x-diff; name="musl-pe-support.patch";, Size: 3435 bytes --]

diff -u musl-1.1.12/configure musl-1.1.12.alt/configure
--- musl-1.1.12/configure	2015-10-19 19:12:57.000000000 -0400
+++ musl-1.1.12.alt/configure	2015-11-04 18:08:50.676855247 -0500
@@ -22,6 +22,7 @@
 System types:
   --target=TARGET         configure to run on target TARGET [detected]
   --host=HOST             same as --target
+  --arch=ARCH             use alternate ARCH-specific source files for TARGET
 
 Optional features:
   --enable-optimize=...   optimize listed components for speed over size [auto]
@@ -166,6 +167,7 @@
 --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;;
 --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
 --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
+--arch=*) ARCH=${arg#*=} ;;
 --host=*|--target=*) target=${arg#*=} ;;
 -* ) echo "$0: unknown option $arg" ;;
 CC=*) CC=${arg#*=} ;;
@@ -280,7 +282,7 @@
 #
 # Convert to just ARCH
 #
-case "$target" in
+test -z "$ARCH" && case "$target" in
 # Catch these early to simplify matching for 32-bit archs
 mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;;
 arm*) ARCH=arm ;;
@@ -504,6 +506,10 @@
 CFLAGS_AUTO="${CFLAGS_AUTO# }"
 fi
 
+# detect PE targets
+test -z "$PE_TARGET" && "$CC" -dM -E - < /dev/null \
+	| grep __PE__ >/dev/null && PE_TARGET=yes
+
 # Some patched GCC builds have these defaults messed up...
 tryldflag LDFLAGS_AUTO -Wl,--hash-style=both
 
@@ -513,7 +519,7 @@
 # runtime library; implementation error is also a possibility.
 tryldflag LDFLAGS_AUTO -Wl,--no-undefined
 
-test "$shared" = "no" || {
+test "$shared" = "no" || test "$PE_TARGET" = "yes" || {
 # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions
 LDFLAGS_DUMMY=
 tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || {
@@ -523,6 +529,19 @@
 }
 }
 
+# PE/ELF-specific LDFLAGS
+test "$shared" = "no" || {
+
+test "$PE_TARGET" = "yes" && "$CC" -dM -E - < /dev/null \
+	| grep __SIZEOF_POINTER__ | grep 4 >/dev/null && underscore='_'
+
+test "$PE_TARGET" = "yes" && \
+	LDFLAGS_IMG_FMT="-Wl,-e,${underscore}__libc_entry_point -Wl,--subsystem,windows"
+
+test "$PE_TARGET" = "yes" || \
+	LDFLAGS_IMG_FMT="-Wl,-e,_dlstart -Wl,-Bsymbolic-functions"
+}
+
 # Find compiler runtime library
 test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh
 test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt
@@ -634,7 +653,7 @@
 CFLAGS_MEMOPS = $CFLAGS_MEMOPS
 CFLAGS_NOSSP = $CFLAGS_NOSSP
 CPPFLAGS = $CPPFLAGS
-LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
+LDFLAGS = $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_IMG_FMT
 CROSS_COMPILE = $CROSS_COMPILE
 LIBCC = $LIBCC
 OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
diff -u musl-1.1.12/Makefile musl-1.1.12.alt/Makefile
--- musl-1.1.12/Makefile	2015-10-19 19:12:57.000000000 -0400
+++ musl-1.1.12.alt/Makefile	2015-11-04 17:48:16.764815762 -0500
@@ -133,6 +133,9 @@
 %.o: $(ARCH)/%.s
 	$(AS_CMD) $(CFLAGS_ALL_STATIC)
 
+%.o: $(ARCH)/%.c $(GENH) $(IMPH)
+	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
+
 %.o: %.c $(GENH) $(IMPH)
 	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
 
@@ -142,12 +145,14 @@
 %.lo: $(ARCH)/%.s
 	$(AS_CMD) $(CFLAGS_ALL_SHARED)
 
+%.lo: $(ARCH)/%.c $(GENH) $(IMPH)
+	$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
+
 %.lo: %.c $(GENH) $(IMPH)
 	$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
 
 lib/libc.so: $(LOBJS)
 	$(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
-	-Wl,-e,_dlstart -Wl,-Bsymbolic-functions \
 	-o $@ $(LOBJS) $(LIBCC)
 
 lib/libc.a: $(OBJS)

             reply	other threads:[~2015-11-05  0:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05  0:39 writeonce [this message]
2015-11-05  1:52 ` Rich Felker
2015-11-05  2:18 writeonce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151104173955.dc30d64f61e5ec441c34ffd4f788e58e.50d5ba8c08.wbe@email15.secureserver.net \
    --to=writeonce@midipix.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).