Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

LLD for x86_64 #24

Closed
tpimh opened this issue Nov 5, 2018 · 4 comments
Closed

LLD for x86_64 #24

tpimh opened this issue Nov 5, 2018 · 4 comments
Assignees

Comments

@tpimh
Copy link
Contributor

tpimh commented Nov 5, 2018

Currently I have a patch which allows linking x86_64 kernel with LLD: fulldiff.patch.txt
Unfortunately there is no conditional detection of linker features, unsupported flags are just removed. This patch needs to be improved.

@nathanchance
Copy link
Member

If we strip that patch down to just the LLD bits, we could theoretically add this to the script to only apply that patch when building with LLD.

  for folder in ../patches/${ARCH} ../patches/${ARCH}/${LD}; done
    [[ -d ${folder} ]] && git apply -3 "${folder}"/*.patch
  done

@tpimh
Copy link
Contributor Author

tpimh commented Nov 6, 2018

These are the LLD specific parts of the patch:

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 9b5adae..e2839b5 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -100,7 +100,7 @@ $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE
 AFLAGS_header.o += -I$(objtree)/$(obj)
 $(obj)/header.o: $(obj)/zoffset.h
 
-LDFLAGS_setup.elf	:= -T
+LDFLAGS_setup.elf	:= -m elf_i386 -T
 $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
 	$(call if_changed,ld)
 
diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 141d415..0624bf2 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -47,7 +47,7 @@ targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
 CPPFLAGS_vdso.lds += -P -C
 
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
-			-z max-page-size=4096 -z common-page-size=4096
+			-z max-page-size=4096
 
 $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
 	$(call if_changed,vdso)
@@ -98,7 +98,7 @@ CFLAGS_REMOVE_vvar.o = -pg
 
 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
 VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
-			   -z max-page-size=4096 -z common-page-size=4096
+			   -z max-page-size=4096
 
 # x32-rebranded versions
 vobjx32s-y := $(vobjs-y:.o=-x32.o)
 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
 index 0d618ee..ee3b5c7 100644
 --- a/arch/x86/kernel/vmlinux.lds.S
 +++ b/arch/x86/kernel/vmlinux.lds.S
 @@ -401,7 +401,7 @@ SECTIONS
   * Per-cpu symbols which need to be offset from __per_cpu_load
   * for the boot processor.
   */
 -#define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
 +#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load
  INIT_PER_CPU(gdt_page);
  INIT_PER_CPU(irq_stack_union);
  
 diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
 index 3cf302b..6c167b9 100644
 --- a/arch/x86/purgatory/Makefile
 +++ b/arch/x86/purgatory/Makefile
 @@ -9,7 +9,7 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
  $(obj)/sha256.o: $(srctree)/lib/sha256.c FORCE
  	$(call if_changed_rule,cc_o_c)
  
 -LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib
 +LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib
  targets += purgatory.ro
  
  KASAN_SANITIZE	:= n
 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
 index 4463fa7..96cb20d 100644
 --- a/arch/x86/realmode/rm/Makefile
 +++ b/arch/x86/realmode/rm/Makefile
 @@ -47,7 +47,7 @@ $(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
  targets += realmode.lds
  $(obj)/realmode.lds: $(obj)/pasyms.h
  
 -LDFLAGS_realmode.elf := --emit-relocs -T
 +LDFLAGS_realmode.elf := -m elf_i386 --emit-relocs -T
  CPPFLAGS_realmode.lds += -P -C -I$(objtree)/$(obj)
  
  targets += realmode.elf

@arndb
Copy link

arndb commented Nov 6, 2018 via email

@tpimh
Copy link
Contributor Author

tpimh commented Nov 6, 2018

Hi, Arnd!

Here are the related issues:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants