Source: dwarfutils
Version: 20170709-1
Tags: upstream patch
User: helm...@debian.org
Usertags: rebootstrap

dwarfutils fails to cross build from source, because its build system it
assumes native compilation in a number of places.

The first hard failure is found in dwarfdump's configure.in. It uses
AC_TRY_RUN to check whether __attribute__ ((unused)) works. Such checks
always fail for cross compilation, but running the example is completely
unnecessary.  The check can easily be turned into AC_TRY_COMPILE.

Then libdwarf runs host tools during build. Its Makefile.in shows that
cross compilation was considered as it clearly marks the relevant places
with uses of $(HOSTCC) rather than $(CC). Unfortunately, HOSTCC receives
the same value as CC. The autoconf-archive has a macro AX_CC_FOR_BUILD
for discovering the build architecture compiler and after using that,
libdwarf actually builds.

Finally, dwarfdump runs tag_tree_build during build and that tool links
libdwarf. I don't have a solution for this part unfortunately.

Thus I am attaching my patch for the first two problems and ask you to
apply it as an incremental improvement. Please close this bug even
though dwarfutils will still fail to cross build when doing so.

Helmut
Index: dwarfutils-20170709/dwarfdump/configure.in
===================================================================
--- dwarfutils-20170709.orig/dwarfdump/configure.in
+++ dwarfutils-20170709/dwarfdump/configure.in
@@ -96,16 +96,14 @@
 		[Define 1 if regex seems to be defined]))
 
 AC_MSG_CHECKING(checking if __attribute__ unused compiles ok)
-AC_TRY_RUN([
+AC_TRY_COMPILE([
   static unsigned foo( unsigned x, __attribute__ ((unused)) int y)
   {  unsigned x2 = x + 1;
      return x2;
   }
-  int main(void) {
+] , [
      unsigned y = 0;
      y = foo(12,y);
-     return 0;
-  }
 ] ,
   [AC_DEFINE(HAVE_UNUSED_ATTRIBUTE,1,
         [Define 1 if __attribute__ ((unused)) compiles ok.])
Index: dwarfutils-20170709/libdwarf/configure.in
===================================================================
--- dwarfutils-20170709.orig/libdwarf/configure.in
+++ dwarfutils-20170709/libdwarf/configure.in
@@ -4,6 +4,7 @@
 AC_CONFIG_HEADER(config.h)
 
 AC_PROG_CC
+AX_CC_FOR_BUILD
 AC_C_BIGENDIAN
 AC_GCC_TRADITIONAL
 AC_PROG_INSTALL
Index: dwarfutils-20170709/libdwarf/Makefile.in
===================================================================
--- dwarfutils-20170709.orig/libdwarf/Makefile.in
+++ dwarfutils-20170709/libdwarf/Makefile.in
@@ -42,7 +42,8 @@
 INSTALL_DATA =	@INSTALL_DATA@
 SHELL =		/bin/sh
 CC =		@CC@
-HOSTCC =	@CC@
+CC_FOR_BUILD =	@CC_FOR_BUILD@
+EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
 AR =		@AR@
 # For use with BSD ar (MacOSX ar) edit the ARFLAGS to be -s
 #ARFLAGS =	@ARFLAGS@
@@ -144,22 +145,22 @@
 	echo "Not building archive library libdwarf.a"
 
 dwgetopt.o: $(srcdir)/dwgetopt.c $(srcdir)/dwgetopt.h
-	$(HOSTCC) $(HOSTCFLAGS) -c $(srcdir)/dwgetopt.c
+	$(CC_FOR_BUILD) $(HOSTCFLAGS) -c $(srcdir)/dwgetopt.c
 dwarf_loc.o: $(srcdir)/dwarf_loc.c  $(srcdir)/dwarf_loc2.c  $(srcdir)/dwarf_loc.h 
 	$(CC) $(CFLAGS) -c $(srcdir)/dwarf_loc.c
 
 errmsg_check: $(srcdir)/dwarf_errmsg_list.c libdwarf.h
 	grep DW_DLE libdwarf.h >errmsg_check_list
-	$(HOSTCC) $(HOSTCFLAGS) $(LDFLAGS)  -DTESTING $(srcdir)/dwarf_errmsg_list.c -o errmsg_check
-	./errmsg_check -f errmsg_check_list
+	$(CC_FOR_BUILD) $(HOSTCFLAGS) $(LDFLAGS)  -DTESTING $(srcdir)/dwarf_errmsg_list.c -o errmsg_check$(EXEEXT_FOR_BUILD)
+	./errmsg_check$(EXEEXT_FOR_BUILD) -f errmsg_check_list
 
 # Gennames builds and runs native, even for a cross-build of libdwarf.
 gennames: $(srcdir)/gennames.c $(srcdir)/dwarf.h dwgetopt.o
-	$(HOSTCC) $(HOSTCFLAGS) $(srcdir)/gennames.c dwgetopt.o $(HOSTLDFLAGS) -o gennames
+	$(CC_FOR_BUILD) $(HOSTCFLAGS) $(srcdir)/gennames.c dwgetopt.o $(HOSTLDFLAGS) -o gennames$(EXEEXT_FOR_BUILD)
 dwarf_names.h: dwarf_names.c
 dwarf_names.c: gennames $(srcdir)/dwarf.h
 	rm -f dwarf_names.h dwarf_names.c
-	./gennames  @dwarf_namestable@  -i $(srcdir) -o .
+	./gennames$(EXEEXT_FOR_BUILD)  @dwarf_namestable@  -i $(srcdir) -o .
 # End gennames build lines
 
 dwarf_line.o: $(srcdir)/dwarf.h libdwarf.h $(srcdir)/dwarf_line_table_reader_common.c $(srcdir)/dwarf_line.c

Reply via email to