Skip to content

Commit a23549a

Browse files
junjiemao1jren1
authored andcommitted
HV: build: make relocation-related code configurable
The relocation feature relies on the ld option "-z noreloc-overflow" which is only available for binutils >= 2.27, while on Ubuntu 16.04 or older the default version of binutils is 2.26. This patch wraps the relocation code with a configurable macro and make it undefined by default to avoid default build failures. NOTE: This is just a hotfix. The code dropped with undefined CONFIG_RELOC needs to be reviewed by the original author of this feature. Checks to the binutils version will also follow up. Signed-off-by: Junjie Mao <junjie.mao@intel.com>
1 parent 057a384 commit a23549a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

hypervisor/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ LDFLAGS += -Wl,--gc-sections -nostartfiles -nostdlib
6363
LDFLAGS += -Wl,-n,-z,max-page-size=0x1000
6464
LDFLAGS += -Wl,-z,noexecstack
6565

66+
ifeq (y, $(CONFIG_RELOC))
6667
# on X86_64, when build with "-pie", GCC fails on linking R_X86_64_32
6768
# relocations with "recompile with fPIC" error, because it may cause
6869
# run-time relocation overflow if it runs at address above 4GB.
6970
# We know it's safe because Hypervisor runs under 4GB. "noreloc-overflow"
7071
# is used to avoid the compile error
7172
LDFLAGS += -pie -z noreloc-overflow
73+
endif
7274

7375
ARCH_CFLAGS += -gdwarf-2
7476
ARCH_ASFLAGS += -gdwarf-2 -DASSEMBLER=1

hypervisor/arch/x86/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ config UEFI_OS_LOADER_NAME
123123
config MTRR_ENABLED
124124
bool
125125
default y
126+
127+
config RELOC
128+
bool "Enable relocation"
129+
default n

hypervisor/boot/reloc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static uint64_t trampoline_relo_addr(void *addr)
6868
return (uint64_t)addr - get_hv_image_delta();
6969
}
7070

71+
#ifdef CONFIG_RELOC
7172
void _relocate(void)
7273
{
7374
struct Elf64_Dyn *dyn;
@@ -136,6 +137,11 @@ void _relocate(void)
136137
start = (struct Elf64_Rel *)((char *)start + size);
137138
}
138139
}
140+
#else
141+
void _relocate(void)
142+
{
143+
}
144+
#endif
139145

140146
uint64_t read_trampoline_sym(void *sym)
141147
{

0 commit comments

Comments
 (0)