diff mbox series

[kvm-unit-tests,1/2] arm/arm64: prepare to compile arm64 tests relocatable

Message ID 20180823092003.6076-2-drjones@redhat.com (mailing list archive)
State New, archived
Headers show
Series arm64: support relocatable compiles | expand

Commit Message

Andrew Jones Aug. 23, 2018, 9:20 a.m. UTC
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/Makefile.arm    |  6 +++++-
 arm/Makefile.arm64  |  6 +++++-
 arm/Makefile.common | 19 +++++++------------
 3 files changed, 17 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/arm/Makefile.arm b/arm/Makefile.arm
index 6b57284382aa..a625267a9c02 100644
--- a/arm/Makefile.arm
+++ b/arm/Makefile.arm
@@ -5,7 +5,6 @@ 
 #
 bits = 32
 ldarch = elf32-littlearm
-kernel_offset = 0x10000
 machine = -marm
 
 # stack.o relies on frame pointers.
@@ -14,6 +13,11 @@  KEEP_FRAME_POINTER := y
 CFLAGS += $(machine)
 CFLAGS += -mcpu=$(PROCESSOR)
 
+arch_LDFLAGS = -Ttext=40010000
+
+define arch_elf_check =
+endef
+
 cstart.o = $(TEST_DIR)/cstart.o
 cflatobjs += lib/arm/spinlock.o
 cflatobjs += lib/arm/processor.o
diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64
index f04bbf476763..782d4faa5cdc 100644
--- a/arm/Makefile.arm64
+++ b/arm/Makefile.arm64
@@ -5,7 +5,11 @@ 
 #
 bits = 64
 ldarch = elf64-littleaarch64
-kernel_offset = 0x80000
+
+arch_LDFLAGS = -Ttext=40080000
+
+define arch_elf_check =
+endef
 
 cstart.o = $(TEST_DIR)/cstart64.o
 cflatobjs += lib/arm64/processor.o
diff --git a/arm/Makefile.common b/arm/Makefile.common
index 1cf9cdcf078e..57c3363a36f2 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -4,11 +4,6 @@ 
 # Authors: Andrew Jones <drjones@redhat.com>
 #
 
-ifeq ($(LOADADDR),)
-	# qemu mach-virt default load address
-	LOADADDR = 0x40000000
-endif
-
 tests-common  = $(TEST_DIR)/selftest.flat
 tests-common += $(TEST_DIR)/spinlock-test.flat
 tests-common += $(TEST_DIR)/pci-test.flat
@@ -23,7 +18,6 @@  all: directories $(tests-all)
 $(TEST_DIR)/sieve.elf: AUXFLAGS = 0x1
 
 ##################################################################
-phys_base = $(LOADADDR)
 AUXFLAGS ?= 0x0
 
 CFLAGS += -std=gnu99
@@ -64,17 +58,18 @@  libeabi = lib/arm/libeabi.a
 eabiobjs = lib/arm/eabi_compat.o
 
 libgcc := $(shell $(CC) $(machine) --print-libgcc-file-name)
-start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
 
 FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
-%.elf: LDFLAGS = $(CFLAGS) -nostdlib
+%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS)
 %.elf: %.o $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o)
-	$(CC) $(LDFLAGS) -o $@ \
-		-Wl,-T,$(SRCDIR)/arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
-		$(filter %.o, $^) $(FLATLIBS) \
-		$(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
+	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \
+		-DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
+	$(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \
+		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
+	$(RM) $(@:.elf=.aux.o)
 
 %.flat: %.elf
+	$(call arch_elf_check, $^)
 	$(OBJCOPY) -O binary $^ $@
 
 $(libeabi): $(eabiobjs)