build: fix binary-link with ld.gold linker
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 8 Mar 2013 16:04:05 +0000 (17:04 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Fri, 8 Mar 2013 16:04:05 +0000 (17:04 +0100)
The ld.gold linker doesn't provide --format=default but needs --format=elf
instead. However, this doesn't work with ld.bfd. To avoid any linker
detection, we now link any binary file via partial-linking into a proper
object file itself and then link this object file in the final linking
step.
This also produces a fake libtool *.lo file so the libtool linking command
doesn't complain about PIC/non-PIC problems.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Makefile.am

index 44787f9..7019290 100644 (file)
@@ -148,6 +148,31 @@ EXTRA_DIST += src/genversion.sh
 GITHEAD:=$(shell $(emptyvariable)"$(srcdir)/src/genversion.sh" "$(srcdir)/src/shl_githead.c")
 
 #
+# Binary File Compiler
+# This target gets as input a binary file *.bin and produces an ELF/etc. output
+# object file *.bin.o and the corresponding libtool file *.bin.lo.
+# Note that we fake the libtool object files as there is no way to make libtool
+# create it. The comments in the .lo file are mandatory so don't remove them!
+#
+
+CLEANFILES += src/*.bin.lo src/*.bin.o
+
+src/%.bin.lo: src/%.bin
+       $(AM_V_GEN)$(LD) -r -o "src/$*.bin.o" -z noexecstack --format=binary "$<"
+       $(AM_V_at)echo "# $@ - a libtool object file" >"$@"
+       $(AM_V_at)echo "# Generated by $(shell $(LIBTOOL) --version | head -n 1)" >>"$@"
+       $(AM_V_at)echo "#" >>"$@"
+       $(AM_V_at)echo "# Please DO NOT delete this file!" >>"$@"
+       $(AM_V_at)echo "# It is necessary for linking the library." >>"$@"
+       $(AM_V_at)echo >>"$@"
+       $(AM_V_at)echo "# Name of the PIC object." >>"$@"
+       $(AM_V_at)echo "pic_object='$*.bin.o'" >>"$@"
+       $(AM_V_at)echo >>"$@"
+       $(AM_V_at)echo "# Name of the non-PIC object" >>"$@"
+       $(AM_V_at)echo "non_pic_object='$*.bin.o'" >>"$@"
+       $(AM_V_at)echo >>"$@"
+
+#
 # SHL - Static Helper Library
 # The SHL subsystem contains several small code pieces used all over kmscon and
 # other applications.
@@ -430,6 +455,7 @@ src/static_shaders.c: $(SHADERS) genshader$(EXEEXT)
 
 UNIFONT = $(top_srcdir)/src/font_unifont_data.hex
 UNIFONT_BIN = src/font_unifont_data.bin
+UNIFONT_LT = src/font_unifont_data.bin.lo
 
 EXTRA_DIST += $(UNIFONT)
 CLEANFILES += $(UNIFONT_BIN)
@@ -451,14 +477,13 @@ mod_unifont_la_SOURCES = \
        src/kmscon_module_interface.h \
        src/font_unifont.c \
        src/kmscon_mod_unifont.c
-EXTRA_mod_unifont_la_DEPENDENCIES = $(UNIFONT_BIN)
-mod_unifont_la_LIBADD = libshl.la
+mod_unifont_la_LIBADD = \
+       $(UNIFONT_LT) \
+       libshl.la
 mod_unifont_la_LDFLAGS = \
        $(AM_LDFLAGS) \
        -module \
-       -avoid-version \
-       -Wl,-z,noexecstack \
-       -Wl,--format=binary -Wl,$(UNIFONT_BIN) -Wl,--format=default
+       -avoid-version
 
 if BUILD_ENABLE_FONT_FREETYPE2
 module_LTLIBRARIES += mod-freetype2.la