From 1929fda490912abadca85055ccaa64228d604868 Mon Sep 17 00:00:00 2001
From: mintsuki <mintsuki@protonmail.com>
Date: Sun, 26 Jun 2022 21:34:35 +0200
Subject: [PATCH] linker.ld: Work around portability issue

---
 kernel/GNUmakefile                     | 7 +++----
 kernel/{linker.ld => linker-x86_64.ld} | 4 ++++
 2 files changed, 7 insertions(+), 4 deletions(-)
 rename kernel/{linker.ld => linker-x86_64.ld} (91%)

diff --git a/kernel/GNUmakefile b/kernel/GNUmakefile
index 0490512..1ac0c2f 100644
--- a/kernel/GNUmakefile
+++ b/kernel/GNUmakefile
@@ -42,7 +42,7 @@ override INTERNALLDFLAGS :=     \
     -nostdlib                   \
     -static                     \
     -Wl,-z,max-page-size=0x1000 \
-    -Wl,-T,linker.ld
+    -Wl,-T,linker-$(ARCH).ld
 
 # Set archtecture specific variables (and check that the architecture is supported).
 ifeq ($(ARCH),x86_64)
@@ -56,9 +56,8 @@ ifeq ($(ARCH),x86_64)
         -mno-sse2              \
         -mno-red-zone          \
         -mcmodel=kernel
-    override INTERNALLDFLAGS +=    \
-        -Wl,-m,elf_x86_64          \
-        -Wl,--oformat=elf64-x86-64
+    override INTERNALLDFLAGS += \
+        -Wl,-m,elf_x86_64
 else
     $(error Architecture $(ARCH) not supported)
 endif
diff --git a/kernel/linker.ld b/kernel/linker-x86_64.ld
similarity index 91%
rename from kernel/linker.ld
rename to kernel/linker-x86_64.ld
index 36fc281..3b0de45 100644
--- a/kernel/linker.ld
+++ b/kernel/linker-x86_64.ld
@@ -1,3 +1,7 @@
+/* Tell the linker that we want an x86_64 ELF64 output file */
+OUTPUT_FORMAT(elf64-x86-64)
+OUTPUT_ARCH(i386:x86-64)
+
 /* We want the symbol _start to be our entry point */
 ENTRY(_start)