Experimentally, gcc/binutils from Debian Jessie (4.9.2/2.25) and CentOS
7.1 (4.8.3/2.23) don't make valid binaries when linking x86-64 object
files as elf32-x86-64.
Issues include corrupt DWARF debugging information (as confirmed by
gdb/readelf), and erroneously merged strings in .rodata (as confirmed by
strings).
Instead, link all binaries in their natural width, and objcopy hvm64
binaries to elf32-x86-64 after the fact.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
#if defined(__x86_64__)
-#if defined(CONFIG_ENV_hvm64)
-
-/*
- * All HVM guests start in 32bit mode in a stub
- * which switches to the desired running mode.
- */
-OUTPUT_FORMAT("elf32-x86-64")
-
-#else
-
OUTPUT_FORMAT("elf64-x86-64")
-
-#endif
-
OUTPUT_ARCH(i386:x86-64)
#elif defined(__i386__)
define PERENV_build
+ifneq ($(1),hvm64)
+# Generic link line for most environments
test-$(1)-$(NAME): $$(DEPS-$(1)) $$(link-$(1))
$$(LD) $$(LDFLAGS_$(1)) $$(DEPS-$(1)) -o $$@
+else
+# hvm64 needs linking normally, then converting to elf32-x86-64
+test-$(1)-$(NAME): $$(DEPS-$(1)) $$(link-$(1))
+ $$(LD) $$(LDFLAGS_$(1)) $$(DEPS-$(1)) -o $$@.tmp
+ objcopy $$@.tmp -O elf32-x86-64 $$@
+ rm -f $$@.tmp
+endif
cfg-$(1) ?= $(defcfg-$(1))