From bb48575141364c4874b123c185e9a12fa69a8c0d Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Mon, 27 Feb 2017 21:26:32 -0800 Subject: Fix elf2flt build on Cygwin in a different way ... after discussion with elf2flt maintainer. Signed-off-by: Alexey Neyman diff --git a/patches/elf2flt/4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/100-filter-includes.patch b/patches/elf2flt/4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/100-filter-includes.patch new file mode 100644 index 0000000..18bd46a --- /dev/null +++ b/patches/elf2flt/4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/100-filter-includes.patch @@ -0,0 +1,190 @@ +From 74f694a5147089463eecc93034d68278c1fc7561 Mon Sep 17 00:00:00 2001 +From: Alexey Neyman +Date: Mon, 27 Feb 2017 01:20:10 -0800 +Subject: [PATCH] When looking for binutils/BFD headers, create a local include + dir + +... and filter only those headers that elf2flt binaries are going +to use, to minimize the chance of clashes with system headers. + +Signed-off-by: Alexey Neyman +--- + Makefile.in | 13 ++++++-- + configure | 4 +-- + configure.ac | 4 +-- + mk-local-include.sh | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 103 insertions(+), 7 deletions(-) + create mode 100755 mk-local-include.sh + +diff --git a/Makefile.in b/Makefile.in +index a6feea6..d3e75bd 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -14,7 +14,9 @@ CPU = @target_cpu@ + TARGET = @target_alias@ + SYMBOL_PREFIX = @SYMBOL_PREFIX@ + CFLAGS = @CFLAGS@ +-INCLUDES = -I$(srcdir) @bfd_include_dir@ @binutils_include_dir@ @zlib_include_dir@ ++INCLUDES = -I$(srcdir) -Ilocal-include @zlib_include_dir@ ++BFD_INCLUDE_DIR = @bfd_include_dir@ ++BINUTILS_INCLUDE_DIR = @binutils_include_dir@ + CPPFLAGS = @CPPFLAGS@ $(DEFS) $(INCLUDES) + LDFLAGS = @LDFLAGS@ + LDLIBS = @LIBS@ +@@ -101,7 +103,7 @@ check-flthdr: + check: check-flthdr + + clean: +- -rm -f $(PROGS) *.$(OBJEXT) .deps ++ -rm -f $(PROGS) *.$(OBJEXT) .deps local-include + + distclean: clean + -rm -f Makefile config.log config.status config.cache ld-elf2flt +@@ -121,5 +123,10 @@ install: + $(INSTALL) -m 644 $(SRC_LDFILE) $(DESTDIR)$(target_libdir)/$(LDFILE) + + sinclude .deps +-.deps: ++.deps: local-include/.stamp + $(CC) -MM $(CPPFLAGS) $(srcdir)/*.c > .deps ++ ++local-include/.stamp: $(srcdir)/mk-local-include.sh ++ bash $(srcdir)/mk-local-include.sh local-include '$(CC)' \ ++ '$(BFD_INCLUDE_DIR)' '$(BINUTILS_INCLUDE_DIR)' $(DEFS) ++ touch $@ +diff --git a/configure b/configure +index 3a4e8d6..af64990 100755 +--- a/configure ++++ b/configure +@@ -3931,12 +3931,12 @@ fi + + bfd_include_dir= + if test "$ac_bfd_include_dir" != "NONE"; then +- bfd_include_dir="-I$ac_bfd_include_dir" ++ bfd_include_dir="$ac_bfd_include_dir" + fi + + binutils_include_dir= + if test "$ac_binutils_include_dir" != "NONE"; then +- binutils_include_dir="-I$ac_binutils_include_dir" ++ binutils_include_dir="$ac_binutils_include_dir" + fi + + zlib_include_dir= +diff --git a/configure.ac b/configure.ac +index 6002894..b7fb790 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -135,12 +135,12 @@ fi + + bfd_include_dir= + if test "$ac_bfd_include_dir" != "NONE"; then +- bfd_include_dir="-I$ac_bfd_include_dir" ++ bfd_include_dir="$ac_bfd_include_dir" + fi + + binutils_include_dir= + if test "$ac_binutils_include_dir" != "NONE"; then +- binutils_include_dir="-I$ac_binutils_include_dir" ++ binutils_include_dir="$ac_binutils_include_dir" + fi + + zlib_include_dir= +diff --git a/mk-local-include.sh b/mk-local-include.sh +new file mode 100755 +index 0000000..a6e8a63 +--- /dev/null ++++ b/mk-local-include.sh +@@ -0,0 +1,89 @@ ++#!/bin/bash ++ ++# Binutils provide certain headers that are clashing with system-wide ++# headers on Cygwin and MacOS. They do so in different manners, though, ++# so it is not possible to just tweak the inclusion/library order. ++# Hence, we prepare a filtered inclusion directory where we only place ++# the headers that we need for BFD/binutils. To determine them, we'll ++# need to preprocess a sample file including the headers that will be used, ++# and have the compiler output the actual list of included headers for us. ++ ++# Usage: ++# mk-local-include.sh DIR CC BFD-INCLUDES BINUTILS-INCLUDES [DEFINES...] ++ ++local_inc=$1 ++cc=$2 ++bfd_inc=$3 ++binutils_inc=$4 ++shift 4 ++# What remains are defines to pass to GCC ++ ++case "${local_inc}" in ++ */*) echo "Local include dir may only have one component" >&2; exit 1;; ++ .|..) echo "Local include dir may not be . or .." >&2; exit 1;; ++esac ++ ++# Re-create it from a clean slate ++rm -rf "${local_inc}" ++mkdir -p "${local_inc}" ++ ++# Create a dummy source file that we'll preprocess ++{ ++ echo "#include " ++ echo "#include " ++ echo "#include " ++} > "${local_inc}/_dummy.c" ++ ++$cc ${bfd_inc:+-I${bfd_inc}} ${binutils_inc:+-I${binutils_inc}} "$@" \ ++ -E -o /dev/null -H "${local_inc}/_dummy.c" 2>&1 | \ ++ sed -rn -e 's/^\.+ //p' > "${local_inc}/_hdr.list" ++if [ $? != 0 ]; then ++ echo "Failed to locate libiberty.h/bfd.h headers" >&2 ++ exit 1 ++fi ++ ++# Now go over the list twice. First determine how the compiler printed ++# the location of and . They themselves may be in ++# a system include directory. We'll create a mess of symlinks in that case, ++# but they'll still point to the system headers. ++while read f; do ++ case "$f" in ++ */bfd.h) bfd_loc=${f%/bfd.h};; ++ */libiberty.h) binutils_loc=${f%/libiberty.h};; ++ esac ++done < $local_inc/_hdr.list ++ ++# Now symlink the headers that reside in the same directory as the headers ++# we're looking for, or in any subdirectory thereof. ++create_link() { ++ local f=$1 ++ local bd=$2 ++ local relpath lnkname bname src ++ ++ relpath=${f#${bd}/} ++ lnkname=${local_inc}/${relpath} ++ bname=${relpath##*/} ++ if [ "${bname}" != "${relpath}" ]; then ++ mkdir -p "${relpath%/*}" ++ fi ++ case "${f}" in ++ /*) src=${f};; ++ *) src=../${f};; # account for one extra path component (DIR) ++ esac ++ if [ ! -L "${lnkname}" ]; then ++ ln -s "${src}" "${lnkname}" ++ fi ++} ++ ++while read f; do ++ case "$f" in ++ ${bfd_loc}/*) create_link "$f" "${bfd_loc}";; ++ ${binutils_loc}/*) create_link "$f" "${binutils_loc}";; ++ esac ++done < $local_inc/_hdr.list ++ ++# Final bit of secret knowledge. We need ELF headers, and the exact headers ++# depend on the selected target. Fortunately, they are all in the 'elf/' ++# subdirectory of binutils include directory, which we get by searching for ++# . ++create_link "${binutils_loc}/elf" "${binutils_loc}" +-- +2.9.3 + diff --git a/patches/elf2flt/4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/100-no-lcygwin.patch b/patches/elf2flt/4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/100-no-lcygwin.patch deleted file mode 100644 index ac5225a..0000000 --- a/patches/elf2flt/4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/100-no-lcygwin.patch +++ /dev/null @@ -1,81 +0,0 @@ -diff -urpN elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32.orig/configure elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/configure ---- elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32.orig/configure 2017-02-21 22:04:05.914752800 -0800 -+++ elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/configure 2017-02-21 23:06:12.088166600 -0800 -@@ -3983,46 +3983,6 @@ case $target in - ;; - esac - --{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for malloc in -lc" >&5 --$as_echo_n "checking for malloc in -lc... " >&6; } --if ${ac_cv_lib_c_malloc+:} false; then : -- $as_echo_n "(cached) " >&6 --else -- ac_check_lib_save_LIBS=$LIBS --LIBS="-lc $LIBS" --cat confdefs.h - <<_ACEOF >conftest.$ac_ext --/* end confdefs.h. */ -- --/* Override any GCC internal prototype to avoid an error. -- Use char because int might match the return type of a GCC -- builtin and then its argument prototype would still apply. */ --#ifdef __cplusplus --extern "C" --#endif --char malloc (); --int --main () --{ --return malloc (); -- ; -- return 0; --} --_ACEOF --if ac_fn_c_try_link "$LINENO"; then : -- ac_cv_lib_c_malloc=yes --else -- ac_cv_lib_c_malloc=no --fi --rm -f core conftest.err conftest.$ac_objext \ -- conftest$ac_exeext conftest.$ac_ext --LIBS=$ac_check_lib_save_LIBS --fi --{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_malloc" >&5 --$as_echo "$ac_cv_lib_c_malloc" >&6; } --if test "x$ac_cv_lib_c_malloc" = xyes; then : -- LIBS="-lc $LIBS" --fi -- - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 - $as_echo_n "checking for dlopen in -ldl... " >&6; } - if ${ac_cv_lib_dl_dlopen+:} false; then : -diff -urpN elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32.orig/configure.ac elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/configure.ac ---- elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32.orig/configure.ac 2017-02-21 22:04:05.915751600 -0800 -+++ elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/configure.ac 2017-02-21 23:06:07.431134300 -0800 -@@ -187,12 +187,6 @@ case $target in - ;; - esac - --dnl Make sure we resolve system symbols before libiberty/libbfd ones. --dnl Otherwise, things like getopt get screwed up because the system headers --dnl redirect some functions to the system symbols, but other local symbols --dnl come from libiberty/libbfd. --dnl int getopt(int, char * const [], const char *) __asm("_" "getopt" "$UNIX2003"); --AC_CHECK_LIB(c, malloc, LIBS="-lc $LIBS") - AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl") - - dnl Checks for header files. -diff -urpN elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32.orig/Makefile.in elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/Makefile.in ---- elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32.orig/Makefile.in 2017-02-21 22:04:05.939740400 -0800 -+++ elf2flt-4820f0dbb77cd6564d5fa0817218fe2a1fb99f32/Makefile.in 2017-02-21 22:06:54.970169200 -0800 -@@ -38,11 +38,6 @@ ifneq (,$(findstring mingw32,$(HOST))) - LDLIBS += -lws2_32 - endif - --# force link order under cygwin to avoid getopts / libiberty clash --ifneq ($(strip $(shell gcc -v 2>&1 | grep "cygwin")),) -- LDLIBS := -lcygwin $(LDLIBS) --endif -- - LDFILE= elf2flt.ld - ifeq ($(strip $(CPU)),e1) - SRC_LDFILE= $(srcdir)/$(CPU)-elf2flt.ld -- cgit v0.10.2-6-g49f6