mirror of
https://github.com/crosstool-ng/crosstool-ng.git
synced 2024-12-19 12:57:53 +00:00
Merge pull request #619 from stilor/refix-elf2flt
Fix elf2flt build on Cygwin in a different way
This commit is contained in:
commit
7992f9b05f
@ -0,0 +1,190 @@
|
||||
From 6ae8f1cc9abd2c25b3376a18f33fee00d9e771cf Mon Sep 17 00:00:00 2001
|
||||
From: Alexey Neyman <stilor@att.net>
|
||||
Date: Mon, 27 Feb 2017 01:20:10 -0800
|
||||
Subject: [PATCH 1/2] 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 <stilor@att.net>
|
||||
---
|
||||
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..1e34bda 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 <libiberty.h>"
|
||||
+ echo "#include <filenames.h>"
|
||||
+ echo "#include <bfd.h>"
|
||||
+} > "${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 <bfd.h> and <libiberty.h>. 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
|
||||
+# <libiberty.h>.
|
||||
+create_link "${binutils_loc}/elf" "${binutils_loc}"
|
||||
--
|
||||
2.9.3
|
||||
|
@ -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
|
@ -0,0 +1,57 @@
|
||||
From 1c19bf8cc294e95c8de314cc457bcea6854c3a2d Mon Sep 17 00:00:00 2001
|
||||
From: Alexey Neyman <stilor@att.net>
|
||||
Date: Tue, 28 Feb 2017 09:29:21 -0800
|
||||
Subject: [PATCH 2/2] Macos does not have <elf.h> and needs a local copy
|
||||
|
||||
Also, move <elf/xtensa.h> up - generic <elf.h> does not have
|
||||
definitions for xtensa relocations.
|
||||
|
||||
Local file, cygwin-elf.h, needs to include <stdint.h> for standard
|
||||
integer types which is POSIX - rather than glibc-originated <features.h>.
|
||||
|
||||
Signed-off-by: Alexey Neyman <stilor@att.net>
|
||||
---
|
||||
cygwin-elf.h | 2 +-
|
||||
elf2flt.c | 7 +++++--
|
||||
2 files changed, 6 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/cygwin-elf.h b/cygwin-elf.h
|
||||
index bd72b37..8e3dbff 100644
|
||||
--- a/cygwin-elf.h
|
||||
+++ b/cygwin-elf.h
|
||||
@@ -26,7 +26,7 @@ typedef uint16_t u_int16_t;
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef uint64_t u_int64_t;
|
||||
#else
|
||||
-#include <features.h>
|
||||
+#include <stdint.h>
|
||||
#endif
|
||||
/* Standard ELF types. */
|
||||
|
||||
diff --git a/elf2flt.c b/elf2flt.c
|
||||
index 08296cf..19a4d4d 100644
|
||||
--- a/elf2flt.c
|
||||
+++ b/elf2flt.c
|
||||
@@ -58,14 +58,17 @@ const char *elf2flt_progname;
|
||||
#include <elf/h8.h> /* TARGET_* ELF support for the BFD library */
|
||||
#elif defined(TARGET_arm)
|
||||
#include <elf/arm.h>
|
||||
-#elif defined(__CYGWIN__) || defined(__MINGW32__) || defined(TARGET_nios) || defined(TARGET_nios2)
|
||||
-#include "cygwin-elf.h" /* Cygwin uses a local copy */
|
||||
#elif defined(TARGET_xtensa)
|
||||
#include <elf/xtensa.h> /* TARGET_* ELF support for the BFD library */
|
||||
+#elif defined(TARGET_nios) || defined(TARGET_nios2)
|
||||
+#include "cygwin-elf.h" // <elf/nios2.h> does not have R_NIOS_* declarations
|
||||
#elif defined(TARGET_microblaze)
|
||||
#include <elf/microblaze.h> /* TARGET_* ELF support for the BFD library */
|
||||
#elif defined(TARGET_v850)
|
||||
#include <elf/v850.h>
|
||||
+#elif (__CYGWIN__) || defined(__MINGW32__) || defined(__APPLE__)
|
||||
+// FIXME: does Cygwin need this? It has <elf.h> in /usr/include
|
||||
+#include "cygwin-elf.h" // Some systems don't have <elf.h>
|
||||
#else
|
||||
#include <elf.h> /* TARGET_* ELF support for the BFD library */
|
||||
#endif
|
||||
--
|
||||
2.9.3
|
||||
|
Loading…
Reference in New Issue
Block a user