From b5306df520b13c146594d28d4d8cf415e9ba9ac1 Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Wed, 5 Nov 2014 18:26:23 +0000 Subject: [PATCH] Implement conventionally named dirent function trampolines. --- mingwrt/ChangeLog | 23 ++++++++++++++++ mingwrt/Makefile.in | 44 ++++++++++++++++++++++++++++++- mingwrt/aclocal.m4 | 27 +++++++++++++++++++ mingwrt/configure.ac | 1 + mingwrt/mingwex/jmpstub.sx | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 mingwrt/mingwex/jmpstub.sx diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 877bed9..c1bb58f 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,26 @@ +2014-11-05 Keith Marshall + + Implement conventionally named dirent function trampolines. + + * mingwex/jmpstub.sx: New file; it implements a generic trampoline, + which redirects a conventionally named function call to its __mingw_ + pseudo-namespace implementation. + + * aclocal.m4 (MINGW_AC_PROG_COMPILE_SX): New macro; define it. + * configure.ac (MINGW_AC_PROG_COMPILE_SX): Use it; it identifies the + appropriate protocol for compiling *.sx files, (supported natively by + GCC >= v4.3, but older versions require `-x assembler-with-cpp'). + + * Makefile.in (COMPILE.sx): New implicit rule; GNU make does not + yet provide it, so we define it ourselves; deploy it for *.sx files. + (Makefile.stub): New sinclude file; create it dynamically, using... + (jmpstub_awk_script): ...this new inline script, which is based on... + (jmpstub_refs, jmpstub_prerequisites): ...these new macros, and... + (mingwex/jmpstub.sx): ...this new file; add vpath reference. + (mostlyclean-local): Remove Makefile.stub; do likewise... + (Makefile): ...when remaking this, to ensure that both will be + remade together. + 2014-11-03 Keith Marshall Make dirent implementation namespace and time_t clean. diff --git a/mingwrt/Makefile.in b/mingwrt/Makefile.in index 3848000..ffa2847 100644 --- a/mingwrt/Makefile.in +++ b/mingwrt/Makefile.in @@ -57,6 +57,7 @@ ARFLAGS = @ARFLAGS@ RANLIB = @RANLIB@ AS = @AS@ +COMPILE.sx = @COMPILE_SX@ DLLTOOL = @DLLTOOL@ STRIP = @STRIP@ NM = @NM@ @@ -112,6 +113,7 @@ vpath Makefile.in ${top_srcdir} requires_existing = $(if $(wildcard $1),$1,$1.missing) Makefile: Makefile.in configure $(call requires_existing,config.status) $(SHELL) config.status + $(RM) Makefile.stub .PHONY: config.status.missing # ... but, in the event that this may be missing, (e.g. because it @@ -154,6 +156,16 @@ ALL_CFLAGS = $(CFLAGS) $(DEPFLAGS) $(INCLUDES) $(NTDDI_VERSION_SPEC) w%.$(OBJEXT): %.c $(CC) -c -D UNICODE $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $< +# Compiling object files from *.sx sources: since GCC-4.3, these +# have been supported as a case agnostic alternative to *.S sources, +# for assembly language sources requiring initial interpretation by +# the C preprocessor; owing to the case-insensitive nature of file +# naming on MS-Windows, we should prefer these, but we must tell +# make how to compile them. +# +%.$(OBJEXT): %.sx + $(COMPILE.sx) $($*_cflags) -o $@ $< + # Several components of the distributable object code base are to # be provided as free-standing object modules, (rather than being # encapsulated within object libraries); we classify these within @@ -478,6 +490,36 @@ $(addsuffix .$(OBJEXT), % %f %l): %_generic.c $(addsuffix .$(OBJEXT), llround llroundf llroundl): %.$(OBJEXT): lround_generic.c $(CC) -c -D FUNCTION=$* $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $< +# The mingwrt headers define a number of functions which are normally +# expected to be compiled as inline code. Each such function must also +# be provided with an externally visible entry point; we provide such +# entry points as stubs in libmingwex.a, via the following rules: +# +sinclude Makefile.stub +jmpstub_refs = grep -lr '__JMPSTUB.*FUNCTION' +jmpstub_prerequisites := $(shell $(jmpstub_refs) ${mingwrt_srcdir}/include) +Makefile.stub: Makefile $(jmpstub_prerequisites) + echo "# $@: automatically generated file -- do not edit!" > $@ + $(jmpstub_awk_script) $(jmpstub_prerequisites) >> $@ + echo "# $@: end of file" >> $@ + +vpath jmpstub.sx ${mingwrt_srcdir}/mingwex +jmpstub_awk_script = test "$^" = Makefile || awk '\ + BEGIN { \ + symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \ + fmt = "\nlib%s.a: %s\n%s: jmpstub.sx\n\t$$(COMPILE.sx) %s -o $$@ $$^\n"; \ + } \ + /__JMPSTUB(__)? *[(].*FUNCTION/ { \ + LIB = "mingwex"; \ + FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \ + OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".stub.$$(OBJEXT)"; \ + OBJNAME_CFLAGS = "-D FUNCTION="FUNCTION; \ + printf fmt, LIB, OBJNAME, OBJNAME, OBJNAME_CFLAGS; \ + } \ + END { \ + printf "\n"; \ + }' + all-mingwrt-libs install-mingwrt-libs: libm.a # Historically, MinGW.org's libm.a has been a dummy, delivering # nothing of value; FIXME: IMO, this sucks; it should deliver the @@ -722,7 +764,7 @@ clean-local: mostlyclean-local $(RM) msvcr*.def moldname*.def mingw*.def lib*.a *.dll mostlyclean-local: - $(RM) *.d *.$(OBJEXT) + $(RM) *.d *.$(OBJEXT) Makefile.stub distclean-local: clean-local $(RM) config.log config.status libm_dummy.c diff --git a/mingwrt/aclocal.m4 b/mingwrt/aclocal.m4 index 3e0ecfd..bcbded3 100644 --- a/mingwrt/aclocal.m4 +++ b/mingwrt/aclocal.m4 @@ -135,4 +135,31 @@ AC_DEFUN_ONCE([MINGW_AC_MAKE_COMMAND_GOALS], AC_SUBST([DEFAULT_MAKECMDGOALS]) ]) +# MINGW_AC_PROG_COMPILE_SX +# ------------------------ +# Determine how to invoke GCC to compile *.sx asssembly language +# files, and provide a suitable derivative of GNU make's COMPILE.S +# rule in AC_SUBST variable 'COMPILE_SX'. Note that GCC itself has +# supported direct compilation of such files from version 4.3 onward, +# (earlier versions require the '-x assembler-with-cpp' hint), but +# GNU make does not provide a complementary built-in rule. +# +AC_DEFUN([MINGW_AC_PROG_COMPILE_SX], +[AC_REQUIRE([AC_PROG_CC])dnl + AC_MSG_CHECKING([for $CC option to compile .sx files]) + rm -f conftest.sx conftest.$OBJEXT; : > conftest.sx + ac_compile_sx='$CC -c $ASFLAGS $CPPFLAGS $ac_val conftest.sx >&5' + for ac_val in "" "-x assembler-with-cpp"; do + (eval $ac_compile_sx) 2>&5 && test -f conftest.$OBJEXT && break + done + AC_SUBST([COMPILE_SX],[`echo '$(COMPILE.S)' $ac_val`]) + test "x$ac_val" = x && ac_val="none needed" + test -f conftest.$OBJEXT || ac_val="not supported" + AC_MSG_RESULT([$ac_val]) + rm -f conftest.sx conftest.$OBJEXT + test "x$ac_val" = "xnot supported" && { + AC_MSG_FAILURE([$CC cannot compile .sx files]) + }dnl +]) + # $RCSfile$: end of file diff --git a/mingwrt/configure.ac b/mingwrt/configure.ac index d2e22e7..b9191d2 100644 --- a/mingwrt/configure.ac +++ b/mingwrt/configure.ac @@ -35,6 +35,7 @@ AC_CONFIG_SRCDIR([include/_mingw.h]) MINGW_AC_CONFIG_EXTRA_SRCDIR([w32api],[include/w32api.h]) MINGW_AC_PROG_CC_COMPILE_ONLY + MINGW_AC_PROG_COMPILE_SX AC_CHECK_TOOL([AS],[as],[as]) AC_CHECK_TOOL([WINDRES],[windres],[windres]) diff --git a/mingwrt/mingwex/jmpstub.sx b/mingwrt/mingwex/jmpstub.sx new file mode 100644 index 0000000..aa57975 --- /dev/null +++ b/mingwrt/mingwex/jmpstub.sx @@ -0,0 +1,65 @@ +/* + * jmpstub.sx + * + * Generic trampoline, mapping any conventional function name to the entry + * point for an implementation within the "__mingw_" pseudo-namespace. + * + * $Id$ + * + * Written by Keith Marshall + * Copyright (C) 2013, 2014, MinGW.org Project + * + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * + * This file implements a generic trampoline stub, which remaps a specified + * function, via a CPU "jmp" instruction, to an alternative entry point; it + * may be compiled using a command such as: + * + * $(CC) -c $(CPPFLAGS) -D FUNCTION=funcname -o funcname.o jmpstub.sx + * + * to create a free standing object module, providing a physically addressable + * entry point for __CRT_ALIAS function, "funcname". (Note that any version of + * GCC predating GCC-4.3 may also require the "-x assembler-with-cpp" option). + * + * By default, the generated stub redirects calls to function "funcname()", + * such that they invoke the equivalent library function, with entry point at + * "__mingw_funcname()"; this default may be overriden, by specification of + * an additional "-D REMAPPED=entryname" option, resulting in redirection + * of "funcname()" calls to the "entryname()" function entry point. + * + */ +#define __entry__(__suffix__) __label__(_,__suffix__) +#define __label__(__prefix__,__suffix__) __prefix__##__suffix__ + +#ifndef REMAPPED +# define __mingw__(__suffix__) __label__(__mingw_,__suffix__) +# define REMAPPED __mingw__(FUNCTION) +#endif + +.text +.global __entry__(FUNCTION) +.def __entry__(FUNCTION); .scl 2; .type 32; .endef +.def __entry__(REMAPPED); .scl 2; .type 32; .endef + +__entry__(FUNCTION): jmp __entry__(REMAPPED) + +/* $RCSfile$: end of file */ -- 2.11.0